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.

memory.py 2.8KB

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