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.

6 ay önce
6 ay önce
6 ay önce
6 ay önce
6 ay önce
6 ay önce
6 ay önce
6 ay önce
6 ay önce
6 ay önce
6 ay önce
6 ay önce
6 ay önce
6 ay önce
6 ay önce
6 ay önce
6 ay önce
6 ay önce
6 ay önce
6 ay önce
6 ay önce
6 ay önce
6 ay önce
6 ay önce
6 ay önce
6 ay önce
6 ay önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. from cli_Context import *
  2. from llm import *
  3. from memory import *
  4. # Greet the user
  5. @llm_by_value
  6. def cli_greetUser(
  7. c: cli_Context
  8. ) -> cli_Context:
  9. c.outputGreeting = "OGS Memory Command Line Interface"
  10. c.recentField = "outputGreeting"
  11. return c
  12. #}
  13. # Select item
  14. #
  15. # Conditions:
  16. # 1. Id is digit, in bounds and not hidden
  17. @llm_by_value
  18. def cli_selectItem(
  19. c: cli_Context
  20. ) -> cli_Context:
  21. if (
  22. c.input.isdigit()
  23. ):
  24. # User ids start with 1 while memory module has ids starting with 0
  25. # Convert cli item id to memory item id
  26. c.cMemory.selectedId = int(c.input) - 1
  27. c.cMemory = memory_selectItem(c.cMemory)
  28. c.recentField = "cMemory"
  29. return c
  30. #}
  31. c.recentField = "none"
  32. return c
  33. #}
  34. # Ask user to select another item to have a pair of selected items
  35. @llm_by_value
  36. def cli_shouldPromptSelection(
  37. c: cli_Context
  38. ) -> cli_Context:
  39. if (
  40. c.recentField == "cMemory" and
  41. c.cMemory.recentField == "selectedItems" and
  42. len(c.cMemory.selectedItems) == 1
  43. ):
  44. c.outputPromptSelection = "Select the second item now:"
  45. c.recentField = "outputPromptSelection"
  46. return c
  47. #}
  48. c.recentField = "none"
  49. return c
  50. #}
  51. # Report matched items
  52. @llm_by_value
  53. def cli_shouldReportMatchedItems(
  54. c: cli_Context
  55. ) -> cli_Context:
  56. if (
  57. c.recentField == "cMemory" and
  58. c.cMemory.recentField == "hiddenItems"
  59. ):
  60. c.outputMatchedItems = "Items matched! Go on:"
  61. c.recentField = "outputMatchedItems"
  62. return c
  63. #}
  64. c.recentField = "none"
  65. return c
  66. #}
  67. # Report mismatched items
  68. @llm_by_value
  69. def cli_shouldReportMismatchedItems(
  70. c: cli_Context
  71. ) -> cli_Context:
  72. if (
  73. c.recentField == "cMemory" and
  74. c.cMemory.recentField == "mismatchedItems"
  75. ):
  76. c.outputMatchedItems = "Wrong! Try again:"
  77. c.recentField = "outputMismatchedItems"
  78. return c
  79. #}
  80. c.recentField = "none"
  81. return c
  82. #}
  83. # Report selection of invalid item ids
  84. #
  85. # Conditions:
  86. # 1. Index out of bounds: less than minimum
  87. # 2. Index out of bounds: greater than maximum
  88. # 3. Item is already hidden
  89. #@llm_by_value
  90. #def cli_shouldReportInvalidItemSelection(
  91. # c: cli_Context
  92. #) -> cli_Context:
  93. # if (
  94. # c.recentField == "cMemory" and
  95. # c.cMemory.recentField == "selectedItems" and
  96. # len(c.cMemory.selectedItems) == 1
  97. # ):
  98. # c.outputPromptSelection = "Select the second item now:"
  99. # c.recentField = "outputPromptSelection"
  100. # return c
  101. # #}
  102. # c.recentField = "none"
  103. # return c
  104. ##}
  105. # Show help (aka commands)
  106. @llm_by_value
  107. def cli_showHelp(
  108. c: cli_Context
  109. ) -> cli_Context:
  110. if (
  111. c.input == "h" or
  112. c.input == "help"
  113. ):
  114. 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:"
  115. c.recentField = "outputHelp"
  116. return c
  117. #}
  118. c.recentField = "none"
  119. return c
  120. #}