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.

109 lines
2.2KB

  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. # 1. Two items are selected and they are of different groups
  43. @llm_by_value
  44. def memory_shouldDeselectMismatchedItems(
  45. c: memory_Context
  46. ) -> memory_Context:
  47. if (
  48. c.recentField == "selectedItems" and
  49. len(c.selectedItems) == 2 and
  50. c.playfieldItems[c.selectedItems[0]] != c.playfieldItems[c.selectedItems[1]]
  51. ):
  52. c.mismatchedItems.clear()
  53. c.mismatchedItems.append(c.selectedItems[0])
  54. c.mismatchedItems.append(c.selectedItems[1])
  55. c.recentField = "mismatchedItems"
  56. return c
  57. c.recentField = None
  58. return c
  59. #}
  60. # Detect victory
  61. #
  62. # Conditions:
  63. # 1. Matching items have just been hidden and all items are hidden now
  64. @llm_by_value
  65. def memory_shouldDetectVictory(
  66. c: memory_Context
  67. ) -> memory_Context:
  68. if (
  69. c.recentField == "hiddenItems" and
  70. len(c.hiddenItems) == len(c.playfieldItems)
  71. ):
  72. c.victory = True
  73. c.recentField = "victory"
  74. return c
  75. c.recentField = None
  76. return c
  77. #}
  78. # Hide matching selected items
  79. #
  80. # Conditions:
  81. # 1. Two items are selected and they are of the same group
  82. @llm_by_value
  83. def memory_shouldHideMatchingItems(
  84. c: memory_Context
  85. ) -> memory_Context:
  86. if (
  87. c.recentField == "selectedItems" and
  88. len(c.selectedItems) == 2 and
  89. c.playfieldItems[c.selectedItems[0]] == c.playfieldItems[c.selectedItems[1]]
  90. ):
  91. c.hiddenItems.append(c.selectedItems[0])
  92. c.hiddenItems.append(c.selectedItems[1])
  93. c.recentField = "hiddenItems"
  94. return c
  95. c.recentField = None
  96. return c
  97. #}