diff --git a/v3/memory.cpp b/v3/memory.cpp index e1e8c80..1870f46 100644 --- a/v3/memory.cpp +++ b/v3/memory.cpp @@ -31,9 +31,9 @@ memory_Context memory_selectItem( if ( c.selectedItems.size() == 2 ) { - c.selectedItems = []; + c.selectedItems.clear(); } - c.selectedItems.append(c.selectedId); + c.selectedItems.push_back(c.selectedId); c.recentField = "selectedItems"; return c; } @@ -62,7 +62,7 @@ memory_Context memory_shouldDeselectMismatchedItems( c.selectedItems[0] == c.selectedItems[1] ) { c.mismatchedItems.clear(); - c.mismatchedItems.append(c.selectedItems[0]); + c.mismatchedItems.push_back(c.selectedItems[0]); c.recentField = "mismatchedItems"; return c; } @@ -70,8 +70,8 @@ memory_Context memory_shouldDeselectMismatchedItems( c.playfieldItems[c.selectedItems[0]] != c.playfieldItems[c.selectedItems[1]] ) { c.mismatchedItems.clear(); - c.mismatchedItems.append(c.selectedItems[0]); - c.mismatchedItems.append(c.selectedItems[1]); + c.mismatchedItems.push_back(c.selectedItems[0]); + c.mismatchedItems.push_back(c.selectedItems[1]); c.recentField = "mismatchedItems"; return c; } @@ -88,9 +88,9 @@ memory_Context memory_shouldDetectVictory( ) { if ( c.recentField == "hiddenItems" && - c.hiddenItems.size() == len(c.playfieldItems) + c.hiddenItems.size() == c.playfieldItems.size() ) { - c.victory = True; + c.victory = true; c.recentField = "victory"; return c; } @@ -110,8 +110,8 @@ memory_Context memory_shouldHideMatchingItems( c.selectedItems.size() == 2 && c.playfieldItems[c.selectedItems[0]] == c.playfieldItems[c.selectedItems[1]] ) { - c.hiddenItems.append(c.selectedItems[0]); - c.hiddenItems.append(c.selectedItems[1]); + c.hiddenItems.push_back(c.selectedItems[0]); + c.hiddenItems.push_back(c.selectedItems[1]); c.recentField = "hiddenItems"; return c; } diff --git a/v3/memory.py b/v3/memory.py index 1185139..c4449d1 100644 --- a/v3/memory.py +++ b/v3/memory.py @@ -31,7 +31,7 @@ def memory_selectItem( if ( len(c.selectedItems) == 2 ): - c.selectedItems = [] + c.selectedItems.clear() #} c.selectedItems.append(c.selectedId) c.recentField = "selectedItems" diff --git a/v3/memory_test.cpp b/v3/memory_test.cpp index c6e17bb..daf32b2 100644 --- a/v3/memory_test.cpp +++ b/v3/memory_test.cpp @@ -174,7 +174,7 @@ std::string memory_test_shouldDetectVictory( # See if victory has been detected.; if ( c.recentField == "victory" && - c.victory == True + c.victory == true ) { return "OK: memory_shouldDetectVictory"; } diff --git a/v3/tPythonC++/CPP.py b/v3/tPythonC++/CPP.py index 7cb2051..cf2e746 100644 --- a/v3/tPythonC++/CPP.py +++ b/v3/tPythonC++/CPP.py @@ -10,12 +10,15 @@ def includes(): def replaceAnd(s): return s.replace("and", "&&") +def replaceAppend(s): + return s.replace(".append(", ".push_back(") + def replaceComment(s): return s.replace("#", "//") def replaceLen(s): posLen = s.find("len(") - posEnd = s.find(")") + posEnd = s.find(")", posLen) if ( posLen == -1 or posEnd == -1 @@ -26,6 +29,9 @@ def replaceLen(s): after = s[posEnd + len(")"):] return f"{before}{name}.size(){after}" +def replaceTrue(s): + return s.replace("True", "true") + def translateParameter(s): # name: type -> type name parts = s.split(": ") @@ -147,7 +153,11 @@ class CPP: for i in range(0, len(self.fn.statements)): s = translateStatement(self.fn.statements[i], self) s = replaceAnd(s) + s = replaceAppend(s) + # Replace len twice to account for double invocation. + s = replaceLen(s) s = replaceLen(s) + s = replaceTrue(s) sts.append(s) strstatements = "\n".join(sts)