d
This commit is contained in:
60
v4/main.py
60
v4/main.py
@@ -1,37 +1,37 @@
|
|||||||
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
|
||||||
|
|
||||||
print(memory_test_generateConstPlayfield())
|
|
||||||
print(memory_test_selectItem_1x())
|
|
||||||
print(memory_test_selectItem_2x())
|
|
||||||
print(memory_test_selectItem_3x())
|
|
||||||
print(memory_test_shouldDeselectMismatchedItems())
|
print(memory_test_shouldDeselectMismatchedItems())
|
||||||
print(memory_test_shouldDeselectMismatchedItems_itemTwice())
|
print(memory_test_shouldDeselectMismatchedItems_itemTwice())
|
||||||
print(memory_test_shouldDetectVictory())
|
print(memory_test_shouldDetectVictory())
|
||||||
|
print(memory_test_shouldGenerateConstPlayfield())
|
||||||
print(memory_test_shouldHideMatchingItems())
|
print(memory_test_shouldHideMatchingItems())
|
||||||
|
print(memory_test_shouldSelectItem_1x())
|
||||||
|
print(memory_test_shouldSelectItem_2x())
|
||||||
|
print(memory_test_shouldSelectItem_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())
|
||||||
print(cli_test_showHelp_h())
|
#print(cli_test_showHelp_h())
|
||||||
print(cli_test_showHelp_help())
|
#print(cli_test_showHelp_help())
|
||||||
|
#
|
||||||
c = shell_createContext()
|
#c = shell_createContext()
|
||||||
c.cCLI = cli_createContext()
|
#c.cCLI = cli_createContext()
|
||||||
c.cCLI.cMemory = memory_createContext()
|
#c.cCLI.cMemory = memory_createContext()
|
||||||
c.cCLI.cMemory.playfieldSize = 2
|
#c.cCLI.cMemory.playfieldSize = 2
|
||||||
c.cCLI.cMemory = memory_generateConstPlayfield(c.cCLI.cMemory)
|
#c.cCLI.cMemory = memory_generateConstPlayfield(c.cCLI.cMemory)
|
||||||
|
#
|
||||||
c = shell_launch(c)
|
#c = shell_launch(c)
|
||||||
print(c.output)
|
#print(c.output)
|
||||||
|
#
|
||||||
for line in sys.stdin:
|
#for line in sys.stdin:
|
||||||
c.input = line.rstrip()
|
# c.input = line.rstrip()
|
||||||
c = shell_processInput(c)
|
# c = shell_processInput(c)
|
||||||
if c.exit:
|
# if c.exit:
|
||||||
break
|
# break
|
||||||
print(c.output)
|
# print(c.output)
|
||||||
|
|||||||
99
v4/memory.py
99
v4/memory.py
@@ -1,49 +1,6 @@
|
|||||||
from memory_Context import *
|
from memory_Context import *
|
||||||
from llm import *
|
from llm import *
|
||||||
|
|
||||||
########
|
|
||||||
# Client initiated input
|
|
||||||
########
|
|
||||||
|
|
||||||
# Generate constant playfield
|
|
||||||
#
|
|
||||||
# Both ids and group ids start with 0
|
|
||||||
@llm_by_value
|
|
||||||
def memory_generateConstPlayfield(
|
|
||||||
c: memory_Context
|
|
||||||
) -> memory_Context:
|
|
||||||
idGroups: dict[int, int] = { }
|
|
||||||
id = 0
|
|
||||||
for gid in range(0, c.playfieldSize):
|
|
||||||
idGroups[id] = gid
|
|
||||||
id += 1
|
|
||||||
idGroups[id] = gid
|
|
||||||
id += 1
|
|
||||||
#}
|
|
||||||
c.playfieldItems = idGroups
|
|
||||||
c.recentField = "playfieldItems"
|
|
||||||
return c
|
|
||||||
#}
|
|
||||||
|
|
||||||
# Select item
|
|
||||||
@llm_by_value
|
|
||||||
def memory_selectItem(
|
|
||||||
c: memory_Context
|
|
||||||
) -> memory_Context:
|
|
||||||
if (
|
|
||||||
len(c.selectedItems) == 2
|
|
||||||
):
|
|
||||||
c.selectedItems.clear()
|
|
||||||
#}
|
|
||||||
c.selectedItems.append(c.selectedId)
|
|
||||||
c.recentField = "selectedItems"
|
|
||||||
return c
|
|
||||||
#}
|
|
||||||
|
|
||||||
########
|
|
||||||
# System initiated reaction
|
|
||||||
########
|
|
||||||
|
|
||||||
# Deselect mismatched items
|
# Deselect mismatched items
|
||||||
#
|
#
|
||||||
# Conditions:
|
# Conditions:
|
||||||
@@ -102,6 +59,36 @@ def memory_shouldDetectVictory(
|
|||||||
return c
|
return c
|
||||||
#}
|
#}
|
||||||
|
|
||||||
|
# Generate constant playfield
|
||||||
|
#
|
||||||
|
# Conditions:
|
||||||
|
# 1. Size has just been specified
|
||||||
|
#
|
||||||
|
# Both ids and group ids start with 0
|
||||||
|
@llm_by_value
|
||||||
|
def memory_shouldGenerateConstPlayfield(
|
||||||
|
c: memory_Context
|
||||||
|
) -> memory_Context:
|
||||||
|
if not (
|
||||||
|
c.recentField == "playfieldSize"
|
||||||
|
):
|
||||||
|
c.recentField = "none"
|
||||||
|
return c
|
||||||
|
#}
|
||||||
|
|
||||||
|
idGroups: dict[int, int] = { }
|
||||||
|
id = 0
|
||||||
|
for gid in range(0, c.playfieldSize):
|
||||||
|
idGroups[id] = gid
|
||||||
|
id += 1
|
||||||
|
idGroups[id] = gid
|
||||||
|
id += 1
|
||||||
|
#}
|
||||||
|
c.playfieldItems = idGroups
|
||||||
|
c.recentField = "playfieldItems"
|
||||||
|
return c
|
||||||
|
#}
|
||||||
|
|
||||||
# Hide matching selected items
|
# Hide matching selected items
|
||||||
#
|
#
|
||||||
# Conditions:
|
# Conditions:
|
||||||
@@ -123,3 +110,29 @@ def memory_shouldHideMatchingItems(
|
|||||||
c.recentField = "none"
|
c.recentField = "none"
|
||||||
return c
|
return c
|
||||||
#}
|
#}
|
||||||
|
|
||||||
|
# Select item
|
||||||
|
#
|
||||||
|
# Conditions:
|
||||||
|
# 1. Id has just been specified for selection
|
||||||
|
@llm_by_value
|
||||||
|
def memory_shouldSelectItem(
|
||||||
|
c: memory_Context
|
||||||
|
) -> memory_Context:
|
||||||
|
if not (
|
||||||
|
c.recentField == "selectedId"
|
||||||
|
):
|
||||||
|
c.recentField = "none"
|
||||||
|
return c
|
||||||
|
#}
|
||||||
|
|
||||||
|
if (
|
||||||
|
len(c.selectedItems) == 2
|
||||||
|
):
|
||||||
|
c.selectedItems.clear()
|
||||||
|
#}
|
||||||
|
c.selectedItems.append(c.selectedId)
|
||||||
|
c.recentField = "selectedItems"
|
||||||
|
return c
|
||||||
|
#}
|
||||||
|
|
||||||
|
|||||||
@@ -1,105 +1,20 @@
|
|||||||
from memory import *
|
from memory import *
|
||||||
from memory_Context import *
|
from memory_Context import *
|
||||||
|
|
||||||
def memory_test_generateConstPlayfield(
|
|
||||||
) -> str:
|
|
||||||
c = memory_createContext()
|
|
||||||
c.playfieldSize = 2
|
|
||||||
c = memory_generateConstPlayfield(c)
|
|
||||||
if (
|
|
||||||
c.recentField == "playfieldItems" and
|
|
||||||
len(c.playfieldItems) == 4 and
|
|
||||||
c.playfieldItems[0] == 0 and
|
|
||||||
c.playfieldItems[1] == 0 and
|
|
||||||
c.playfieldItems[2] == 1 and
|
|
||||||
c.playfieldItems[3] == 1
|
|
||||||
):
|
|
||||||
return "OK: memory_generateConstPlayfield"
|
|
||||||
#}
|
|
||||||
return "ERR: memory_generateConstPlayfield"
|
|
||||||
#}
|
|
||||||
|
|
||||||
def memory_test_selectItem_1x(
|
|
||||||
) -> str:
|
|
||||||
c = memory_createContext()
|
|
||||||
c.playfieldSize = 2
|
|
||||||
c = memory_generateConstPlayfield(c)
|
|
||||||
|
|
||||||
# Select the first item.
|
|
||||||
c.selectedId = 0
|
|
||||||
c = memory_selectItem(c)
|
|
||||||
|
|
||||||
# See if it's in selectedItems now.
|
|
||||||
if (
|
|
||||||
c.recentField == "selectedItems" and
|
|
||||||
len(c.selectedItems) == 1 and
|
|
||||||
c.selectedItems[0] == 0
|
|
||||||
):
|
|
||||||
return "OK: memory_selectItem_1x"
|
|
||||||
#}
|
|
||||||
return "ERR: memory_selectItem_1x"
|
|
||||||
#}
|
|
||||||
|
|
||||||
def memory_test_selectItem_2x(
|
|
||||||
) -> str:
|
|
||||||
c = memory_createContext()
|
|
||||||
c.playfieldSize = 2
|
|
||||||
c = memory_generateConstPlayfield(c)
|
|
||||||
|
|
||||||
# Select the first two items.
|
|
||||||
c.selectedId = 0
|
|
||||||
c = memory_selectItem(c)
|
|
||||||
c.selectedId = 1
|
|
||||||
c = memory_selectItem(c)
|
|
||||||
|
|
||||||
# See if both items are selected now.
|
|
||||||
if (
|
|
||||||
c.recentField == "selectedItems" and
|
|
||||||
len(c.selectedItems) == 2 and
|
|
||||||
c.selectedItems[0] == 0 and
|
|
||||||
c.selectedItems[1] == 1
|
|
||||||
):
|
|
||||||
return "OK: memory_selectItem_2x"
|
|
||||||
#}
|
|
||||||
return "ERR: memory_selectItem_2x"
|
|
||||||
#}
|
|
||||||
|
|
||||||
def memory_test_selectItem_3x(
|
|
||||||
) -> str:
|
|
||||||
c = memory_createContext()
|
|
||||||
c.playfieldSize = 2
|
|
||||||
c = memory_generateConstPlayfield(c)
|
|
||||||
|
|
||||||
# Select three items.
|
|
||||||
c.selectedId = 0
|
|
||||||
c = memory_selectItem(c)
|
|
||||||
c.selectedId = 1
|
|
||||||
c = memory_selectItem(c)
|
|
||||||
c.selectedId = 2
|
|
||||||
c = memory_selectItem(c)
|
|
||||||
|
|
||||||
# See if only one (last) item is selected now.
|
|
||||||
if (
|
|
||||||
c.recentField == "selectedItems" and
|
|
||||||
len(c.selectedItems) == 1 and
|
|
||||||
c.selectedItems[0] == 2
|
|
||||||
):
|
|
||||||
return "OK: memory_selectItem_3x"
|
|
||||||
#}
|
|
||||||
return "ERR: memory_selectItem_3x"
|
|
||||||
#}
|
|
||||||
|
|
||||||
def memory_test_shouldDeselectMismatchedItems(
|
def memory_test_shouldDeselectMismatchedItems(
|
||||||
) -> str:
|
) -> str:
|
||||||
c = memory_createContext()
|
c = memory_createContext()
|
||||||
c.playfieldSize = 2
|
c.playfieldSize = 2
|
||||||
c = memory_generateConstPlayfield(c)
|
c.recentField = "playfieldSize"
|
||||||
|
c = memory_shouldGenerateConstPlayfield(c)
|
||||||
|
|
||||||
# Select two items of different groups.
|
# Select two items of different groups.
|
||||||
c.selectedId = 0
|
c.selectedId = 0
|
||||||
c = memory_selectItem(c)
|
c.recentField = "selectedId"
|
||||||
|
c = memory_shouldSelectItem(c)
|
||||||
c.selectedId = 2
|
c.selectedId = 2
|
||||||
c = memory_selectItem(c)
|
c.recentField = "selectedId"
|
||||||
|
c = memory_shouldSelectItem(c)
|
||||||
|
|
||||||
# Detect mismatching.
|
# Detect mismatching.
|
||||||
c = memory_shouldDeselectMismatchedItems(c)
|
c = memory_shouldDeselectMismatchedItems(c)
|
||||||
@@ -120,13 +35,16 @@ def memory_test_shouldDeselectMismatchedItems_itemTwice(
|
|||||||
) -> str:
|
) -> str:
|
||||||
c = memory_createContext()
|
c = memory_createContext()
|
||||||
c.playfieldSize = 2
|
c.playfieldSize = 2
|
||||||
c = memory_generateConstPlayfield(c)
|
c.recentField = "playfieldSize"
|
||||||
|
c = memory_shouldGenerateConstPlayfield(c)
|
||||||
|
|
||||||
# Select the same item twice.
|
# Select the same item twice.
|
||||||
c.selectedId = 0
|
c.selectedId = 0
|
||||||
c = memory_selectItem(c)
|
c.recentField = "selectedId"
|
||||||
|
c = memory_shouldSelectItem(c)
|
||||||
c.selectedId = 0
|
c.selectedId = 0
|
||||||
c = memory_selectItem(c)
|
c.recentField = "selectedId"
|
||||||
|
c = memory_shouldSelectItem(c)
|
||||||
|
|
||||||
# Detect mismatching.
|
# Detect mismatching.
|
||||||
c = memory_shouldDeselectMismatchedItems(c)
|
c = memory_shouldDeselectMismatchedItems(c)
|
||||||
@@ -146,22 +64,27 @@ def memory_test_shouldDetectVictory(
|
|||||||
) -> str:
|
) -> str:
|
||||||
c = memory_createContext()
|
c = memory_createContext()
|
||||||
c.playfieldSize = 2
|
c.playfieldSize = 2
|
||||||
c = memory_generateConstPlayfield(c)
|
c.recentField = "playfieldSize"
|
||||||
|
c = memory_shouldGenerateConstPlayfield(c)
|
||||||
|
|
||||||
# Select the first two items of the same group.
|
# Select the first two items of the same group.
|
||||||
c.selectedId = 0
|
c.selectedId = 0
|
||||||
c = memory_selectItem(c)
|
c.recentField = "selectedId"
|
||||||
|
c = memory_shouldSelectItem(c)
|
||||||
c.selectedId = 1
|
c.selectedId = 1
|
||||||
c = memory_selectItem(c)
|
c.recentField = "selectedId"
|
||||||
|
c = memory_shouldSelectItem(c)
|
||||||
|
|
||||||
# Hide the first pair.
|
# Hide the first pair.
|
||||||
c = memory_shouldHideMatchingItems(c)
|
c = memory_shouldHideMatchingItems(c)
|
||||||
|
|
||||||
# Select the last two items of the same group.
|
# Select the last two items of the same group.
|
||||||
c.selectedId = 2
|
c.selectedId = 2
|
||||||
c = memory_selectItem(c)
|
c.recentField = "selectedId"
|
||||||
|
c = memory_shouldSelectItem(c)
|
||||||
c.selectedId = 3
|
c.selectedId = 3
|
||||||
c = memory_selectItem(c)
|
c.recentField = "selectedId"
|
||||||
|
c = memory_shouldSelectItem(c)
|
||||||
|
|
||||||
# Hide the second pair.
|
# Hide the second pair.
|
||||||
c = memory_shouldHideMatchingItems(c)
|
c = memory_shouldHideMatchingItems(c)
|
||||||
@@ -179,17 +102,39 @@ def memory_test_shouldDetectVictory(
|
|||||||
return "ERR: memory_shouldDetectVictory"
|
return "ERR: memory_shouldDetectVictory"
|
||||||
#}
|
#}
|
||||||
|
|
||||||
|
def memory_test_shouldGenerateConstPlayfield(
|
||||||
|
) -> str:
|
||||||
|
c = memory_createContext()
|
||||||
|
c.playfieldSize = 2
|
||||||
|
c.recentField = "playfieldSize"
|
||||||
|
c = memory_shouldGenerateConstPlayfield(c)
|
||||||
|
if (
|
||||||
|
c.recentField == "playfieldItems" and
|
||||||
|
len(c.playfieldItems) == 4 and
|
||||||
|
c.playfieldItems[0] == 0 and
|
||||||
|
c.playfieldItems[1] == 0 and
|
||||||
|
c.playfieldItems[2] == 1 and
|
||||||
|
c.playfieldItems[3] == 1
|
||||||
|
):
|
||||||
|
return "OK: memory_shouldGenerateConstPlayfield"
|
||||||
|
#}
|
||||||
|
return "ERR: memory_shouldGenerateConstPlayfield"
|
||||||
|
#}
|
||||||
|
|
||||||
def memory_test_shouldHideMatchingItems(
|
def memory_test_shouldHideMatchingItems(
|
||||||
) -> str:
|
) -> str:
|
||||||
c = memory_createContext()
|
c = memory_createContext()
|
||||||
c.playfieldSize = 2
|
c.playfieldSize = 2
|
||||||
c = memory_generateConstPlayfield(c)
|
c.recentField = "playfieldSize"
|
||||||
|
c = memory_shouldGenerateConstPlayfield(c)
|
||||||
|
|
||||||
# Select two items of the same group.
|
# Select two items of the same group.
|
||||||
c.selectedId = 0
|
c.selectedId = 0
|
||||||
c = memory_selectItem(c)
|
c.recentField = "selectedId"
|
||||||
|
c = memory_shouldSelectItem(c)
|
||||||
c.selectedId = 1
|
c.selectedId = 1
|
||||||
c = memory_selectItem(c)
|
c.recentField = "selectedId"
|
||||||
|
c = memory_shouldSelectItem(c)
|
||||||
|
|
||||||
# Hide matching items.
|
# Hide matching items.
|
||||||
c = memory_shouldHideMatchingItems(c)
|
c = memory_shouldHideMatchingItems(c)
|
||||||
@@ -205,3 +150,82 @@ def memory_test_shouldHideMatchingItems(
|
|||||||
#}
|
#}
|
||||||
return "ERR: memory_shouldHideMatchingItems"
|
return "ERR: memory_shouldHideMatchingItems"
|
||||||
#}
|
#}
|
||||||
|
|
||||||
|
def memory_test_shouldSelectItem_1x(
|
||||||
|
) -> str:
|
||||||
|
c = memory_createContext()
|
||||||
|
c.playfieldSize = 2
|
||||||
|
c.recentField = "playfieldSize"
|
||||||
|
c = memory_shouldGenerateConstPlayfield(c)
|
||||||
|
|
||||||
|
# Select the first item.
|
||||||
|
c.selectedId = 0
|
||||||
|
c.recentField = "selectedId"
|
||||||
|
c = memory_shouldSelectItem(c)
|
||||||
|
|
||||||
|
# See if it's in selectedItems now.
|
||||||
|
if (
|
||||||
|
c.recentField == "selectedItems" and
|
||||||
|
len(c.selectedItems) == 1 and
|
||||||
|
c.selectedItems[0] == 0
|
||||||
|
):
|
||||||
|
return "OK: memory_shouldSelectItem_1x"
|
||||||
|
#}
|
||||||
|
return "ERR: memory_shouldSelectItem_1x"
|
||||||
|
#}
|
||||||
|
|
||||||
|
def memory_test_shouldSelectItem_2x(
|
||||||
|
) -> str:
|
||||||
|
c = memory_createContext()
|
||||||
|
c.playfieldSize = 2
|
||||||
|
c.recentField = "playfieldSize"
|
||||||
|
c = memory_shouldGenerateConstPlayfield(c)
|
||||||
|
|
||||||
|
# Select the first two items.
|
||||||
|
c.selectedId = 0
|
||||||
|
c.recentField = "selectedId"
|
||||||
|
c = memory_shouldSelectItem(c)
|
||||||
|
c.selectedId = 1
|
||||||
|
c.recentField = "selectedId"
|
||||||
|
c = memory_shouldSelectItem(c)
|
||||||
|
|
||||||
|
# See if both items are selected now.
|
||||||
|
if (
|
||||||
|
c.recentField == "selectedItems" and
|
||||||
|
len(c.selectedItems) == 2 and
|
||||||
|
c.selectedItems[0] == 0 and
|
||||||
|
c.selectedItems[1] == 1
|
||||||
|
):
|
||||||
|
return "OK: memory_shouldSelectItem_2x"
|
||||||
|
#}
|
||||||
|
return "ERR: memory_shouldSelectItem_2x"
|
||||||
|
#}
|
||||||
|
|
||||||
|
def memory_test_shouldSelectItem_3x(
|
||||||
|
) -> str:
|
||||||
|
c = memory_createContext()
|
||||||
|
c.playfieldSize = 2
|
||||||
|
c.recentField = "playfieldSize"
|
||||||
|
c = memory_shouldGenerateConstPlayfield(c)
|
||||||
|
|
||||||
|
# Select three items.
|
||||||
|
c.selectedId = 0
|
||||||
|
c.recentField = "selectedId"
|
||||||
|
c = memory_shouldSelectItem(c)
|
||||||
|
c.selectedId = 1
|
||||||
|
c.recentField = "selectedId"
|
||||||
|
c = memory_shouldSelectItem(c)
|
||||||
|
c.selectedId = 2
|
||||||
|
c.recentField = "selectedId"
|
||||||
|
c = memory_shouldSelectItem(c)
|
||||||
|
|
||||||
|
# See if only one (last) item is selected now.
|
||||||
|
if (
|
||||||
|
c.recentField == "selectedItems" and
|
||||||
|
len(c.selectedItems) == 1 and
|
||||||
|
c.selectedItems[0] == 2
|
||||||
|
):
|
||||||
|
return "OK: memory_shouldSelectItem_3x"
|
||||||
|
#}
|
||||||
|
return "ERR: memory_shouldSelectItem_3x"
|
||||||
|
#}
|
||||||
|
|||||||
Reference in New Issue
Block a user