Research portable Memory game | Исследовать портируемую игру Память
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
2.5KB

  1. from memory_Context import *
  2. from llm import *
  3. ########
  4. # Client initiated input
  5. ########
  6. # Generate constant playfield
  7. @llm_by_value
  8. def memory_generateConstPlayfield(
  9. c: memory_Context
  10. ) -> memory_Context:
  11. idGroups: dict[int, int] = { }
  12. id = 0
  13. for gid in range(0, c.playfieldSize):
  14. idGroups[id] = gid
  15. id += 1
  16. idGroups[id] = gid
  17. id += 1
  18. #}
  19. c.playfieldItems = idGroups
  20. c.recentField = "playfieldItems"
  21. return c
  22. #}
  23. # Select item
  24. @llm_by_value
  25. def memory_selectItem(
  26. c: memory_Context
  27. ) -> memory_Context:
  28. if (
  29. len(c.selectedItems) == 2
  30. ):
  31. c.selectedItems.clear()
  32. #}
  33. c.selectedItems.append(c.selectedId)
  34. c.recentField = "selectedItems"
  35. return c
  36. #}
  37. ########
  38. # System initiated reaction
  39. ########
  40. # Deselect mismatched items
  41. #
  42. # Conditions:
  43. # 0. Two items has just been selected
  44. # 1. The same item has been selected twice
  45. # 2. Selected items are of different groups
  46. @llm_by_value
  47. def memory_shouldDeselectMismatchedItems(
  48. c: memory_Context
  49. ) -> memory_Context:
  50. if not (
  51. c.recentField == "selectedItems" and
  52. len(c.selectedItems) == 2
  53. ):
  54. c.recentField = "none"
  55. return c
  56. #}
  57. if (
  58. c.selectedItems[0] == c.selectedItems[1]
  59. ):
  60. c.mismatchedItems.clear()
  61. c.mismatchedItems.append(c.selectedItems[0])
  62. c.recentField = "mismatchedItems"
  63. return c
  64. #}
  65. if (
  66. c.playfieldItems[c.selectedItems[0]] != c.playfieldItems[c.selectedItems[1]]
  67. ):
  68. c.mismatchedItems.clear()
  69. c.mismatchedItems.append(c.selectedItems[0])
  70. c.mismatchedItems.append(c.selectedItems[1])
  71. c.recentField = "mismatchedItems"
  72. return c
  73. #}
  74. c.recentField = "none"
  75. return c
  76. #}
  77. # Detect victory
  78. #
  79. # Conditions:
  80. # 1. Matching items have just been hidden and all items are hidden now
  81. @llm_by_value
  82. def memory_shouldDetectVictory(
  83. c: memory_Context
  84. ) -> memory_Context:
  85. if (
  86. c.recentField == "hiddenItems" and
  87. len(c.hiddenItems) == len(c.playfieldItems)
  88. ):
  89. c.victory = True
  90. c.recentField = "victory"
  91. return c
  92. #}
  93. c.recentField = "none"
  94. return c
  95. #}
  96. # Hide matching selected items
  97. #
  98. # Conditions:
  99. # 1. Two items are selected and they are of the same group
  100. @llm_by_value
  101. def memory_shouldHideMatchingItems(
  102. c: memory_Context
  103. ) -> memory_Context:
  104. if (
  105. c.recentField == "selectedItems" and
  106. len(c.selectedItems) == 2 and
  107. c.playfieldItems[c.selectedItems[0]] == c.playfieldItems[c.selectedItems[1]]
  108. ):
  109. c.hiddenItems.append(c.selectedItems[0])
  110. c.hiddenItems.append(c.selectedItems[1])
  111. c.recentField = "hiddenItems"
  112. return c
  113. #}
  114. c.recentField = "none"
  115. return c
  116. #}