Михаил Капелько 8 月之前
父節點
當前提交
fc82f332ed
共有 9 個檔案被更改,包括 71 行新增42 行删除
  1. +1
    -1
      v3/gen-C++
  2. +4
    -0
      v3/main.cpp
  3. +20
    -19
      v3/memory.cpp
  4. +10
    -10
      v3/memory.py
  5. +4
    -6
      v3/memory_Context.cpp
  6. +19
    -0
      v3/memory_Context.h
  7. +2
    -2
      v3/memory_Context.py
  8. +2
    -1
      v3/memory_test.cpp
  9. +9
    -3
      v3/tPythonC++/CPP.py

+ 1
- 1
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

+ 4
- 0
v3/main.cpp 查看文件

@@ -1,8 +1,12 @@
#include "memory_Context.h"
#include <iostream>
#include <string>
#include <vector>

extern memory_Context memory_createContext();

int main() {
memory_createContext();
std::cout <<
"check" //memory_test_generateConstPlayfield()
<< std::endl


+ 20
- 19
v3/memory.cpp 查看文件

@@ -1,6 +1,7 @@
#include <map>
#include <string>
#include "entities.h"
#include <vector>
#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<int, int> 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;
}


+ 10
- 10
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
#}

+ 4
- 6
v3/memory_Context.cpp 查看文件

@@ -1,7 +1,5 @@
#include <map>
#include <string>
#include "entities.h"



#include "memory_Context.h"

memory_Context memory_createContext() {
return memory_Context();
}

+ 19
- 0
v3/memory_Context.h 查看文件

@@ -0,0 +1,19 @@
#include <map>
#include <string>
#include <vector>

#ifndef memory_Context_HEADER
#define memory_Context_HEADER

struct memory_Context {
std::vector<int> hiddenItems;
std::vector<int> mismatchedItems;
std::map<int, int> playfieldItems;
int playfieldSize = 0;
std::string recentField = "none";
int selectedId = -1;
std::vector<int> selectedItems;
bool victory = false;
};

#endif // memory_Context_HEADER

+ 2
- 2
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



+ 2
- 1
v3/memory_test.cpp 查看文件

@@ -1,6 +1,7 @@
#include <map>
#include <string>
#include "entities.h"
#include <vector>
#include "memory_Context.h"

std::string memory_test_generateConstPlayfield(
) {


+ 9
- 3
v3/tPythonC++/CPP.py 查看文件

@@ -3,7 +3,8 @@ from Function import *
def includes():
return """#include <map>
#include <string>
#include "entities.h"
#include <vector>
#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):


Loading…
取消
儲存