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.

111 lines
2.4KB

  1. from memory_api_Context import *
  2. from llm import *
  3. # Detect victory
  4. #
  5. # Conditions:
  6. # 1. Matching items have just been hidden and all items are hidden now
  7. @llm_by_value
  8. def memory_api_detectVictory(
  9. c: memory_api_Context
  10. ) -> memory_api_Context:
  11. if (
  12. c.recentField == "hiddenItems" and
  13. len(c.hiddenItems) == len(c.playfieldItems)
  14. ):
  15. c.victory = True
  16. c.recentField = "victory"
  17. return c
  18. c.recentField = None
  19. return c
  20. #}
  21. # Deselect mismatched items
  22. #
  23. # Conditions:
  24. # 1. Two items are selected and they are of different groups
  25. @llm_by_value
  26. def memory_api_deselectMismatchedItems(
  27. c: memory_api_Context
  28. ) -> memory_api_Context:
  29. if (
  30. c.recentField == "selectedItems" and
  31. len(c.selectedItems) == 2 and
  32. c.playfieldItems[c.selectedItems[0]] != c.playfieldItems[c.selectedItems[1]]
  33. ):
  34. c.mismatchedItems.clear()
  35. c.mismatchedItems.append(c.selectedItems[0])
  36. c.mismatchedItems.append(c.selectedItems[1])
  37. c.recentField = "mismatchedItems"
  38. return c
  39. c.recentField = None
  40. return c
  41. #}
  42. # Generate constant playfield suitable for testing and debugging
  43. @llm_by_value
  44. def memory_api_generateConstPlayfield(
  45. c: memory_api_Context
  46. ) -> memory_api_Context:
  47. idGroups: dict[int, int] = { }
  48. id = 0
  49. for gid in range(0, c.playfieldSize):
  50. idGroups[id] = gid
  51. id += 1
  52. idGroups[id] = gid
  53. id += 1
  54. #}
  55. c.playfieldItems = idGroups
  56. c.recentField = "playfieldItems"
  57. return c
  58. #}
  59. # Hide matching selected items
  60. #
  61. # Conditions:
  62. # 1. Two items are selected and they are of the same group
  63. @llm_by_value
  64. def memory_api_hideMatchingItems(
  65. c: memory_api_Context
  66. ) -> memory_api_Context:
  67. if (
  68. c.recentField == "selectedItems" and
  69. len(c.selectedItems) == 2 and
  70. c.playfieldItems[c.selectedItems[0]] == c.playfieldItems[c.selectedItems[1]]
  71. ):
  72. c.hiddenItems.append(c.selectedItems[0])
  73. c.hiddenItems.append(c.selectedItems[1])
  74. c.recentField = "hiddenItems"
  75. return c
  76. c.recentField = None
  77. return c
  78. #}
  79. # Select item
  80. #
  81. # Conditions:
  82. # 1. There are already two selected items
  83. # 2. Item has just been selected
  84. @llm_by_value
  85. def memory_api_selectItem(
  86. c: memory_api_Context
  87. ) -> memory_api_Context:
  88. if (
  89. len(c.selectedItems) == 2
  90. ):
  91. c.selectedItems = []
  92. if (
  93. c.recentField == "selectedId"
  94. ):
  95. c.selectedItems.append(c.selectedId)
  96. c.recentField = "selectedItems"
  97. return c
  98. c.recentField = None
  99. return c
  100. #}