d
This commit is contained in:
204
v4/cli.py
204
v4/cli.py
@@ -1,99 +1,48 @@
|
|||||||
from cli_Context import *
|
from memory_Context import *
|
||||||
from llm import *
|
from llm import *
|
||||||
from memory import *
|
|
||||||
|
|
||||||
# Greet the user
|
# Greet the user
|
||||||
@llm_by_value
|
@llm_by_value
|
||||||
def cli_greetUser(
|
def cli_greetUser(
|
||||||
c: cli_Context
|
c: memory_Context
|
||||||
) -> cli_Context:
|
) -> memory_Context:
|
||||||
c.outputGreeting = "OGS Memory Command Line Interface"
|
|
||||||
c.recentField = "outputGreeting"
|
|
||||||
return c
|
|
||||||
#}
|
|
||||||
|
|
||||||
# Select item
|
|
||||||
#
|
|
||||||
# Conditions:
|
|
||||||
# 1. Id is digit, in bounds and not hidden
|
|
||||||
@llm_by_value
|
|
||||||
def cli_selectItem(
|
|
||||||
c: cli_Context
|
|
||||||
) -> cli_Context:
|
|
||||||
if (
|
if (
|
||||||
c.input.isdigit()
|
c.recentField == "launched" and
|
||||||
|
c.launched == True
|
||||||
):
|
):
|
||||||
# User ids start with 1 while memory module has ids starting with 0
|
c.outputGreeting = "OGS Memory Command Line Interface"
|
||||||
# Convert cli item id to memory item id
|
c.recentField = "outputGreeting"
|
||||||
c.cMemory.selectedId = int(c.input) - 1
|
|
||||||
c.cMemory = memory_selectItem(c.cMemory)
|
|
||||||
c.recentField = "cMemory"
|
|
||||||
return c
|
return c
|
||||||
#}
|
#}
|
||||||
c.recentField = "none"
|
c.recentField = "none"
|
||||||
return c
|
return c
|
||||||
#}
|
#}
|
||||||
|
|
||||||
# Ask user to select another item to have a pair of selected items
|
## Select item
|
||||||
@llm_by_value
|
##
|
||||||
def cli_shouldPromptSelection(
|
## Conditions:
|
||||||
c: cli_Context
|
## 1. Id is digit, in bounds and not hidden
|
||||||
) -> cli_Context:
|
|
||||||
if (
|
|
||||||
c.recentField == "cMemory" and
|
|
||||||
c.cMemory.recentField == "selectedItems" and
|
|
||||||
len(c.cMemory.selectedItems) == 1
|
|
||||||
):
|
|
||||||
c.outputPromptSelection = "Select the second item now:"
|
|
||||||
c.recentField = "outputPromptSelection"
|
|
||||||
return c
|
|
||||||
#}
|
|
||||||
c.recentField = "none"
|
|
||||||
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:
|
|
||||||
# 1. Index out of bounds: less than minimum
|
|
||||||
# 2. Index out of bounds: greater than maximum
|
|
||||||
# 3. Item is already hidden
|
|
||||||
#@llm_by_value
|
#@llm_by_value
|
||||||
#def cli_shouldReportInvalidItemSelection(
|
#def cli_selectItem(
|
||||||
|
# c: cli_Context
|
||||||
|
#) -> cli_Context:
|
||||||
|
# if (
|
||||||
|
# c.input.isdigit()
|
||||||
|
# ):
|
||||||
|
# # User ids start with 1 while memory module has ids starting with 0
|
||||||
|
# # Convert cli item id to memory item id
|
||||||
|
# c.cMemory.selectedId = int(c.input) - 1
|
||||||
|
# c.cMemory = memory_selectItem(c.cMemory)
|
||||||
|
# c.recentField = "cMemory"
|
||||||
|
# return c
|
||||||
|
# #}
|
||||||
|
# c.recentField = "none"
|
||||||
|
# return c
|
||||||
|
##}
|
||||||
|
#
|
||||||
|
## Ask user to select another item to have a pair of selected items
|
||||||
|
#@llm_by_value
|
||||||
|
#def cli_shouldPromptSelection(
|
||||||
# c: cli_Context
|
# c: cli_Context
|
||||||
#) -> cli_Context:
|
#) -> cli_Context:
|
||||||
# if (
|
# if (
|
||||||
@@ -108,20 +57,77 @@ def cli_shouldReportMismatchedItems(
|
|||||||
# c.recentField = "none"
|
# c.recentField = "none"
|
||||||
# return c
|
# return c
|
||||||
##}
|
##}
|
||||||
|
#
|
||||||
# Show help (aka commands)
|
## Report matched items
|
||||||
@llm_by_value
|
#@llm_by_value
|
||||||
def cli_showHelp(
|
#def cli_shouldReportMatchedItems(
|
||||||
c: cli_Context
|
# c: cli_Context
|
||||||
) -> cli_Context:
|
#) -> cli_Context:
|
||||||
if (
|
# if (
|
||||||
c.input == "h" or
|
# c.recentField == "cMemory" and
|
||||||
c.input == "help"
|
# c.cMemory.recentField == "hiddenItems"
|
||||||
):
|
# ):
|
||||||
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.outputMatchedItems = "Items matched! Go on:"
|
||||||
c.recentField = "outputHelp"
|
# c.recentField = "outputMatchedItems"
|
||||||
return c
|
# return c
|
||||||
#}
|
# #}
|
||||||
c.recentField = "none"
|
# c.recentField = "none"
|
||||||
return c
|
# 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:
|
||||||
|
## 1. Index out of bounds: less than minimum
|
||||||
|
## 2. Index out of bounds: greater than maximum
|
||||||
|
## 3. Item is already hidden
|
||||||
|
##@llm_by_value
|
||||||
|
##def cli_shouldReportInvalidItemSelection(
|
||||||
|
## c: cli_Context
|
||||||
|
##) -> cli_Context:
|
||||||
|
## if (
|
||||||
|
## c.recentField == "cMemory" and
|
||||||
|
## c.cMemory.recentField == "selectedItems" and
|
||||||
|
## len(c.cMemory.selectedItems) == 1
|
||||||
|
## ):
|
||||||
|
## c.outputPromptSelection = "Select the second item now:"
|
||||||
|
## c.recentField = "outputPromptSelection"
|
||||||
|
## return c
|
||||||
|
## #}
|
||||||
|
## c.recentField = "none"
|
||||||
|
## return c
|
||||||
|
###}
|
||||||
|
#
|
||||||
|
## Show help (aka commands)
|
||||||
|
#@llm_by_value
|
||||||
|
#def cli_showHelp(
|
||||||
|
# c: cli_Context
|
||||||
|
#) -> cli_Context:
|
||||||
|
# if (
|
||||||
|
# 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\nEnter your choice:"
|
||||||
|
# c.recentField = "outputHelp"
|
||||||
|
# return c
|
||||||
|
# #}
|
||||||
|
# c.recentField = "none"
|
||||||
|
# return c
|
||||||
|
##}
|
||||||
|
|||||||
145
v4/cli_test.py
145
v4/cli_test.py
@@ -1,11 +1,12 @@
|
|||||||
from cli import *
|
from cli import *
|
||||||
from cli_Context import *
|
|
||||||
from memory import *
|
from memory import *
|
||||||
from memory_Context import *
|
from memory_Context import *
|
||||||
|
|
||||||
def cli_test_greetUser(
|
def cli_test_greetUser(
|
||||||
) -> str:
|
) -> str:
|
||||||
c = cli_createContext()
|
c = memory_createContext()
|
||||||
|
c.launched = True
|
||||||
|
c.recentField = "launched"
|
||||||
c = cli_greetUser(c)
|
c = cli_greetUser(c)
|
||||||
if (
|
if (
|
||||||
c.recentField == "outputGreeting"
|
c.recentField == "outputGreeting"
|
||||||
@@ -15,73 +16,73 @@ def cli_test_greetUser(
|
|||||||
return "ERR: cli_greetUser"
|
return "ERR: cli_greetUser"
|
||||||
#}
|
#}
|
||||||
|
|
||||||
def cli_test_selectItem(
|
#def cli_test_selectItem(
|
||||||
) -> str:
|
#) -> str:
|
||||||
c = cli_createContext()
|
# c = cli_createContext()
|
||||||
c.cMemory = memory_createContext()
|
# c.cMemory = memory_createContext()
|
||||||
c.input = "1"
|
# c.input = "1"
|
||||||
c = cli_selectItem(c)
|
# c = cli_selectItem(c)
|
||||||
if (
|
# if (
|
||||||
c.recentField == "cMemory" and
|
# c.recentField == "cMemory" and
|
||||||
c.cMemory.recentField == "selectedItems"
|
# c.cMemory.recentField == "selectedItems"
|
||||||
):
|
# ):
|
||||||
return "OK: cli_selectItem"
|
# return "OK: cli_selectItem"
|
||||||
#}
|
# #}
|
||||||
return "ERR: cli_selectItem"
|
# return "ERR: cli_selectItem"
|
||||||
#}
|
##}
|
||||||
|
#
|
||||||
def cli_test_shouldPromptSelection(
|
#def cli_test_shouldPromptSelection(
|
||||||
) -> str:
|
#) -> str:
|
||||||
c = cli_createContext()
|
# c = cli_createContext()
|
||||||
c.cMemory = memory_createContext()
|
# c.cMemory = memory_createContext()
|
||||||
c.input = "1"
|
# c.input = "1"
|
||||||
c = cli_selectItem(c)
|
# c = cli_selectItem(c)
|
||||||
c = cli_shouldPromptSelection(c)
|
# c = cli_shouldPromptSelection(c)
|
||||||
if (
|
# if (
|
||||||
c.recentField == "outputPromptSelection"
|
# c.recentField == "outputPromptSelection"
|
||||||
):
|
# ):
|
||||||
return "OK: cli_shouldPromptSelection"
|
# return "OK: cli_shouldPromptSelection"
|
||||||
#}
|
# #}
|
||||||
return "ERR: cli_shouldPromptSelection"
|
# return "ERR: cli_shouldPromptSelection"
|
||||||
#}
|
##}
|
||||||
|
#
|
||||||
def cli_test_shouldReportIvalidItemSelection_outOfBoundsMin(
|
#def cli_test_shouldReportIvalidItemSelection_outOfBoundsMin(
|
||||||
) -> str:
|
#) -> str:
|
||||||
c = cli_createContext()
|
# c = cli_createContext()
|
||||||
c.cMemory = memory_createContext()
|
# c.cMemory = memory_createContext()
|
||||||
c.input = "0"
|
# c.input = "0"
|
||||||
c = cli_selectItem(c)
|
# c = cli_selectItem(c)
|
||||||
c = cli_shouldReportInvalidItemSelection(c)
|
# c = cli_shouldReportInvalidItemSelection(c)
|
||||||
if (
|
# if (
|
||||||
c.recentField == "outputInvalidItemSelection"
|
# c.recentField == "outputInvalidItemSelection"
|
||||||
):
|
# ):
|
||||||
return "OK: cli_shouldReportInvalidItemSelection"
|
# return "OK: cli_shouldReportInvalidItemSelection"
|
||||||
#}
|
# #}
|
||||||
return "ERR: cli_shouldReportInvalidItemSelection"
|
# return "ERR: cli_shouldReportInvalidItemSelection"
|
||||||
#}
|
##}
|
||||||
|
#
|
||||||
def cli_test_showHelp_h(
|
#def cli_test_showHelp_h(
|
||||||
) -> str:
|
#) -> str:
|
||||||
c = cli_createContext()
|
# c = cli_createContext()
|
||||||
c.input = "h"
|
# c.input = "h"
|
||||||
c = cli_showHelp(c)
|
# c = cli_showHelp(c)
|
||||||
if (
|
# if (
|
||||||
c.recentField == "outputHelp"
|
# c.recentField == "outputHelp"
|
||||||
):
|
# ):
|
||||||
return "OK: cli_showHelp_h"
|
# return "OK: cli_showHelp_h"
|
||||||
#}
|
# #}
|
||||||
return "ERR: cli_showHelp_h"
|
# return "ERR: cli_showHelp_h"
|
||||||
#}
|
##}
|
||||||
|
#
|
||||||
def cli_test_showHelp_help(
|
#def cli_test_showHelp_help(
|
||||||
) -> str:
|
#) -> str:
|
||||||
c = cli_createContext()
|
# c = cli_createContext()
|
||||||
c.input = "help"
|
# c.input = "help"
|
||||||
c = cli_showHelp(c)
|
# c = cli_showHelp(c)
|
||||||
if (
|
# if (
|
||||||
c.recentField == "outputHelp"
|
# c.recentField == "outputHelp"
|
||||||
):
|
# ):
|
||||||
return "OK: cli_showHelp_help"
|
# return "OK: cli_showHelp_help"
|
||||||
#}
|
# #}
|
||||||
return "ERR: cli_showHelp_help"
|
# return "ERR: cli_showHelp_help"
|
||||||
#}
|
##}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#from cli import *
|
from cli import *
|
||||||
#from cli_test import *
|
from cli_test import *
|
||||||
from memory_test import *
|
from memory_test import *
|
||||||
#from shell import *
|
#from shell import *
|
||||||
#import sys
|
#import sys
|
||||||
@@ -13,7 +13,7 @@ print(memory_test_selectItem_1x())
|
|||||||
print(memory_test_selectItem_2x())
|
print(memory_test_selectItem_2x())
|
||||||
print(memory_test_selectItem_3x())
|
print(memory_test_selectItem_3x())
|
||||||
|
|
||||||
#print(cli_test_greetUser())
|
print(cli_test_greetUser())
|
||||||
#print(cli_test_selectItem())
|
#print(cli_test_selectItem())
|
||||||
#print(cli_test_shouldPromptSelection())
|
#print(cli_test_shouldPromptSelection())
|
||||||
##print(cli_test_shouldReportIvalidItemSelection_outOfBoundsMin())
|
##print(cli_test_shouldReportIvalidItemSelection_outOfBoundsMin())
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
class memory_Context:
|
class memory_Context:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.hiddenItems = []
|
self.hiddenItems = []
|
||||||
|
self.input = ""
|
||||||
self.mismatchedItems = []
|
self.mismatchedItems = []
|
||||||
|
self.outputGreeting = ""
|
||||||
|
self.outputHelp = ""
|
||||||
|
self.outputMatchedItems = ""
|
||||||
|
self.outputMismatchedItems = ""
|
||||||
self.playfieldItems = {}
|
self.playfieldItems = {}
|
||||||
self.playfieldSize = 0
|
self.playfieldSize = 0
|
||||||
self.recentField = "none"
|
self.recentField = "none"
|
||||||
@@ -9,6 +14,7 @@ class memory_Context:
|
|||||||
self.selectedItems = []
|
self.selectedItems = []
|
||||||
self.victory = False
|
self.victory = False
|
||||||
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return self.__str__()
|
return self.__str__()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user