d
This commit is contained in:
68
v4/cli.py
68
v4/cli.py
@@ -12,6 +12,36 @@ def cli_greetUser(
|
|||||||
return c
|
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 not (
|
||||||
|
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
|
||||||
|
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
|
# Ask user to select another item to have a pair of selected items
|
||||||
@llm_by_value
|
@llm_by_value
|
||||||
def cli_shouldPromptSelection(
|
def cli_shouldPromptSelection(
|
||||||
@@ -30,22 +60,28 @@ def cli_shouldPromptSelection(
|
|||||||
return c
|
return c
|
||||||
#}
|
#}
|
||||||
|
|
||||||
# Select item
|
# Report selection of invalid item ids
|
||||||
@llm_by_value
|
#
|
||||||
def cli_selectItem(
|
# Conditions:
|
||||||
c: cli_Context
|
# 1. Index out of bounds: less than minimum
|
||||||
) -> cli_Context:
|
# 2. Index out of bounds: greater than maximum
|
||||||
if (
|
# 3. Item is already hidden
|
||||||
c.input.isdigit()
|
#@llm_by_value
|
||||||
):
|
#def cli_shouldReportInvalidItemSelection(
|
||||||
id = int(c.input)
|
# c: cli_Context
|
||||||
c.cMemory = memory_selectItem(c.cMemory)
|
#) -> cli_Context:
|
||||||
c.recentField = "cMemory"
|
# if (
|
||||||
return c
|
# c.recentField == "cMemory" and
|
||||||
#}
|
# c.cMemory.recentField == "selectedItems" and
|
||||||
c.recentField = "none"
|
# len(c.cMemory.selectedItems) == 1
|
||||||
return c
|
# ):
|
||||||
#}
|
# c.outputPromptSelection = "Select the second item now:"
|
||||||
|
# c.recentField = "outputPromptSelection"
|
||||||
|
# return c
|
||||||
|
# #}
|
||||||
|
# c.recentField = "none"
|
||||||
|
# return c
|
||||||
|
##}
|
||||||
|
|
||||||
# Show help (aka commands)
|
# Show help (aka commands)
|
||||||
@llm_by_value
|
@llm_by_value
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
from cli import *
|
from cli import *
|
||||||
from cli_Context import *
|
from cli_Context import *
|
||||||
|
from memory import *
|
||||||
|
from memory_Context import *
|
||||||
|
|
||||||
def cli_test_greetUser(
|
def cli_test_greetUser(
|
||||||
) -> str:
|
) -> str:
|
||||||
@@ -13,6 +15,51 @@ def cli_test_greetUser(
|
|||||||
return "ERR: cli_greetUser"
|
return "ERR: cli_greetUser"
|
||||||
#}
|
#}
|
||||||
|
|
||||||
|
def cli_test_selectItem(
|
||||||
|
) -> str:
|
||||||
|
c = cli_createContext()
|
||||||
|
c.cMemory = memory_createContext()
|
||||||
|
c.input = "1"
|
||||||
|
c = cli_selectItem(c)
|
||||||
|
if (
|
||||||
|
c.recentField == "cMemory" and
|
||||||
|
c.cMemory.recentField == "selectedItems"
|
||||||
|
):
|
||||||
|
return "OK: cli_selectItem"
|
||||||
|
#}
|
||||||
|
return "ERR: cli_selectItem"
|
||||||
|
#}
|
||||||
|
|
||||||
|
def cli_test_shouldPromptSelection(
|
||||||
|
) -> str:
|
||||||
|
c = cli_createContext()
|
||||||
|
c.cMemory = memory_createContext()
|
||||||
|
c.input = "1"
|
||||||
|
c = cli_selectItem(c)
|
||||||
|
c = cli_shouldPromptSelection(c)
|
||||||
|
if (
|
||||||
|
c.recentField == "outputPromptSelection"
|
||||||
|
):
|
||||||
|
return "OK: cli_shouldPromptSelection"
|
||||||
|
#}
|
||||||
|
return "ERR: cli_shouldPromptSelection"
|
||||||
|
#}
|
||||||
|
|
||||||
|
def cli_test_shouldReportIvalidItemSelection_outOfBoundsMin(
|
||||||
|
) -> str:
|
||||||
|
c = cli_createContext()
|
||||||
|
c.cMemory = memory_createContext()
|
||||||
|
c.input = "0"
|
||||||
|
c = cli_selectItem(c)
|
||||||
|
c = cli_shouldReportInvalidItemSelection(c)
|
||||||
|
if (
|
||||||
|
c.recentField == "outputInvalidItemSelection"
|
||||||
|
):
|
||||||
|
return "OK: cli_shouldReportInvalidItemSelection"
|
||||||
|
#}
|
||||||
|
return "ERR: cli_shouldReportInvalidItemSelection"
|
||||||
|
#}
|
||||||
|
|
||||||
def cli_test_showHelp_h(
|
def cli_test_showHelp_h(
|
||||||
) -> str:
|
) -> str:
|
||||||
c = cli_createContext()
|
c = cli_createContext()
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ print(memory_test_shouldDetectVictory())
|
|||||||
print(memory_test_shouldHideMatchingItems())
|
print(memory_test_shouldHideMatchingItems())
|
||||||
|
|
||||||
print(cli_test_greetUser())
|
print(cli_test_greetUser())
|
||||||
|
print(cli_test_selectItem())
|
||||||
|
print(cli_test_shouldPromptSelection())
|
||||||
|
print(cli_test_shouldReportIvalidItemSelection_outOfBoundsMin())
|
||||||
print(cli_test_showHelp_h())
|
print(cli_test_showHelp_h())
|
||||||
print(cli_test_showHelp_help())
|
print(cli_test_showHelp_help())
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ from llm import *
|
|||||||
########
|
########
|
||||||
|
|
||||||
# Generate constant playfield
|
# Generate constant playfield
|
||||||
|
#
|
||||||
|
# Both ids and group ids start with 0
|
||||||
@llm_by_value
|
@llm_by_value
|
||||||
def memory_generateConstPlayfield(
|
def memory_generateConstPlayfield(
|
||||||
c: memory_Context
|
c: memory_Context
|
||||||
|
|||||||
Reference in New Issue
Block a user