From d046c67108715707990b10954841d146f75530cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Mon, 13 May 2024 23:00:35 +0300 Subject: [PATCH] d --- "v4/\\" | 91 +++++++++++++++++++++++++++++++++++++++++++++++ v4/cli.py | 46 ++++++++++++++++++------ v4/cli_Context.py | 2 ++ v4/main.py | 4 ++- v4/shell.py | 33 +++++++++++++++-- 5 files changed, 162 insertions(+), 14 deletions(-) create mode 100644 "v4/\\" diff --git "a/v4/\\" "b/v4/\\" new file mode 100644 index 0000000..679e775 --- /dev/null +++ "b/v4/\\" @@ -0,0 +1,91 @@ +from cli import * +from llm import * +from shell_Context import * + +# Greet the user upon start +@llm_by_value +def shell_launch( + c: shell_Context +) -> shell_Context: + c.cCLI = cli_greetUser(c.cCLI) + c.cCLI.input = "help" + c.cCLI = cli_showHelp(c.cCLI) + + c.output = c.cCLI.outputGreeting + "\n" + c.cCLI.outputHelp + return c +#} + +# Switch among CLI functions based on input +# +# Conditions: +# 1. User requested to quit the game +# 2. User plays the game +@llm_by_value +def shell_processInput( + c: shell_Context +) -> shell_Context: + # Exit + if ( + c.input == "e" or + c.input == "exit" or + c.input == "q" or + c.input == "quit" + ): + c.exit = True + return c + #} + + c.cCLI.input = c.input + c.output = "" + + # Help (aka commands) + c.cCLI = cli_showHelp(c.cCLI) + if ( + c.cCLI.recentField == "outputHelp" + ): + c.output += c.cCLI.outputHelp + #} + + c.cCLI = cli_selectItem(c.cCLI) + + # Game actions. + if ( + c.cCLI.recentField == "cMemory" + ): + # Prompt second item. + cli = cli_shouldPromptSelection(c.cCLI) + if ( + cli.recentField == "outputPromptSelection" + ): + c.output += cli.outputPromptSelection + #} + + # Check matching items. + cli = c.cCLI + memory = memory_shouldHideMatchingItems(cli.cMemory) + cli.recentField = "cMemory" + # Report matched items. + cli = cli_shouldReportMatchedItems(cli) + if ( + cli.recentField == "outputMatchedItems" + ): + c.output += cli.outputMatchedItems + c.cCLI.cMemory = memory + #} + + # Check mismatching items. + memory = memory_shouldDeselectMismatchedItems(c.cCLI.cMemory) + c.cCLI.recentField = "cMemory" + # Report mismatched items. + cli = cli_shouldReportMismatchedItems(c.cCLI) + if ( + cli.recentField == "outputMismatchedItems" + ): + c.output += cli.outputMismatchedItems + c.cCLI.cMemory = memory + #} + + #} + + return c +#} diff --git a/v4/cli.py b/v4/cli.py index a3bb780..4277626 100644 --- a/v4/cli.py +++ b/v4/cli.py @@ -20,16 +20,8 @@ def cli_greetUser( def cli_selectItem( c: cli_Context ) -> cli_Context: - if not ( + if ( c.input.isdigit() - ): - c.recentField = "none" - return c - #} - - int(c.input) >= 1 and - int(c.input) <= c.cMemory.playfieldSize * 2 and - int(c.input) not in c.cMemory.hiddenItems ): # User ids start with 1 while memory module has ids starting with 0 # Convert cli item id to memory item id @@ -60,6 +52,40 @@ def cli_shouldPromptSelection( return c #} +# Report matched items +@llm_by_value +def cli_shouldReportMatchedItems( + c: cli_Context +) -> cli_Context: + if ( + c.recentField == "cMemory" and + c.cMemory.recentField == "hiddenItems" + ): + c.outputMatchedItems = "Items matched! Go on:" + c.recentField = "outputMatchedItems" + return c + #} + c.recentField = "none" + return c +#} + +# Report mismatched items +@llm_by_value +def cli_shouldReportMismatchedItems( + c: cli_Context +) -> cli_Context: + if ( + c.recentField == "cMemory" and + c.cMemory.recentField == "mismatchedItems" + ): + c.outputMatchedItems = "Wrong! Try again:" + c.recentField = "outputMismatchedItems" + return c + #} + c.recentField = "none" + return c +#} + # Report selection of invalid item ids # # Conditions: @@ -92,7 +118,7 @@ def cli_showHelp( c.input == "h" or c.input == "help" ): - 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\n" + 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:" c.recentField = "outputHelp" return c #} diff --git a/v4/cli_Context.py b/v4/cli_Context.py index a4b190d..15d1340 100644 --- a/v4/cli_Context.py +++ b/v4/cli_Context.py @@ -5,6 +5,8 @@ class cli_Context: self.outputGreeting = "" self.outputHelp = "" self.recentField = "none" + self.outputMatchedItems = "" + self.outputMismatchedItems = "" def cli_createContext(): return cli_Context() diff --git a/v4/main.py b/v4/main.py index d9bfc26..274bc8d 100644 --- a/v4/main.py +++ b/v4/main.py @@ -16,13 +16,15 @@ print(memory_test_shouldHideMatchingItems()) print(cli_test_greetUser()) print(cli_test_selectItem()) print(cli_test_shouldPromptSelection()) -print(cli_test_shouldReportIvalidItemSelection_outOfBoundsMin()) +#print(cli_test_shouldReportIvalidItemSelection_outOfBoundsMin()) print(cli_test_showHelp_h()) print(cli_test_showHelp_help()) c = shell_createContext() c.cCLI = cli_createContext() c.cCLI.cMemory = memory_createContext() +c.cCLI.cMemory.playfieldSize = 2 +c.cCLI.cMemory = memory_generateConstPlayfield(c.cCLI.cMemory) c = shell_launch(c) print(c.output) diff --git a/v4/shell.py b/v4/shell.py index 174bdb2..33f84a4 100644 --- a/v4/shell.py +++ b/v4/shell.py @@ -52,12 +52,39 @@ def shell_processInput( if ( c.cCLI.recentField == "cMemory" ): - psCLI = cli_shouldPromptSelection(c.cCLI) + # Prompt second item. + cli = cli_shouldPromptSelection(c.cCLI) if ( - psCLI.recentField == "outputPromptSelection" + cli.recentField == "outputPromptSelection" ): - c.output += psCLI.outputPromptSelection + c.output += cli.outputPromptSelection #} + + # Check matching items. + cli = c.cCLI + cli.cMemory = memory_shouldHideMatchingItems(c.cCLI.cMemory) + cli.recentField = "cMemory" + # Report matched items. + cli = cli_shouldReportMatchedItems(cli) + if ( + cli.recentField == "outputMatchedItems" + ): + c.output += cli.outputMatchedItems + c.cCLI.cMemory = memory + #} + + # Check mismatching items. + memory = memory_shouldDeselectMismatchedItems(c.cCLI.cMemory) + c.cCLI.recentField = "cMemory" + # Report mismatched items. + cli = cli_shouldReportMismatchedItems(c.cCLI) + if ( + cli.recentField == "outputMismatchedItems" + ): + c.output += cli.outputMismatchedItems + c.cCLI.cMemory = memory + #} + #} return c