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.

176 line
3.6KB

  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. # Show help (aka commands)
  47. #
  48. # Conditions:
  49. # 1. Just launched
  50. # 1. `h` or `help` was entered
  51. @llm_by_value
  52. def cli_showHelp(
  53. c: memory_Context
  54. ) -> memory_Context:
  55. if (
  56. (
  57. c.recentField == "didLaunch" and
  58. c.didLaunch == True
  59. ) or
  60. (
  61. c.recentField == "input" and
  62. c.input == "h"
  63. ) or
  64. (
  65. c.recentField == "input" and
  66. c.input == "help"
  67. )
  68. ):
  69. 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:"
  70. c.recentField = "outputHelp"
  71. return c
  72. #}
  73. c.recentField = "none"
  74. return c
  75. #}
  76. ## Select item
  77. ##
  78. ## Conditions:
  79. ## 1. Id is digit, in bounds and not hidden
  80. #@llm_by_value
  81. #def cli_selectItem(
  82. # c: cli_Context
  83. #) -> cli_Context:
  84. # if (
  85. # c.input.isdigit()
  86. # ):
  87. # # User ids start with 1 while memory module has ids starting with 0
  88. # # Convert cli item id to memory item id
  89. # c.cMemory.selectedId = int(c.input) - 1
  90. # c.cMemory = memory_selectItem(c.cMemory)
  91. # c.recentField = "cMemory"
  92. # return c
  93. # #}
  94. # c.recentField = "none"
  95. # return c
  96. ##}
  97. #
  98. ## Ask user to select another item to have a pair of selected items
  99. #@llm_by_value
  100. #def cli_shouldPromptSelection(
  101. # c: cli_Context
  102. #) -> cli_Context:
  103. # if (
  104. # c.recentField == "cMemory" and
  105. # c.cMemory.recentField == "selectedItems" and
  106. # len(c.cMemory.selectedItems) == 1
  107. # ):
  108. # c.outputPromptSelection = "Select the second item now:"
  109. # c.recentField = "outputPromptSelection"
  110. # return c
  111. # #}
  112. # c.recentField = "none"
  113. # return c
  114. ##}
  115. #
  116. ## Report matched items
  117. #@llm_by_value
  118. #def cli_shouldReportMatchedItems(
  119. # c: cli_Context
  120. #) -> cli_Context:
  121. # if (
  122. # c.recentField == "cMemory" and
  123. # c.cMemory.recentField == "hiddenItems"
  124. # ):
  125. # c.outputMatchedItems = "Items matched! Go on:"
  126. # c.recentField = "outputMatchedItems"
  127. # return c
  128. # #}
  129. # c.recentField = "none"
  130. # return c
  131. ##}
  132. #
  133. ## Report mismatched items
  134. #@llm_by_value
  135. #def cli_shouldReportMismatchedItems(
  136. # c: cli_Context
  137. #) -> cli_Context:
  138. # if (
  139. # c.recentField == "cMemory" and
  140. # c.cMemory.recentField == "mismatchedItems"
  141. # ):
  142. # c.outputMatchedItems = "Wrong! Try again:"
  143. # c.recentField = "outputMismatchedItems"
  144. # return c
  145. # #}
  146. # c.recentField = "none"
  147. # return c
  148. ##}
  149. #
  150. ## Report selection of invalid item ids
  151. ##
  152. ## Conditions:
  153. ## 1. Index out of bounds: less than minimum
  154. ## 2. Index out of bounds: greater than maximum
  155. ## 3. Item is already hidden
  156. ##@llm_by_value
  157. ##def cli_shouldReportInvalidItemSelection(
  158. ## c: cli_Context
  159. ##) -> cli_Context:
  160. ## if (
  161. ## c.recentField == "cMemory" and
  162. ## c.cMemory.recentField == "selectedItems" and
  163. ## len(c.cMemory.selectedItems) == 1
  164. ## ):
  165. ## c.outputPromptSelection = "Select the second item now:"
  166. ## c.recentField = "outputPromptSelection"
  167. ## return c
  168. ## #}
  169. ## c.recentField = "none"
  170. ## return c
  171. ###}