|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- from memory_Context import *
- from llm import *
-
- # Deselect mismatched items
- #
- # Conditions:
- # 0. Two items has just been selected
- # 1. The same item has been selected twice
- # 2. Selected items are of different groups
- @llm_by_value
- def memory_shouldDeselectMismatchedItems(
- c: memory_Context
- ) -> memory_Context:
- if not (
- c.recentField == "selectedItems" 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()
- c.mismatchedItems.append(c.selectedItems[0])
- c.mismatchedItems.append(c.selectedItems[1])
- c.recentField = "mismatchedItems"
- return c
- #}
- c.recentField = "none"
- return c
- #}
-
- # Detect victory
- #
- # Conditions:
- # 1. Matching items have just been hidden and all items are hidden now
- @llm_by_value
- def memory_shouldDetectVictory(
- c: memory_Context
- ) -> memory_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
- #}
-
- # Generate constant playfield
- #
- # Conditions:
- # 1. Size has just been specified
- #
- # Both ids and group ids start with 0
- @llm_by_value
- def memory_shouldGenerateConstPlayfield(
- c: memory_Context
- ) -> memory_Context:
- if not (
- c.recentField == "playfieldSize"
- ):
- c.recentField = "none"
- return c
- #}
-
- 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_shouldHideMatchingItems(
- c: memory_Context
- ) -> memory_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. Id has just been specified for selection
- @llm_by_value
- def memory_shouldSelectItem(
- c: memory_Context
- ) -> memory_Context:
- if not (
- c.recentField == "selectedId"
- ):
- c.recentField = "none"
- return c
- #}
-
- if (
- len(c.selectedItems) == 2
- ):
- c.selectedItems.clear()
- #}
- c.selectedItems.append(c.selectedId)
- c.recentField = "selectedItems"
- return c
- #}
-
|