Research portable Memory game | Исследовать портируемую игру Память
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

124 řádky
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 = []
  32. c.selectedItems.append(c.selectedId)
  33. c.recentField = "selectedItems"
  34. return c
  35. #}
  36. ########
  37. # System initiated reaction
  38. ########
  39. # Deselect mismatched items
  40. #
  41. # Conditions:
  42. # 0. Two items has just been selected
  43. # 1. The same item has been selected twice
  44. # 1. Selected items are of different groups
  45. @llm_by_value
  46. def memory_shouldDeselectMismatchedItems(
  47. c: memory_Context
  48. ) -> memory_Context:
  49. if not (
  50. c.recentField == "selectedItems" and
  51. len(c.selectedItems) == 2
  52. ):
  53. c.recentField = None
  54. return c
  55. if (
  56. c.selectedItems[0] == c.selectedItems[1]
  57. ):
  58. c.mismatchedItems.clear()
  59. c.mismatchedItems.append(c.selectedItems[0])
  60. c.recentField = "mismatchedItems"
  61. return c
  62. if (
  63. c.playfieldItems[c.selectedItems[0]] != c.playfieldItems[c.selectedItems[1]]
  64. ):
  65. c.mismatchedItems.clear()
  66. c.mismatchedItems.append(c.selectedItems[0])
  67. c.mismatchedItems.append(c.selectedItems[1])
  68. c.recentField = "mismatchedItems"
  69. return c
  70. c.recentField = None
  71. return c
  72. #}
  73. # Detect victory
  74. #
  75. # Conditions:
  76. # 1. Matching items have just been hidden and all items are hidden now
  77. @llm_by_value
  78. def memory_shouldDetectVictory(
  79. c: memory_Context
  80. ) -> memory_Context:
  81. if (
  82. c.recentField == "hiddenItems" and
  83. len(c.hiddenItems) == len(c.playfieldItems)
  84. ):
  85. c.victory = True
  86. c.recentField = "victory"
  87. return c
  88. c.recentField = None
  89. return c
  90. #}
  91. # Hide matching selected items
  92. #
  93. # Conditions:
  94. # 1. Two items are selected and they are of the same group
  95. @llm_by_value
  96. def memory_shouldHideMatchingItems(
  97. c: memory_Context
  98. ) -> memory_Context:
  99. if (
  100. c.recentField == "selectedItems" and
  101. len(c.selectedItems) == 2 and
  102. c.playfieldItems[c.selectedItems[0]] == c.playfieldItems[c.selectedItems[1]]
  103. ):
  104. c.hiddenItems.append(c.selectedItems[0])
  105. c.hiddenItems.append(c.selectedItems[1])
  106. c.recentField = "hiddenItems"
  107. return c
  108. c.recentField = None
  109. return c
  110. #}