Михаил Капелько 8 månader sedan
förälder
incheckning
5fe21fe872
4 ändrade filer med 22 tillägg och 12 borttagningar
  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 Visa fil

@@ -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;
}


+ 1
- 1
v3/memory.py Visa fil

@@ -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"


+ 1
- 1
v3/memory_test.cpp Visa fil

@@ -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";
}


+ 11
- 1
v3/tPythonC++/CPP.py Visa fil

@@ -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)



Laddar…
Avbryt
Spara