d
This commit is contained in:
12
v3/memory.h
Normal file
12
v3/memory.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "memory_Context.h"
|
||||
|
||||
#ifndef memory_HEADER
|
||||
#define memory_HEADER
|
||||
|
||||
memory_Context memory_generateConstPlayfield(memory_Context);
|
||||
memory_Context memory_selectItem(memory_Context);
|
||||
memory_Context memory_shouldDeselectMismatchedItems(memory_Context);
|
||||
memory_Context memory_shouldDetectVictory(memory_Context);
|
||||
memory_Context memory_shouldHideMatchingItems(memory_Context);
|
||||
|
||||
#endif // memory_HEADER
|
||||
@@ -16,4 +16,6 @@ struct memory_Context {
|
||||
bool victory = false;
|
||||
};
|
||||
|
||||
memory_Context memory_createContext();
|
||||
|
||||
#endif // memory_Context_HEADER
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "memory.h"
|
||||
#include "memory_Context.h"
|
||||
|
||||
std::string memory_test_generateConstPlayfield(
|
||||
) {
|
||||
auto c = memory_createContext();
|
||||
c.playfieldSize = 2;
|
||||
auto c = memory_generateConstPlayfield(c);
|
||||
c = memory_generateConstPlayfield(c);
|
||||
if (
|
||||
c.recentField == "playfieldItems" &&
|
||||
c.playfieldItems.size() == 4 &&
|
||||
@@ -27,10 +28,10 @@ std::string memory_test_selectItem_1x(
|
||||
) {
|
||||
auto c = memory_createContext();
|
||||
c.playfieldSize = 2;
|
||||
auto c = memory_generateConstPlayfield(c);
|
||||
c = memory_generateConstPlayfield(c);
|
||||
# Select the first item.;
|
||||
c.selectedId = 0;
|
||||
auto c = memory_selectItem(c);
|
||||
c = memory_selectItem(c);
|
||||
# See if it's in selectedItems now.;
|
||||
if (
|
||||
c.recentField == "selectedItems" &&
|
||||
@@ -48,12 +49,12 @@ std::string memory_test_selectItem_2x(
|
||||
) {
|
||||
auto c = memory_createContext();
|
||||
c.playfieldSize = 2;
|
||||
auto c = memory_generateConstPlayfield(c);
|
||||
c = memory_generateConstPlayfield(c);
|
||||
# Select the first two items.;
|
||||
c.selectedId = 0;
|
||||
auto c = memory_selectItem(c);
|
||||
c = memory_selectItem(c);
|
||||
c.selectedId = 1;
|
||||
auto c = memory_selectItem(c);
|
||||
c = memory_selectItem(c);
|
||||
# See if both items are selected now.;
|
||||
if (
|
||||
c.recentField == "selectedItems" &&
|
||||
@@ -72,14 +73,14 @@ std::string memory_test_selectItem_3x(
|
||||
) {
|
||||
auto c = memory_createContext();
|
||||
c.playfieldSize = 2;
|
||||
auto c = memory_generateConstPlayfield(c);
|
||||
c = memory_generateConstPlayfield(c);
|
||||
# Select three items.;
|
||||
c.selectedId = 0;
|
||||
auto c = memory_selectItem(c);
|
||||
c = memory_selectItem(c);
|
||||
c.selectedId = 1;
|
||||
auto c = memory_selectItem(c);
|
||||
c = memory_selectItem(c);
|
||||
c.selectedId = 2;
|
||||
auto c = memory_selectItem(c);
|
||||
c = memory_selectItem(c);
|
||||
# See if only one (last) item is selected now.;
|
||||
if (
|
||||
c.recentField == "selectedItems" &&
|
||||
@@ -98,14 +99,14 @@ std::string memory_test_shouldDeselectMismatchedItems(
|
||||
) {
|
||||
auto c = memory_createContext();
|
||||
c.playfieldSize = 2;
|
||||
auto c = memory_generateConstPlayfield(c);
|
||||
c = memory_generateConstPlayfield(c);
|
||||
# Select two items of different groups.;
|
||||
c.selectedId = 0;
|
||||
auto c = memory_selectItem(c);
|
||||
c = memory_selectItem(c);
|
||||
c.selectedId = 2;
|
||||
auto c = memory_selectItem(c);
|
||||
c = memory_selectItem(c);
|
||||
# Detect mismatching.;
|
||||
auto c = memory_shouldDeselectMismatchedItems(c);
|
||||
c = memory_shouldDeselectMismatchedItems(c);
|
||||
# See if the two selected items do not match.;
|
||||
if (
|
||||
c.recentField == "mismatchedItems" &&
|
||||
@@ -125,14 +126,14 @@ std::string memory_test_shouldDeselectMismatchedItems_itemTwice(
|
||||
) {
|
||||
auto c = memory_createContext();
|
||||
c.playfieldSize = 2;
|
||||
auto c = memory_generateConstPlayfield(c);
|
||||
c = memory_generateConstPlayfield(c);
|
||||
# Select the same item twice.;
|
||||
c.selectedId = 0;
|
||||
auto c = memory_selectItem(c);
|
||||
c = memory_selectItem(c);
|
||||
c.selectedId = 0;
|
||||
auto c = memory_selectItem(c);
|
||||
c = memory_selectItem(c);
|
||||
# Detect mismatching.;
|
||||
auto c = memory_shouldDeselectMismatchedItems(c);
|
||||
c = memory_shouldDeselectMismatchedItems(c);
|
||||
# See if the two selected items do not match.;
|
||||
if (
|
||||
c.recentField == "mismatchedItems" &&
|
||||
@@ -154,23 +155,23 @@ std::string memory_test_shouldDetectVictory(
|
||||
) {
|
||||
auto c = memory_createContext();
|
||||
c.playfieldSize = 2;
|
||||
auto c = memory_generateConstPlayfield(c);
|
||||
c = memory_generateConstPlayfield(c);
|
||||
# Select the first two items of the same group.;
|
||||
c.selectedId = 0;
|
||||
auto c = memory_selectItem(c);
|
||||
c = memory_selectItem(c);
|
||||
c.selectedId = 1;
|
||||
auto c = memory_selectItem(c);
|
||||
c = memory_selectItem(c);
|
||||
# Hide the first pair.;
|
||||
auto c = memory_shouldHideMatchingItems(c);
|
||||
c = memory_shouldHideMatchingItems(c);
|
||||
# Select the last two items of the same group.;
|
||||
c.selectedId = 2;
|
||||
auto c = memory_selectItem(c);
|
||||
c = memory_selectItem(c);
|
||||
c.selectedId = 3;
|
||||
auto c = memory_selectItem(c);
|
||||
c = memory_selectItem(c);
|
||||
# Hide the second pair.;
|
||||
auto c = memory_shouldHideMatchingItems(c);
|
||||
c = memory_shouldHideMatchingItems(c);
|
||||
# Detect victory.;
|
||||
auto c = memory_shouldDetectVictory(c);
|
||||
c = memory_shouldDetectVictory(c);
|
||||
# See if victory has been detected.;
|
||||
if (
|
||||
c.recentField == "victory" &&
|
||||
@@ -188,14 +189,14 @@ std::string memory_test_shouldHideMatchingItems(
|
||||
) {
|
||||
auto c = memory_createContext();
|
||||
c.playfieldSize = 2;
|
||||
auto c = memory_generateConstPlayfield(c);
|
||||
c = memory_generateConstPlayfield(c);
|
||||
# Select two items of the same group.;
|
||||
c.selectedId = 0;
|
||||
auto c = memory_selectItem(c);
|
||||
c = memory_selectItem(c);
|
||||
c.selectedId = 1;
|
||||
auto c = memory_selectItem(c);
|
||||
c = memory_selectItem(c);
|
||||
# Hide matching items.;
|
||||
auto c = memory_shouldHideMatchingItems(c);
|
||||
c = memory_shouldHideMatchingItems(c);
|
||||
# See if the two selected items match.;
|
||||
if (
|
||||
c.recentField == "hiddenItems" &&
|
||||
|
||||
@@ -90,8 +90,12 @@ def translateStatement(s, state):
|
||||
posEqual >= 0
|
||||
):
|
||||
name = ss[:posEqual]
|
||||
value = ss[posEqual + len(" = "):]
|
||||
return f"{indentation}auto {name} = {value};"
|
||||
# Skip prepending 'auto' each time variable is assigned,
|
||||
# only do it the first time
|
||||
if name not in state.varNames:
|
||||
state.varNames[name] = True
|
||||
value = ss[posEqual + len(" = "):]
|
||||
return f"{indentation}auto {name} = {value};"
|
||||
|
||||
# Keep "if ("
|
||||
if ss == "if (":
|
||||
@@ -138,6 +142,7 @@ class CPP:
|
||||
self.fn = fn
|
||||
self.isIf = False
|
||||
self.isIfNot = False
|
||||
self.varNames = {}
|
||||
|
||||
def translate(self):
|
||||
returnType = translateType(self.fn.returnType)
|
||||
|
||||
Reference in New Issue
Block a user