Михаил Капелько 8 月之前
父節點
當前提交
1adaab1afd
共有 3 個文件被更改,包括 45 次插入3 次删除
  1. +1
    -0
      v3/main.py
  2. +18
    -3
      v3/memory.py
  3. +26
    -0
      v3/memory_test.py

+ 1
- 0
v3/main.py 查看文件

@@ -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 查看文件

@@ -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 查看文件

@@ -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…
取消
儲存