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.

175 lines
3.4KB

  1. from memory_Context import *
  2. from llm import *
  3. # Exit
  4. #
  5. # Conditions:
  6. # 1. `e`, `exit`, `q`, or `quit` was entered
  7. @llm_by_value
  8. def cli_exit(
  9. c: memory_Context
  10. ) -> memory_Context:
  11. if (
  12. c.recentField == "input" and
  13. (
  14. c.input == "e" or
  15. c.input == "exit" or
  16. c.input == "q" or
  17. c.input == "quit"
  18. )
  19. ):
  20. c.exit = True
  21. c.recentField = "exit"
  22. return c
  23. #}
  24. c.recentField = "none"
  25. return c
  26. #}
  27. # Greet the user
  28. #
  29. # Conditions:
  30. # 1. Just launched
  31. @llm_by_value
  32. def cli_greetUser(
  33. c: memory_Context
  34. ) -> memory_Context:
  35. if (
  36. c.recentField == "didLaunch" and
  37. c.didLaunch == True
  38. ):
  39. c.outputGreeting = "OGS Memory Command Line Interface"
  40. c.recentField = "outputGreeting"
  41. return c
  42. #}
  43. c.recentField = "none"
  44. return c
  45. #}
  46. # Ask user to select second item to have a pair of selected items
  47. @llm_by_value
  48. def cli_promptSecondItemSelection(
  49. c: memory_Context
  50. ) -> memory_Context:
  51. if (
  52. c.recentField == "selectedItems" and
  53. len(c.selectedItems) == 1
  54. ):
  55. c.outputPromptSelection = "Select the second item now:"
  56. c.recentField = "outputPromptSelection"
  57. return c
  58. #}
  59. c.recentField = "none"
  60. return c
  61. #}
  62. # Report matched items
  63. @llm_by_value
  64. def cli_reportMatchedItems(
  65. c: memory_Context
  66. ) -> memory_Context:
  67. if (
  68. c.recentField == "hiddenItems"
  69. ):
  70. c.outputMatchedItems = "Items matched! Go on:"
  71. c.recentField = "outputMatchedItems"
  72. return c
  73. #}
  74. c.recentField = "none"
  75. return c
  76. #}
  77. # Select item
  78. #
  79. # Conditions:
  80. # 1. Id is digit
  81. @llm_by_value
  82. def cli_selectItem(
  83. c: memory_Context
  84. ) -> memory_Context:
  85. if (
  86. c.recentField == "input" and
  87. c.input.isdigit()
  88. ):
  89. # CLI ids start with 1 while memory module has ids starting with 0
  90. # Convert CLI id to memory id
  91. c.selectedId = int(c.input) - 1
  92. c.recentField = "selectedId"
  93. return c
  94. #}
  95. c.recentField = "none"
  96. return c
  97. #}
  98. # Show help (aka commands)
  99. #
  100. # Conditions:
  101. # 1. Just launched
  102. # 1. `h` or `help` was entered
  103. @llm_by_value
  104. def cli_showHelp(
  105. c: memory_Context
  106. ) -> memory_Context:
  107. if (
  108. (
  109. c.recentField == "didLaunch" and
  110. c.didLaunch == True
  111. ) or
  112. (
  113. c.recentField == "input" and
  114. c.input == "h"
  115. ) or
  116. (
  117. c.recentField == "input" and
  118. c.input == "help"
  119. )
  120. ):
  121. c.outputHelp = "Commands:\n\te, exit, q, quit\n\t\tExit\n\th, help\n\t\tList commands\n\t1, 2, 3, ...\n\t\tSelect item\nEnter your choice:"
  122. c.recentField = "outputHelp"
  123. return c
  124. #}
  125. c.recentField = "none"
  126. return c
  127. #}
  128. ## Report mismatched items
  129. #@llm_by_value
  130. #def cli_shouldReportMismatchedItems(
  131. # c: cli_Context
  132. #) -> cli_Context:
  133. # if (
  134. # c.recentField == "cMemory" and
  135. # c.cMemory.recentField == "mismatchedItems"
  136. # ):
  137. # c.outputMatchedItems = "Wrong! Try again:"
  138. # c.recentField = "outputMismatchedItems"
  139. # return c
  140. # #}
  141. # c.recentField = "none"
  142. # return c
  143. ##}
  144. #
  145. ## Report selection of invalid item ids
  146. ##
  147. ## Conditions:
  148. ## 1. Index out of bounds: less than minimum
  149. ## 2. Index out of bounds: greater than maximum
  150. ## 3. Item is already hidden
  151. ##@llm_by_value
  152. ##def cli_shouldReportInvalidItemSelection(
  153. ## c: cli_Context
  154. ##) -> cli_Context:
  155. ## if (
  156. ## c.recentField == "cMemory" and
  157. ## c.cMemory.recentField == "selectedItems" and
  158. ## len(c.cMemory.selectedItems) == 1
  159. ## ):
  160. ## c.outputPromptSelection = "Select the second item now:"
  161. ## c.recentField = "outputPromptSelection"
  162. ## return c
  163. ## #}
  164. ## c.recentField = "none"
  165. ## return c
  166. ###}