Research portable Memory game | Исследовать портируемую игру Память
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

seq.py 5.0KB

6 månader sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. from entities import *
  2. from llm import *
  3. # Execute selections and verify
  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: MemoryContext
  10. ) -> MemoryContext:
  11. # Test.
  12. def test_memory_generateConstPlayfield(
  13. ) -> str:
  14. c = memory_createEmptyContext()
  15. c.playfieldSize = 2
  16. c = memory_generateConstPlayfield(c)
  17. if (
  18. c.recentField == "playfieldItems" and
  19. len(c.playfieldItems) == 4 and
  20. c.playfieldItems[0] == 0 and
  21. c.playfieldItems[1] == 0 and
  22. c.playfieldItems[2] == 1 and
  23. c.playfieldItems[3] == 1
  24. ):
  25. return "OK: memory_generateConstPlayfield"
  26. #}
  27. return "ERR: memory_generateConstPlayfield"
  28. #}
  29. def test_memory_selectItem(
  30. ) -> str:
  31. c = memory_createEmptyContext()
  32. c.playfieldSize = 2
  33. c = memory_generateConstPlayfield(c)
  34. # Select the first item.
  35. c.selectedId = 0
  36. c.recentField = "selectedId"
  37. c = memory_selectItem(c)
  38. # See if it's in selectedItems now.
  39. if (
  40. c.recentField == "selectedItems" and
  41. len(c.selectedItems) == 1 and
  42. c.selectedItems[0] == 0
  43. ):
  44. return "OK: selectItem"
  45. #}
  46. return "ERR: selectItem"
  47. #}
  48. def test_selectTwoItems(
  49. ) -> str:
  50. c = memory_createEmptyContext()
  51. c.playfieldSize = 2
  52. c = memory_generateConstPlayfield(c)
  53. # Select the first two items.
  54. c.selectedId = 0
  55. c.recentField = "selectedId"
  56. c = memory_selectItem(c)
  57. c.selectedId = 1
  58. c.recentField = "selectedId"
  59. c = memory_selectItem(c)
  60. # See if it's both items are selected now.
  61. if (
  62. c.recentField == "selectedItems" and
  63. len(c.selectedItems) == 2 and
  64. c.selectedItems[0] == 0 and
  65. c.selectedItems[1] == 1
  66. ):
  67. return "OK: selectTwoItems"
  68. #}
  69. return "ERR: selectTwoItems"
  70. #}
  71. def test_selectThreeItems(
  72. ) -> str:
  73. c = memory_createEmptyContext()
  74. c.playfieldSize = 2
  75. c = memory_generateConstPlayfield(c)
  76. # Select three items.
  77. c.selectedId = 0
  78. c.recentField = "selectedId"
  79. c = memory_selectItem(c)
  80. c.selectedId = 1
  81. c.recentField = "selectedId"
  82. c = memory_selectItem(c)
  83. c.selectedId = 2
  84. c.recentField = "selectedId"
  85. c = memory_selectItem(c)
  86. # See if only one (last) item is selected now.
  87. if (
  88. c.recentField == "selectedItems" and
  89. len(c.selectedItems) == 1 and
  90. c.selectedItems[0] == 2
  91. ):
  92. return "OK: selectThreeItems"
  93. #}
  94. return "ERR: selectThreeItems"
  95. #}
  96. def test_memory_hideMatchingItems(
  97. ) -> str:
  98. c = memory_createEmptyContext()
  99. c.playfieldSize = 2
  100. c = memory_generateConstPlayfield(c)
  101. # Select two items of the same group.
  102. c.selectedId = 0
  103. c.recentField = "selectedId"
  104. c = memory_selectItem(c)
  105. c.selectedId = 1
  106. c.recentField = "selectedId"
  107. c = memory_selectItem(c)
  108. # Hide matching items.
  109. c = memory_hideMatchingItems(c)
  110. # See if the two selected items match.
  111. if (
  112. c.recentField == "hiddenItems" and
  113. len(c.hiddenItems) == 2 and
  114. c.hiddenItems[0] == 0 and
  115. c.hiddenItems[1] == 1
  116. ):
  117. return "OK: memory_hideMatchingItems"
  118. #}
  119. return "ERR: memory_hideMatchingItems"
  120. #}
  121. def test_memory_deselectMismatchedItems(
  122. ) -> str:
  123. c = memory_createEmptyContext()
  124. c.playfieldSize = 2
  125. c = memory_generateConstPlayfield(c)
  126. # Select two items of different groups.
  127. c.selectedId = 0
  128. c.recentField = "selectedId"
  129. c = memory_selectItem(c)
  130. c.selectedId = 2
  131. c.recentField = "selectedId"
  132. c = memory_selectItem(c)
  133. # Detect mismatching.
  134. c = memory_deselectMismatchedItems(c)
  135. # See if the two selected items do not match.
  136. if (
  137. c.recentField == "mismatchedItems" and
  138. len(c.mismatchedItems) == 2 and
  139. c.mismatchedItems[0] == 0 and
  140. c.mismatchedItems[1] == 2
  141. ):
  142. return "OK: memory_deselectMismatchedItems"
  143. #}
  144. return "ERR: memory_deselectMismatchedItems"
  145. #}
  146. def test_memory_detectVictory(
  147. ) -> str:
  148. c = memory_createEmptyContext()
  149. c.playfieldSize = 2
  150. c = memory_generateConstPlayfield(c)
  151. # Select the first two items of the same group.
  152. c.selectedId = 0
  153. c.recentField = "selectedId"
  154. c = memory_selectItem(c)
  155. c.selectedId = 1
  156. c.recentField = "selectedId"
  157. c = memory_selectItem(c)
  158. # Hide the first pair.
  159. c = memory_hideMatchingItems(c)
  160. # Select the last two items of the same group.
  161. c.selectedId = 2
  162. c.recentField = "selectedId"
  163. c = memory_selectItem(c)
  164. c.selectedId = 3
  165. c.recentField = "selectedId"
  166. c = memory_selectItem(c)
  167. # Hide the second pair.
  168. c = memory_hideMatchingItems(c)
  169. # Detect victory.
  170. c = memory_detectVictory(c)
  171. # See if victory has been detected.
  172. if (
  173. c.recentField == "victory" and
  174. c.victory == True
  175. ):
  176. return "OK: memory_detectVictory"
  177. #}
  178. return "ERR: memory_detectVictory"
  179. #}
  180. def test_passContextByValue(
  181. ) -> str:
  182. c = memory_createEmptyContext()
  183. c.playfieldSize = 2
  184. c = memory_generateConstPlayfield(c)
  185. c.selectedId = 0
  186. c.recentField = "selectedId"
  187. c1 = memory_selectItem(c)
  188. c.selectedId = 1
  189. c.recentField = "selectedId"
  190. c2 = memory_selectItem(c)
  191. # See if c1 and c2 have different recentField.
  192. if (
  193. c1.selectedId != c2.selectedId
  194. ):
  195. return "OK: passContextByValue"
  196. return "ERR: passContextByValue"
  197. #}