From fc82f332ede103b226101d8401857eb9444f8b0d 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: Wed, 24 Apr 2024 22:44:36 +0300 Subject: [PATCH] d --- v3/gen-C++ | 2 +- v3/main.cpp | 4 ++++ v3/memory.cpp | 39 ++++++++++++++++++++------------------- v3/memory.py | 20 ++++++++++---------- v3/memory_Context.cpp | 10 ++++------ v3/memory_Context.h | 19 +++++++++++++++++++ v3/memory_Context.py | 4 ++-- v3/memory_test.cpp | 3 ++- v3/tPythonC++/CPP.py | 12 +++++++++--- 9 files changed, 71 insertions(+), 42 deletions(-) create mode 100644 v3/memory_Context.h diff --git a/v3/gen-C++ b/v3/gen-C++ index cbf52cd..a1d9b2d 100755 --- a/v3/gen-C++ +++ b/v3/gen-C++ @@ -1 +1 @@ -c++ -o test_memory_C++ -std=c++11 main.cpp +c++ -o test_memory_C++ -std=c++11 -I. memory.cpp memory_Context.cpp main.cpp diff --git a/v3/main.cpp b/v3/main.cpp index 0f98d1b..a8fedd7 100644 --- a/v3/main.cpp +++ b/v3/main.cpp @@ -1,8 +1,12 @@ +#include "memory_Context.h" #include #include #include +extern memory_Context memory_createContext(); + int main() { + memory_createContext(); std::cout << "check" //memory_test_generateConstPlayfield() << std::endl diff --git a/v3/memory.cpp b/v3/memory.cpp index cff44ad..e1e8c80 100644 --- a/v3/memory.cpp +++ b/v3/memory.cpp @@ -1,6 +1,7 @@ #include #include -#include "entities.h" +#include +#include "memory_Context.h" //////////////// // Client initiated input @@ -8,7 +9,7 @@ // Generate constant playfield memory_Context memory_generateConstPlayfield( - memory_Context& c + memory_Context c ) { std::map idGroups = { }; auto id = 0; @@ -24,14 +25,14 @@ memory_Context memory_generateConstPlayfield( } // Select item - memory_Context memory_selectItem( - memory_Context& c + memory_Context c ) { if ( c.selectedItems.size() == 2 ) { c.selectedItems = []; + } c.selectedItems.append(c.selectedId); c.recentField = "selectedItems"; return c; @@ -47,18 +48,16 @@ memory_Context memory_selectItem( // 0. Two items has just been selected // 1. The same item has been selected twice // 1. Selected items are of different groups - - - memory_Context memory_shouldDeselectMismatchedItems( - memory_Context& c + memory_Context c ) { - if not (; - c.recentField == "selectedItems" &&; - c.selectedItems.size() == 2; + if !( + c.recentField == "selectedItems" && + c.selectedItems.size() == 2 ) { - c.recentField = None; + c.recentField = "none"; return c; + } if ( c.selectedItems[0] == c.selectedItems[1] ) { @@ -66,6 +65,7 @@ memory_Context memory_shouldDeselectMismatchedItems( c.mismatchedItems.append(c.selectedItems[0]); c.recentField = "mismatchedItems"; return c; + } if ( c.playfieldItems[c.selectedItems[0]] != c.playfieldItems[c.selectedItems[1]] ) { @@ -74,7 +74,8 @@ memory_Context memory_shouldDeselectMismatchedItems( c.mismatchedItems.append(c.selectedItems[1]); c.recentField = "mismatchedItems"; return c; - c.recentField = None; + } + c.recentField = "none"; return c; } @@ -82,9 +83,8 @@ memory_Context memory_shouldDeselectMismatchedItems( // // Conditions: // 1. Matching items have just been hidden and all items are hidden now - memory_Context memory_shouldDetectVictory( - memory_Context& c + memory_Context c ) { if ( c.recentField == "hiddenItems" && @@ -93,7 +93,8 @@ memory_Context memory_shouldDetectVictory( c.victory = True; c.recentField = "victory"; return c; - c.recentField = None; + } + c.recentField = "none"; return c; } @@ -101,9 +102,8 @@ memory_Context memory_shouldDetectVictory( // // Conditions: // 1. Two items are selected and they are of the same group - memory_Context memory_shouldHideMatchingItems( - memory_Context& c + memory_Context c ) { if ( c.recentField == "selectedItems" && @@ -114,7 +114,8 @@ memory_Context memory_shouldHideMatchingItems( c.hiddenItems.append(c.selectedItems[1]); c.recentField = "hiddenItems"; return c; - c.recentField = None; + } + c.recentField = "none"; return c; } diff --git a/v3/memory.py b/v3/memory.py index 1286dc2..1185139 100644 --- a/v3/memory.py +++ b/v3/memory.py @@ -32,7 +32,7 @@ def memory_selectItem( len(c.selectedItems) == 2 ): c.selectedItems = [] - + #} c.selectedItems.append(c.selectedId) c.recentField = "selectedItems" return c @@ -56,9 +56,9 @@ def memory_shouldDeselectMismatchedItems( c.recentField == "selectedItems" and len(c.selectedItems) == 2 ): - c.recentField = None + c.recentField = "none" return c - + #} if ( c.selectedItems[0] == c.selectedItems[1] ): @@ -66,7 +66,7 @@ def memory_shouldDeselectMismatchedItems( c.mismatchedItems.append(c.selectedItems[0]) c.recentField = "mismatchedItems" return c - + #} if ( c.playfieldItems[c.selectedItems[0]] != c.playfieldItems[c.selectedItems[1]] ): @@ -75,8 +75,8 @@ def memory_shouldDeselectMismatchedItems( c.mismatchedItems.append(c.selectedItems[1]) c.recentField = "mismatchedItems" return c - - c.recentField = None + #} + c.recentField = "none" return c #} @@ -95,8 +95,8 @@ def memory_shouldDetectVictory( c.victory = True c.recentField = "victory" return c - - c.recentField = None + #} + c.recentField = "none" return c #} @@ -117,7 +117,7 @@ def memory_shouldHideMatchingItems( c.hiddenItems.append(c.selectedItems[1]) c.recentField = "hiddenItems" return c - - c.recentField = None + #} + c.recentField = "none" return c #} diff --git a/v3/memory_Context.cpp b/v3/memory_Context.cpp index 623a573..d21fb82 100644 --- a/v3/memory_Context.cpp +++ b/v3/memory_Context.cpp @@ -1,7 +1,5 @@ -#include -#include -#include "entities.h" - - - +#include "memory_Context.h" +memory_Context memory_createContext() { + return memory_Context(); +} diff --git a/v3/memory_Context.h b/v3/memory_Context.h new file mode 100644 index 0000000..e74cde1 --- /dev/null +++ b/v3/memory_Context.h @@ -0,0 +1,19 @@ +#include +#include +#include + +#ifndef memory_Context_HEADER +#define memory_Context_HEADER + +struct memory_Context { + std::vector hiddenItems; + std::vector mismatchedItems; + std::map playfieldItems; + int playfieldSize = 0; + std::string recentField = "none"; + int selectedId = -1; + std::vector selectedItems; + bool victory = false; +}; + +#endif // memory_Context_HEADER diff --git a/v3/memory_Context.py b/v3/memory_Context.py index 2f3b01f..39af108 100644 --- a/v3/memory_Context.py +++ b/v3/memory_Context.py @@ -4,8 +4,8 @@ class memory_Context: self.mismatchedItems = [] self.playfieldItems = {} self.playfieldSize = 0 - self.recentField = None - self.selectedId = None + self.recentField = "none" + self.selectedId = -1 self.selectedItems = [] self.victory = False diff --git a/v3/memory_test.cpp b/v3/memory_test.cpp index c307f30..c6e17bb 100644 --- a/v3/memory_test.cpp +++ b/v3/memory_test.cpp @@ -1,6 +1,7 @@ #include #include -#include "entities.h" +#include +#include "memory_Context.h" std::string memory_test_generateConstPlayfield( ) { diff --git a/v3/tPythonC++/CPP.py b/v3/tPythonC++/CPP.py index 4d4ab65..7cb2051 100644 --- a/v3/tPythonC++/CPP.py +++ b/v3/tPythonC++/CPP.py @@ -3,7 +3,8 @@ from Function import * def includes(): return """#include #include -#include "entities.h" +#include +#include "memory_Context.h" """ def replaceAnd(s): @@ -91,6 +92,11 @@ def translateStatement(s, state): state.isIf = True return s + # Keep "if not (" + if ss == "if not (": + state.isIf = True + return f"{indentation}if !(" + # ): -> } if ss == "):": state.isIf = False @@ -129,8 +135,8 @@ class CPP: for i in range(0, len(self.fn.parameters)): p = translateParameter(self.fn.parameters[i]) # Make Context passed by reference. - if "Context" in p: - p = p.replace("Context", "Context&") + #if "Context" in p: + # p = p.replace("Context", "Context&") params.append(p) strparams = "\n".join(params) if (len(strparams) > 0):