Михаил Капелько 8 months ago
parent
commit
5fe21fe872
4 changed files with 22 additions and 12 deletions
  1. +9
    -9
      v3/memory.cpp
  2. +1
    -1
      v3/memory.py
  3. +1
    -1
      v3/memory_test.cpp
  4. +11
    -1
      v3/tPythonC++/CPP.py

+ 9
- 9
v3/memory.cpp View File

@@ -31,9 +31,9 @@ memory_Context memory_selectItem(
if ( if (
c.selectedItems.size() == 2 c.selectedItems.size() == 2
) { ) {
c.selectedItems = [];
c.selectedItems.clear();
} }
c.selectedItems.append(c.selectedId);
c.selectedItems.push_back(c.selectedId);
c.recentField = "selectedItems"; c.recentField = "selectedItems";
return c; return c;
} }
@@ -62,7 +62,7 @@ memory_Context memory_shouldDeselectMismatchedItems(
c.selectedItems[0] == c.selectedItems[1] c.selectedItems[0] == c.selectedItems[1]
) { ) {
c.mismatchedItems.clear(); c.mismatchedItems.clear();
c.mismatchedItems.append(c.selectedItems[0]);
c.mismatchedItems.push_back(c.selectedItems[0]);
c.recentField = "mismatchedItems"; c.recentField = "mismatchedItems";
return c; return c;
} }
@@ -70,8 +70,8 @@ memory_Context memory_shouldDeselectMismatchedItems(
c.playfieldItems[c.selectedItems[0]] != c.playfieldItems[c.selectedItems[1]] c.playfieldItems[c.selectedItems[0]] != c.playfieldItems[c.selectedItems[1]]
) { ) {
c.mismatchedItems.clear(); 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"; c.recentField = "mismatchedItems";
return c; return c;
} }
@@ -88,9 +88,9 @@ memory_Context memory_shouldDetectVictory(
) { ) {
if ( if (
c.recentField == "hiddenItems" && c.recentField == "hiddenItems" &&
c.hiddenItems.size() == len(c.playfieldItems)
c.hiddenItems.size() == c.playfieldItems.size()
) { ) {
c.victory = True;
c.victory = true;
c.recentField = "victory"; c.recentField = "victory";
return c; return c;
} }
@@ -110,8 +110,8 @@ memory_Context memory_shouldHideMatchingItems(
c.selectedItems.size() == 2 && c.selectedItems.size() == 2 &&
c.playfieldItems[c.selectedItems[0]] == c.playfieldItems[c.selectedItems[1]] 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"; c.recentField = "hiddenItems";
return c; return c;
} }


+ 1
- 1
v3/memory.py View File

@@ -31,7 +31,7 @@ def memory_selectItem(
if ( if (
len(c.selectedItems) == 2 len(c.selectedItems) == 2
): ):
c.selectedItems = []
c.selectedItems.clear()
#} #}
c.selectedItems.append(c.selectedId) c.selectedItems.append(c.selectedId)
c.recentField = "selectedItems" c.recentField = "selectedItems"


+ 1
- 1
v3/memory_test.cpp View File

@@ -174,7 +174,7 @@ std::string memory_test_shouldDetectVictory(
# See if victory has been detected.; # See if victory has been detected.;
if ( if (
c.recentField == "victory" && c.recentField == "victory" &&
c.victory == True
c.victory == true
) { ) {
return "OK: memory_shouldDetectVictory"; return "OK: memory_shouldDetectVictory";
} }


+ 11
- 1
v3/tPythonC++/CPP.py View File

@@ -10,12 +10,15 @@ def includes():
def replaceAnd(s): def replaceAnd(s):
return s.replace("and", "&&") return s.replace("and", "&&")


def replaceAppend(s):
return s.replace(".append(", ".push_back(")

def replaceComment(s): def replaceComment(s):
return s.replace("#", "//") return s.replace("#", "//")


def replaceLen(s): def replaceLen(s):
posLen = s.find("len(") posLen = s.find("len(")
posEnd = s.find(")")
posEnd = s.find(")", posLen)
if ( if (
posLen == -1 or posLen == -1 or
posEnd == -1 posEnd == -1
@@ -26,6 +29,9 @@ def replaceLen(s):
after = s[posEnd + len(")"):] after = s[posEnd + len(")"):]
return f"{before}{name}.size(){after}" return f"{before}{name}.size(){after}"


def replaceTrue(s):
return s.replace("True", "true")

def translateParameter(s): def translateParameter(s):
# name: type -> type name # name: type -> type name
parts = s.split(": ") parts = s.split(": ")
@@ -147,7 +153,11 @@ class CPP:
for i in range(0, len(self.fn.statements)): for i in range(0, len(self.fn.statements)):
s = translateStatement(self.fn.statements[i], self) s = translateStatement(self.fn.statements[i], self)
s = replaceAnd(s) s = replaceAnd(s)
s = replaceAppend(s)
# Replace len twice to account for double invocation.
s = replaceLen(s)
s = replaceLen(s) s = replaceLen(s)
s = replaceTrue(s)
sts.append(s) sts.append(s)
strstatements = "\n".join(sts) strstatements = "\n".join(sts)




Loading…
Cancel
Save