|
- from entities import *
- from llm import *
-
-
-
-
-
- @llm_by_value
- def memory_detectVictory(
- c: MemoryContext
- ) -> MemoryContext:
- if (
- c.recentField == "hiddenItems" and
- len(c.hiddenItems) == len(c.playfieldItems)
- ):
- c.victory = True
- c.recentField = "victory"
- return c
-
- c.recentField = None
- return c
-
-
-
-
-
-
- @llm_by_value
- def memory_deselectMismatchedItems(
- c: MemoryContext
- ) -> MemoryContext:
- if (
- c.recentField == "selectedItems" and
- len(c.selectedItems) == 2 and
- c.playfieldItems[c.selectedItems[0]] != c.playfieldItems[c.selectedItems[1]]
- ):
- c.mismatchedItems.clear()
- c.mismatchedItems.append(c.selectedItems[0])
- c.mismatchedItems.append(c.selectedItems[1])
- c.recentField = "mismatchedItems"
- return c
-
- c.recentField = None
- return c
-
-
-
- @llm_by_value
- def memory_generateConstPlayfield(
- c: MemoryContext
- ) -> MemoryContext:
- idGroups: dict[int, int] = { }
- id = 0
- for gid in range(0, c.playfieldSize):
- idGroups[id] = gid
- id += 1
- idGroups[id] = gid
- id += 1
-
- c.playfieldItems = idGroups
- c.recentField = "playfieldItems"
- return c
-
-
-
-
-
-
- @llm_by_value
- def memory_hideMatchingItems(
- c: MemoryContext
- ) -> MemoryContext:
- if (
- c.recentField == "selectedItems" and
- len(c.selectedItems) == 2 and
- c.playfieldItems[c.selectedItems[0]] == c.playfieldItems[c.selectedItems[1]]
- ):
- c.hiddenItems.append(c.selectedItems[0])
- c.hiddenItems.append(c.selectedItems[1])
- c.recentField = "hiddenItems"
- return c
-
- c.recentField = None
- return c
-
-
-
-
-
-
-
- @llm_by_value
- def memory_selectItem(
- c: MemoryContext
- ) -> MemoryContext:
- if (
- len(c.selectedItems) == 2
- ):
- c.selectedItems = []
-
- if (
- c.recentField == "selectedId"
- ):
- c.selectedItems.append(c.selectedId)
- c.recentField = "selectedItems"
- return c
-
- c.recentField = None
- return c
-
-
-
-
- def test_memory_generateConstPlayfield(
- ) -> str:
- c = memory_createEmptyContext()
- c.playfieldSize = 2
- c = memory_generateConstPlayfield(c)
- if (
- c.recentField == "playfieldItems" and
- len(c.playfieldItems) == 4 and
- c.playfieldItems[0] == 0 and
- c.playfieldItems[1] == 0 and
- c.playfieldItems[2] == 1 and
- c.playfieldItems[3] == 1
- ):
- return "OK: memory_generateConstPlayfield"
-
- return "ERR: memory_generateConstPlayfield"
-
-
- def test_memory_selectItem(
- ) -> str:
- c = memory_createEmptyContext()
- c.playfieldSize = 2
- c = memory_generateConstPlayfield(c)
-
-
- c.selectedId = 0
- c.recentField = "selectedId"
- c = memory_selectItem(c)
-
-
- if (
- c.recentField == "selectedItems" and
- len(c.selectedItems) == 1 and
- c.selectedItems[0] == 0
- ):
- return "OK: selectItem"
-
- return "ERR: selectItem"
-
-
- def test_selectTwoItems(
- ) -> str:
- c = memory_createEmptyContext()
- c.playfieldSize = 2
- c = memory_generateConstPlayfield(c)
-
-
- c.selectedId = 0
- c.recentField = "selectedId"
- c = memory_selectItem(c)
- c.selectedId = 1
- c.recentField = "selectedId"
- c = memory_selectItem(c)
-
-
- if (
- c.recentField == "selectedItems" and
- len(c.selectedItems) == 2 and
- c.selectedItems[0] == 0 and
- c.selectedItems[1] == 1
- ):
- return "OK: selectTwoItems"
-
- return "ERR: selectTwoItems"
-
-
- def test_selectThreeItems(
- ) -> str:
- c = memory_createEmptyContext()
- c.playfieldSize = 2
- c = memory_generateConstPlayfield(c)
-
-
- c.selectedId = 0
- c.recentField = "selectedId"
- c = memory_selectItem(c)
- c.selectedId = 1
- c.recentField = "selectedId"
- c = memory_selectItem(c)
- c.selectedId = 2
- c.recentField = "selectedId"
- c = memory_selectItem(c)
-
-
- if (
- c.recentField == "selectedItems" and
- len(c.selectedItems) == 1 and
- c.selectedItems[0] == 2
- ):
- return "OK: selectThreeItems"
-
- return "ERR: selectThreeItems"
-
-
- def test_memory_hideMatchingItems(
- ) -> str:
- c = memory_createEmptyContext()
- c.playfieldSize = 2
- c = memory_generateConstPlayfield(c)
-
-
- c.selectedId = 0
- c.recentField = "selectedId"
- c = memory_selectItem(c)
- c.selectedId = 1
- c.recentField = "selectedId"
- c = memory_selectItem(c)
-
-
- c = memory_hideMatchingItems(c)
-
-
- if (
- c.recentField == "hiddenItems" and
- len(c.hiddenItems) == 2 and
- c.hiddenItems[0] == 0 and
- c.hiddenItems[1] == 1
- ):
- return "OK: memory_hideMatchingItems"
-
- return "ERR: memory_hideMatchingItems"
-
-
- def test_memory_deselectMismatchedItems(
- ) -> str:
- c = memory_createEmptyContext()
- c.playfieldSize = 2
- c = memory_generateConstPlayfield(c)
-
-
- c.selectedId = 0
- c.recentField = "selectedId"
- c = memory_selectItem(c)
- c.selectedId = 2
- c.recentField = "selectedId"
- c = memory_selectItem(c)
-
-
- c = memory_deselectMismatchedItems(c)
-
-
- if (
- c.recentField == "mismatchedItems" and
- len(c.mismatchedItems) == 2 and
- c.mismatchedItems[0] == 0 and
- c.mismatchedItems[1] == 2
- ):
- return "OK: memory_deselectMismatchedItems"
-
- return "ERR: memory_deselectMismatchedItems"
-
-
- def test_memory_detectVictory(
- ) -> str:
- c = memory_createEmptyContext()
- c.playfieldSize = 2
- c = memory_generateConstPlayfield(c)
-
-
- c.selectedId = 0
- c.recentField = "selectedId"
- c = memory_selectItem(c)
- c.selectedId = 1
- c.recentField = "selectedId"
- c = memory_selectItem(c)
-
-
- c = memory_hideMatchingItems(c)
-
-
- c.selectedId = 2
- c.recentField = "selectedId"
- c = memory_selectItem(c)
- c.selectedId = 3
- c.recentField = "selectedId"
- c = memory_selectItem(c)
-
-
- c = memory_hideMatchingItems(c)
-
-
- c = memory_detectVictory(c)
-
-
- if (
- c.recentField == "victory" and
- c.victory == True
- ):
- return "OK: memory_detectVictory"
-
- return "ERR: memory_detectVictory"
-
-
- def test_passContextByValue(
- ) -> str:
- c = memory_createEmptyContext()
- c.playfieldSize = 2
- c = memory_generateConstPlayfield(c)
-
- c.selectedId = 0
- c.recentField = "selectedId"
- c1 = memory_selectItem(c)
-
- c.selectedId = 1
- c.recentField = "selectedId"
- c2 = memory_selectItem(c)
-
-
- if (
- c1.selectedId != c2.selectedId
- ):
- return "OK: passContextByValue"
-
- return "ERR: passContextByValue"
-
|