Research portable Memory game | Исследовать портируемую игру Память
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

144 satır
3.4KB

  1. from memory_api import *
  2. from memory_api_Context import *
  3. from llm import *
  4. def memory_api_test_deselectMismatchedItems(
  5. ) -> str:
  6. c = memory_api_createContext()
  7. c.playfieldSize = 2
  8. c = memory_api_generateConstPlayfield(c)
  9. # Select two items of different groups.
  10. c.selectedId = 0
  11. c.recentField = "selectedId"
  12. c = memory_api_selectItem(c)
  13. c.selectedId = 2
  14. c.recentField = "selectedId"
  15. c = memory_api_selectItem(c)
  16. # Detect mismatching.
  17. c = memory_api_deselectMismatchedItems(c)
  18. # See if the two selected items do not match.
  19. if (
  20. c.recentField == "mismatchedItems" and
  21. len(c.mismatchedItems) == 2 and
  22. c.mismatchedItems[0] == 0 and
  23. c.mismatchedItems[1] == 2
  24. ):
  25. return "OK: memory_api_deselectMismatchedItems"
  26. #}
  27. return "ERR: memory_api_deselectMismatchedItems"
  28. #}
  29. def memory_api_test_detectVictory(
  30. ) -> str:
  31. c = memory_api_createContext()
  32. c.playfieldSize = 2
  33. c = memory_api_generateConstPlayfield(c)
  34. # Select the first two items of the same group.
  35. c.selectedId = 0
  36. c.recentField = "selectedId"
  37. c = memory_api_selectItem(c)
  38. c.selectedId = 1
  39. c.recentField = "selectedId"
  40. c = memory_api_selectItem(c)
  41. # Hide the first pair.
  42. c = memory_api_hideMatchingItems(c)
  43. # Select the last two items of the same group.
  44. c.selectedId = 2
  45. c.recentField = "selectedId"
  46. c = memory_api_selectItem(c)
  47. c.selectedId = 3
  48. c.recentField = "selectedId"
  49. c = memory_api_selectItem(c)
  50. # Hide the second pair.
  51. c = memory_api_hideMatchingItems(c)
  52. # Detect victory.
  53. c = memory_api_detectVictory(c)
  54. # See if victory has been detected.
  55. if (
  56. c.recentField == "victory" and
  57. c.victory == True
  58. ):
  59. return "OK: memory_api_detectVictory"
  60. #}
  61. return "ERR: memory_api_detectVictory"
  62. #}
  63. def memory_api_test_generateConstPlayfield(
  64. ) -> str:
  65. c = memory_api_createContext()
  66. c.playfieldSize = 2
  67. c = memory_api_generateConstPlayfield(c)
  68. if (
  69. c.recentField == "playfieldItems" and
  70. len(c.playfieldItems) == 4 and
  71. c.playfieldItems[0] == 0 and
  72. c.playfieldItems[1] == 0 and
  73. c.playfieldItems[2] == 1 and
  74. c.playfieldItems[3] == 1
  75. ):
  76. return "OK: memory_api_generateConstPlayfield"
  77. #}
  78. return "ERR: memory_api_generateConstPlayfield"
  79. #}
  80. def memory_api_test_hideMatchingItems(
  81. ) -> str:
  82. c = memory_api_createContext()
  83. c.playfieldSize = 2
  84. c = memory_api_generateConstPlayfield(c)
  85. # Select two items of the same group.
  86. c.selectedId = 0
  87. c.recentField = "selectedId"
  88. c = memory_api_selectItem(c)
  89. c.selectedId = 1
  90. c.recentField = "selectedId"
  91. c = memory_api_selectItem(c)
  92. # Hide matching items.
  93. c = memory_api_hideMatchingItems(c)
  94. # See if the two selected items match.
  95. if (
  96. c.recentField == "hiddenItems" and
  97. len(c.hiddenItems) == 2 and
  98. c.hiddenItems[0] == 0 and
  99. c.hiddenItems[1] == 1
  100. ):
  101. return "OK: memory_api_hideMatchingItems"
  102. #}
  103. return "ERR: memory_api_hideMatchingItems"
  104. #}
  105. def memory_api_test_selectItem(
  106. ) -> str:
  107. c = memory_api_createContext()
  108. c.playfieldSize = 2
  109. c = memory_api_generateConstPlayfield(c)
  110. # Select the first item.
  111. c.selectedId = 0
  112. c.recentField = "selectedId"
  113. c = memory_api_selectItem(c)
  114. # See if it's in selectedItems now.
  115. if (
  116. c.recentField == "selectedItems" and
  117. len(c.selectedItems) == 1 and
  118. c.selectedItems[0] == 0
  119. ):
  120. return "OK: memory_api_selectItem"
  121. #}
  122. return "ERR: memory_api_selectItem"
  123. #}