Михаил Капелько 8 months ago
parent
commit
1adaab1afd
3 changed files with 45 additions and 3 deletions
  1. +1
    -0
      v3/main.py
  2. +18
    -3
      v3/memory.py
  3. +26
    -0
      v3/memory_test.py

+ 1
- 0
v3/main.py View File

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



+ 18
- 3
v3/memory.py View File

@@ -45,14 +45,29 @@ def memory_selectItem(
# Deselect mismatched items
#
# 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
def memory_shouldDeselectMismatchedItems(
c: memory_Context
) -> memory_Context:
if (
if not (
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.mismatchedItems.clear()


+ 26
- 0
v3/memory_test.py View File

@@ -116,6 +116,32 @@ def memory_test_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(
) -> str:
c = memory_createContext()


Loading…
Cancel
Save