d
This commit is contained in:
@@ -38,6 +38,10 @@ class Controller:
|
|||||||
def registerFunction(self, f):
|
def registerFunction(self, f):
|
||||||
self.functions.append(f)
|
self.functions.append(f)
|
||||||
|
|
||||||
|
def registerFunctions(self, funcs):
|
||||||
|
for f in funcs:
|
||||||
|
self.functions.append(f)
|
||||||
|
|
||||||
def reportContext(self):
|
def reportContext(self):
|
||||||
for cb in self.callbacks:
|
for cb in self.callbacks:
|
||||||
cb(self.context)
|
cb(self.context)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "llm.h"
|
||||||
#include "memory_Context.h"
|
#include "memory_Context.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
@@ -135,11 +136,11 @@ memory_Context cli_selectItem(
|
|||||||
) {
|
) {
|
||||||
if (
|
if (
|
||||||
c.recentField == "input" &&
|
c.recentField == "input" &&
|
||||||
c.input.isdigit()
|
llm_isDigit(c.input)
|
||||||
) {
|
) {
|
||||||
// CLI ids start with 1 while memory module has ids starting with 0
|
// CLI ids start with 1 while memory module has ids starting with 0
|
||||||
// Convert CLI id to memory id
|
// Convert CLI id to memory id
|
||||||
c.selectedId = int(c.input) - 1;
|
c.selectedId = llm_strToInt(c.input) - 1;
|
||||||
c.recentField = "selectedId";
|
c.recentField = "selectedId";
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,11 +139,11 @@ def cli_selectItem(
|
|||||||
) -> memory_Context:
|
) -> memory_Context:
|
||||||
if (
|
if (
|
||||||
c.recentField == "input" and
|
c.recentField == "input" and
|
||||||
c.input.isdigit()
|
llm_isDigit(c.input)
|
||||||
):
|
):
|
||||||
# CLI ids start with 1 while memory module has ids starting with 0
|
# CLI ids start with 1 while memory module has ids starting with 0
|
||||||
# Convert CLI id to memory id
|
# Convert CLI id to memory id
|
||||||
c.selectedId = int(c.input) - 1
|
c.selectedId = llm_strToInt(c.input) - 1
|
||||||
c.recentField = "selectedId"
|
c.recentField = "selectedId"
|
||||||
return c
|
return c
|
||||||
#}
|
#}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "llm.h"
|
||||||
#include "memory_Context.h"
|
#include "memory_Context.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#// file unused
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "memory_Context.h"
|
#include "memory_Context.h"
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ TMP=/tmp/cxx-headers.tmp
|
|||||||
|
|
||||||
grep '^memory_Context ' memory.cpp > $TMP
|
grep '^memory_Context ' memory.cpp > $TMP
|
||||||
grep '^std::string ' memory_test.cpp >> $TMP
|
grep '^std::string ' memory_test.cpp >> $TMP
|
||||||
#grep '^memory_Context ' cli.cpp >> $TMP
|
grep '^memory_Context ' cli.cpp >> $TMP
|
||||||
|
grep '^std::string ' cli_test.cpp >> $TMP
|
||||||
|
grep '^std::string ' llm_test.cpp >> $TMP
|
||||||
|
|
||||||
IN=$TMP
|
IN=$TMP
|
||||||
OUT=$DIR/main.h
|
OUT=$DIR/main.h
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ c++ -o test_memory_C++ -std=c++11 -I. \
|
|||||||
memory.cpp \
|
memory.cpp \
|
||||||
memory_Context.cpp \
|
memory_Context.cpp \
|
||||||
memory_test.cpp \
|
memory_test.cpp \
|
||||||
|
llm.cpp \
|
||||||
|
llm_test.cpp \
|
||||||
|
cli.cpp \
|
||||||
|
cli_test.cpp \
|
||||||
main.cpp
|
main.cpp
|
||||||
|
|
||||||
# cli.cpp \
|
|
||||||
# cli_test.cpp \
|
|
||||||
|
|||||||
11
v4/llm.cpp
Normal file
11
v4/llm.cpp
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#include "llm.h"
|
||||||
|
|
||||||
|
bool llm_isDigit(const std::string &str) {
|
||||||
|
return
|
||||||
|
!str.empty() &&
|
||||||
|
str.find_first_not_of("0123456789") == std::string::npos;
|
||||||
|
}
|
||||||
|
|
||||||
|
int llm_strToInt(const std::string &str) {
|
||||||
|
return std::stoi(str);
|
||||||
|
}
|
||||||
9
v4/llm.h
Normal file
9
v4/llm.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#ifndef llm_HEADER
|
||||||
|
#define llm_HEADER
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
bool llm_isDigit(const std::string &str);
|
||||||
|
int llm_strToInt(const std::string &str);
|
||||||
|
|
||||||
|
#endif // llm_HEADER
|
||||||
10
v4/llm.py
10
v4/llm.py
@@ -1,6 +1,6 @@
|
|||||||
import copy
|
import copy
|
||||||
|
|
||||||
# Make deep copies of arguments to mimic behaviour of strongly typed languages.
|
# Make deep copies of arguments to treat the arguments as structs.
|
||||||
# https://stackoverflow.com/a/15398021
|
# https://stackoverflow.com/a/15398021
|
||||||
def llm_by_value(f):
|
def llm_by_value(f):
|
||||||
def _f(*args, **kwargs):
|
def _f(*args, **kwargs):
|
||||||
@@ -8,3 +8,11 @@ def llm_by_value(f):
|
|||||||
kwargsCopy = copy.deepcopy(kwargs)
|
kwargsCopy = copy.deepcopy(kwargs)
|
||||||
return f(*argsCopy, **kwargsCopy)
|
return f(*argsCopy, **kwargsCopy)
|
||||||
return _f
|
return _f
|
||||||
|
|
||||||
|
# Tell if string is a digit
|
||||||
|
def llm_isDigit(s):
|
||||||
|
return s.isdigit()
|
||||||
|
|
||||||
|
# Convert string to integer
|
||||||
|
def llm_strToInt(s):
|
||||||
|
return int(s)
|
||||||
|
|||||||
37
v4/llm_test.cpp
Normal file
37
v4/llm_test.cpp
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include "llm.h"
|
||||||
|
#include "memory_Context.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
std::string llm_test_isDigit_digit(
|
||||||
|
) {
|
||||||
|
if (
|
||||||
|
llm_isDigit("123")
|
||||||
|
) {
|
||||||
|
return "OK: llm_isDigit_digit";
|
||||||
|
}
|
||||||
|
return "ERR: llm_isDigit_digit";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string llm_test_isDigit_notDigit(
|
||||||
|
) {
|
||||||
|
if (
|
||||||
|
llm_isDigit("abc")
|
||||||
|
) {
|
||||||
|
return "ERR: llm_isDigit_notDigit";
|
||||||
|
}
|
||||||
|
return "OK: llm_isDigit_notDigit";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string llm_test_strToInt(
|
||||||
|
) {
|
||||||
|
if (
|
||||||
|
llm_strToInt("123") == 123
|
||||||
|
) {
|
||||||
|
return "OK: llm_strToInt";
|
||||||
|
}
|
||||||
|
return "ERR: llm_strToInt";
|
||||||
|
}
|
||||||
|
|
||||||
31
v4/llm_test.py
Normal file
31
v4/llm_test.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
from llm import *
|
||||||
|
|
||||||
|
def llm_test_isDigit_digit(
|
||||||
|
) -> str:
|
||||||
|
if (
|
||||||
|
llm_isDigit("123")
|
||||||
|
):
|
||||||
|
return "OK: llm_isDigit_digit"
|
||||||
|
#}
|
||||||
|
return "ERR: llm_isDigit_digit"
|
||||||
|
#}
|
||||||
|
|
||||||
|
def llm_test_isDigit_notDigit(
|
||||||
|
) -> str:
|
||||||
|
if (
|
||||||
|
llm_isDigit("abc")
|
||||||
|
):
|
||||||
|
return "ERR: llm_isDigit_notDigit"
|
||||||
|
#}
|
||||||
|
return "OK: llm_isDigit_notDigit"
|
||||||
|
#}
|
||||||
|
|
||||||
|
def llm_test_strToInt(
|
||||||
|
) -> str:
|
||||||
|
if (
|
||||||
|
llm_strToInt("123") == 123
|
||||||
|
):
|
||||||
|
return "OK: llm_strToInt"
|
||||||
|
#}
|
||||||
|
return "ERR: llm_strToInt"
|
||||||
|
#}
|
||||||
21
v4/llm_test_Python.py
Normal file
21
v4/llm_test_Python.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
from llm import *
|
||||||
|
from memory_Context import *
|
||||||
|
|
||||||
|
def llm_test_Python_copyByValue(
|
||||||
|
) -> str:
|
||||||
|
c = memory_createContext()
|
||||||
|
c.input = "abc"
|
||||||
|
|
||||||
|
@llm_by_value
|
||||||
|
def alterValue(c):
|
||||||
|
c.input = "alteredValue"
|
||||||
|
|
||||||
|
alterValue(c)
|
||||||
|
|
||||||
|
if (
|
||||||
|
c.input == "abc"
|
||||||
|
):
|
||||||
|
return "OK: llm_Python_copyByValue"
|
||||||
|
#}
|
||||||
|
return "ERR: llm_Python_copyByValue"
|
||||||
|
#}
|
||||||
34
v4/main.cpp
34
v4/main.cpp
@@ -5,6 +5,15 @@
|
|||||||
#include "memory_Context.h"
|
#include "memory_Context.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
std::cout
|
||||||
|
<< llm_test_isDigit_digit()
|
||||||
|
<< std::endl
|
||||||
|
<< llm_test_isDigit_notDigit()
|
||||||
|
<< std::endl
|
||||||
|
<< llm_test_strToInt()
|
||||||
|
<< std::endl
|
||||||
|
;
|
||||||
|
|
||||||
std::cout
|
std::cout
|
||||||
<< memory_test_detectMismatchedItems()
|
<< memory_test_detectMismatchedItems()
|
||||||
<< std::endl
|
<< std::endl
|
||||||
@@ -24,16 +33,39 @@ int main() {
|
|||||||
<< std::endl
|
<< std::endl
|
||||||
;
|
;
|
||||||
|
|
||||||
/*
|
|
||||||
std::cout
|
std::cout
|
||||||
|
<< cli_test_exit_e()
|
||||||
|
<< std::endl
|
||||||
|
<< cli_test_exit_exit()
|
||||||
|
<< std::endl
|
||||||
|
<< cli_test_exit_victory()
|
||||||
|
<< std::endl
|
||||||
|
<< cli_test_exit_q()
|
||||||
|
<< std::endl
|
||||||
|
<< cli_test_exit_quit()
|
||||||
|
<< std::endl
|
||||||
|
<< cli_test_goOn()
|
||||||
|
<< std::endl
|
||||||
<< cli_test_greetUser()
|
<< cli_test_greetUser()
|
||||||
<< std::endl
|
<< std::endl
|
||||||
<< cli_test_showHelp_h()
|
<< cli_test_showHelp_h()
|
||||||
<< std::endl
|
<< std::endl
|
||||||
<< cli_test_showHelp_help()
|
<< cli_test_showHelp_help()
|
||||||
<< std::endl
|
<< std::endl
|
||||||
|
<< cli_test_selectItem()
|
||||||
|
<< std::endl
|
||||||
|
<< cli_test_promptSecondItemSelection()
|
||||||
|
<< std::endl
|
||||||
|
<< cli_test_reportMatchedItems()
|
||||||
|
<< std::endl
|
||||||
|
<< cli_test_reportMismatchedItems()
|
||||||
|
<< std::endl
|
||||||
|
<< cli_test_reportVictory()
|
||||||
|
<< std::endl
|
||||||
;
|
;
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
auto c = shell_createContext();
|
auto c = shell_createContext();
|
||||||
c.cCLI = cli_createContext();
|
c.cCLI = cli_createContext();
|
||||||
c = shell_launch(c);
|
c = shell_launch(c);
|
||||||
|
|||||||
26
v4/main.h
26
v4/main.h
@@ -17,6 +17,32 @@ std::string memory_test_hideMatchingItems();
|
|||||||
std::string memory_test_selectItem_1x();
|
std::string memory_test_selectItem_1x();
|
||||||
std::string memory_test_selectItem_2x();
|
std::string memory_test_selectItem_2x();
|
||||||
std::string memory_test_selectItem_3x();
|
std::string memory_test_selectItem_3x();
|
||||||
|
memory_Context cli_exit(memory_Context);
|
||||||
|
memory_Context cli_goOn(memory_Context);
|
||||||
|
memory_Context cli_greetUser(memory_Context);
|
||||||
|
memory_Context cli_promptSecondItemSelection(memory_Context);
|
||||||
|
memory_Context cli_reportMatchedItems(memory_Context);
|
||||||
|
memory_Context cli_reportVictory(memory_Context);
|
||||||
|
memory_Context cli_selectItem(memory_Context);
|
||||||
|
memory_Context cli_showHelp(memory_Context);
|
||||||
|
memory_Context cli_reportMismatchedItems(memory_Context);
|
||||||
|
std::string cli_test_exit_e();
|
||||||
|
std::string cli_test_exit_exit();
|
||||||
|
std::string cli_test_exit_victory();
|
||||||
|
std::string cli_test_exit_q();
|
||||||
|
std::string cli_test_exit_quit();
|
||||||
|
std::string cli_test_goOn();
|
||||||
|
std::string cli_test_greetUser();
|
||||||
|
std::string cli_test_promptSecondItemSelection();
|
||||||
|
std::string cli_test_reportMatchedItems();
|
||||||
|
std::string cli_test_reportMismatchedItems();
|
||||||
|
std::string cli_test_selectItem();
|
||||||
|
std::string cli_test_showHelp_h();
|
||||||
|
std::string cli_test_showHelp_help();
|
||||||
|
std::string cli_test_reportVictory();
|
||||||
|
std::string llm_test_isDigit_digit();
|
||||||
|
std::string llm_test_isDigit_notDigit();
|
||||||
|
std::string llm_test_strToInt();
|
||||||
|
|
||||||
#endif // main_HEADER
|
#endif // main_HEADER
|
||||||
|
|
||||||
|
|||||||
39
v4/main.py
39
v4/main.py
@@ -1,9 +1,16 @@
|
|||||||
from cli import *
|
from cli import *
|
||||||
from cli_test import *
|
from cli_test import *
|
||||||
|
from llm_test import *
|
||||||
|
from llm_test_Python import *
|
||||||
from memory_test import *
|
from memory_test import *
|
||||||
from Controller import *
|
from Controller import *
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
print(llm_test_Python_copyByValue())
|
||||||
|
print(llm_test_isDigit_digit())
|
||||||
|
print(llm_test_isDigit_notDigit())
|
||||||
|
print(llm_test_strToInt())
|
||||||
|
|
||||||
print(memory_test_detectMismatchedItems())
|
print(memory_test_detectMismatchedItems())
|
||||||
print(memory_test_detectMismatchedItems_itemTwice())
|
print(memory_test_detectMismatchedItems_itemTwice())
|
||||||
print(memory_test_detectVictory())
|
print(memory_test_detectVictory())
|
||||||
@@ -28,28 +35,28 @@ print(cli_test_reportMatchedItems())
|
|||||||
print(cli_test_reportMismatchedItems())
|
print(cli_test_reportMismatchedItems())
|
||||||
print(cli_test_reportVictory())
|
print(cli_test_reportVictory())
|
||||||
|
|
||||||
|
|
||||||
ctrl = Controller(memory_createContext())
|
ctrl = Controller(memory_createContext())
|
||||||
ctrl.registerFunction(cli_exit)
|
ctrl.registerFunctions([
|
||||||
ctrl.registerFunction(cli_goOn)
|
cli_exit,
|
||||||
ctrl.registerFunction(cli_greetUser)
|
cli_goOn,
|
||||||
ctrl.registerFunction(cli_promptSecondItemSelection)
|
cli_greetUser,
|
||||||
ctrl.registerFunction(cli_reportMatchedItems)
|
cli_promptSecondItemSelection,
|
||||||
ctrl.registerFunction(cli_reportMismatchedItems)
|
cli_reportMatchedItems,
|
||||||
ctrl.registerFunction(cli_reportVictory)
|
cli_reportMismatchedItems,
|
||||||
ctrl.registerFunction(cli_selectItem)
|
cli_reportVictory,
|
||||||
ctrl.registerFunction(cli_showHelp)
|
cli_selectItem,
|
||||||
ctrl.registerFunction(memory_detectMismatchedItems)
|
cli_showHelp,
|
||||||
ctrl.registerFunction(memory_detectVictory)
|
memory_detectMismatchedItems,
|
||||||
ctrl.registerFunction(memory_generateConstPlayfield)
|
memory_detectVictory,
|
||||||
ctrl.registerFunction(memory_hideMatchingItems)
|
memory_generateConstPlayfield,
|
||||||
ctrl.registerFunction(memory_selectItem)
|
memory_hideMatchingItems,
|
||||||
|
memory_selectItem,
|
||||||
|
])
|
||||||
|
|
||||||
def printOutput(c):
|
def printOutput(c):
|
||||||
if c.recentField.startswith("output"):
|
if c.recentField.startswith("output"):
|
||||||
print(c.field(c.recentField))
|
print(c.field(c.recentField))
|
||||||
ctrl.registerCallback(printOutput)
|
ctrl.registerCallback(printOutput)
|
||||||
#ctrl.registerCallback(lambda c: print(f"ИГР App.dbg ctx: '{c}'"))
|
|
||||||
ctrl.registerFieldCallback("exit", lambda c: sys.exit(0))
|
ctrl.registerFieldCallback("exit", lambda c: sys.exit(0))
|
||||||
|
|
||||||
ctrl.set("didLaunch", True)
|
ctrl.set("didLaunch", True)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "llm.h"
|
||||||
#include "memory_Context.h"
|
#include "memory_Context.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,18 @@
|
|||||||
#define memory_Context_HEADER
|
#define memory_Context_HEADER
|
||||||
|
|
||||||
struct memory_Context {
|
struct memory_Context {
|
||||||
|
bool didLaunch = false;
|
||||||
|
bool exit = false;
|
||||||
|
std::string input = "";
|
||||||
std::vector<int> hiddenItems;
|
std::vector<int> hiddenItems;
|
||||||
std::vector<int> mismatchedItems;
|
std::vector<int> mismatchedItems;
|
||||||
|
std::string outputGoOn = "";
|
||||||
|
std::string outputGreeting = "";
|
||||||
|
std::string outputHelp = "";
|
||||||
|
std::string outputMatchedItems = "";
|
||||||
|
std::string outputMismatchedItems = "";
|
||||||
|
std::string outputPromptSelection = "";
|
||||||
|
std::string outputVictory = "";
|
||||||
std::map<int, int> playfieldItems;
|
std::map<int, int> playfieldItems;
|
||||||
int playfieldSize = 0;
|
int playfieldSize = 0;
|
||||||
std::string recentField = "none";
|
std::string recentField = "none";
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
class memory_Context:
|
class memory_Context:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.didLaunch = False
|
self.didLaunch = False
|
||||||
|
self.exit = False
|
||||||
self.hiddenItems = []
|
self.hiddenItems = []
|
||||||
self.input = ""
|
self.input = ""
|
||||||
self.mismatchedItems = []
|
self.mismatchedItems = []
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "llm.h"
|
||||||
#include "memory_Context.h"
|
#include "memory_Context.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
#include <string>
|
|
||||||
|
|
||||||
#ifndef memory_test_HEADER
|
|
||||||
#define memory_test_HEADER
|
|
||||||
|
|
||||||
std::string memory_test_generateConstPlayfield();
|
|
||||||
std::string memory_test_selectItem_1x();
|
|
||||||
std::string memory_test_selectItem_2x();
|
|
||||||
std::string memory_test_selectItem_3x();
|
|
||||||
std::string memory_test_shouldDeselectMismatchedItems();
|
|
||||||
std::string memory_test_shouldDeselectMismatchedItems_itemTwice();
|
|
||||||
std::string memory_test_shouldDetectVictory();
|
|
||||||
std::string memory_test_shouldHideMatchingItems();
|
|
||||||
|
|
||||||
#endif // memory_test_HEADER
|
|
||||||
@@ -4,6 +4,7 @@ def includes():
|
|||||||
return """#include <map>
|
return """#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "llm.h"
|
||||||
#include "memory_Context.h"
|
#include "memory_Context.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -7,3 +7,5 @@ $TR $DIR/memory.py > $DIR/memory.cpp
|
|||||||
$TR $DIR/memory_test.py > $DIR/memory_test.cpp
|
$TR $DIR/memory_test.py > $DIR/memory_test.cpp
|
||||||
$TR $DIR/cli.py > $DIR/cli.cpp
|
$TR $DIR/cli.py > $DIR/cli.cpp
|
||||||
$TR $DIR/cli_test.py > $DIR/cli_test.cpp
|
$TR $DIR/cli_test.py > $DIR/cli_test.cpp
|
||||||
|
$TR $DIR/llm_test.py > $DIR/llm_test.cpp
|
||||||
|
$DIR/cxx-headers
|
||||||
|
|||||||
Reference in New Issue
Block a user