This commit is contained in:
Михаил Капелько
2024-04-23 22:31:30 +03:00
parent c6a08d00a1
commit 1adaab1afd
3 changed files with 45 additions and 3 deletions

View File

@@ -5,6 +5,7 @@ print(memory_test_selectItem_1x())
print(memory_test_selectItem_2x()) print(memory_test_selectItem_2x())
print(memory_test_selectItem_3x()) print(memory_test_selectItem_3x())
print(memory_test_shouldDeselectMismatchedItems()) print(memory_test_shouldDeselectMismatchedItems())
print(memory_test_shouldDeselectMismatchedItems_itemTwice())
print(memory_test_shouldDetectVictory()) print(memory_test_shouldDetectVictory())
print(memory_test_shouldHideMatchingItems()) print(memory_test_shouldHideMatchingItems())

View File

@@ -45,14 +45,29 @@ def memory_selectItem(
# Deselect mismatched items # Deselect mismatched items
# #
# Conditions: # Conditions:
# 1. Two items are selected and they are of different groups # 0. Two items has just been selected
# 1. The same item has been selected twice
# 1. Selected items are of different groups
@llm_by_value @llm_by_value
def memory_shouldDeselectMismatchedItems( def memory_shouldDeselectMismatchedItems(
c: memory_Context c: memory_Context
) -> memory_Context: ) -> memory_Context:
if ( if not (
c.recentField == "selectedItems" and c.recentField == "selectedItems" and
len(c.selectedItems) == 2 and len(c.selectedItems) == 2
):
c.recentField = None
return c
if (
c.selectedItems[0] == c.selectedItems[1]
):
c.mismatchedItems.clear()
c.mismatchedItems.append(c.selectedItems[0])
c.recentField = "mismatchedItems"
return c
if (
c.playfieldItems[c.selectedItems[0]] != c.playfieldItems[c.selectedItems[1]] c.playfieldItems[c.selectedItems[0]] != c.playfieldItems[c.selectedItems[1]]
): ):
c.mismatchedItems.clear() c.mismatchedItems.clear()

View File

@@ -116,6 +116,32 @@ def memory_test_shouldDeselectMismatchedItems(
return "ERR: memory_shouldDeselectMismatchedItems" return "ERR: memory_shouldDeselectMismatchedItems"
#} #}
def memory_test_shouldDeselectMismatchedItems_itemTwice(
) -> str:
c = memory_createContext()
c.playfieldSize = 2
c = memory_generateConstPlayfield(c)
# Select the same item twice.
c.selectedId = 0
c = memory_selectItem(c)
c.selectedId = 0
c = memory_selectItem(c)
# Detect mismatching.
c = memory_shouldDeselectMismatchedItems(c)
# See if the two selected items do not match.
if (
c.recentField == "mismatchedItems" and
len(c.mismatchedItems) == 1 and
c.mismatchedItems[0] == 0
):
return "OK: memory_shouldDeselectMismatchedItems_itemTwice"
#}
return "ERR: memory_shouldDeselectMismatchedItems_itemTwice"
#}
def memory_test_shouldDetectVictory( def memory_test_shouldDetectVictory(
) -> str: ) -> str:
c = memory_createContext() c = memory_createContext()