|
- from memory_api_Context import *
- from llm import *
-
- # Detect victory
- #
- # Conditions:
- # 1. Matching items have just been hidden and all items are hidden now
- @llm_by_value
- def memory_api_detectVictory(
- c: memory_api_Context
- ) -> memory_api_Context:
- if (
- c.recentField == "hiddenItems" and
- len(c.hiddenItems) == len(c.playfieldItems)
- ):
- c.victory = True
- c.recentField = "victory"
- return c
-
- c.recentField = None
- return c
- #}
-
- # Deselect mismatched items
- #
- # Conditions:
- # 1. Two items are selected and they are of different groups
- @llm_by_value
- def memory_api_deselectMismatchedItems(
- c: memory_api_Context
- ) -> memory_api_Context:
- 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
- #}
-
- # Generate constant playfield suitable for testing and debugging
- @llm_by_value
- def memory_api_generateConstPlayfield(
- c: memory_api_Context
- ) -> memory_api_Context:
- 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
- #}
-
- # Hide matching selected items
- #
- # Conditions:
- # 1. Two items are selected and they are of the same group
- @llm_by_value
- def memory_api_hideMatchingItems(
- c: memory_api_Context
- ) -> memory_api_Context:
- 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
- #}
-
- # Select item
- #
- # Conditions:
- # 1. There are already two selected items
- # 2. Item has just been selected
- @llm_by_value
- def memory_api_selectItem(
- c: memory_api_Context
- ) -> memory_api_Context:
- 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
- #}
|