aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/input-output/input/json-parsing/rules_parser.cpp2
-rw-r--r--src/main/input-output/input/sol_preset_types.cpp4
-rw-r--r--src/test/integration_tests/canfield_test.cpp102
-rw-r--r--src/test/test_helper.cpp8
-rw-r--r--src/test/test_helper.h2
5 files changed, 115 insertions, 3 deletions
diff --git a/src/main/input-output/input/json-parsing/rules_parser.cpp b/src/main/input-output/input/json-parsing/rules_parser.cpp
index 4e0634f..da43cf3 100644
--- a/src/main/input-output/input/json-parsing/rules_parser.cpp
+++ b/src/main/input-output/input/json-parsing/rules_parser.cpp
@@ -512,7 +512,7 @@ string rules_parser::rules_schema_json() {
"any",
"no-build",
"kings",
- "auto-reserve"
+ "auto-reserve-then-waste"
]
},
"diagonal deal": {
diff --git a/src/main/input-output/input/sol_preset_types.cpp b/src/main/input-output/input/sol_preset_types.cpp
index 34ad822..dc5f6b1 100644
--- a/src/main/input-output/input/sol_preset_types.cpp
+++ b/src/main/input-output/input/sol_preset_types.cpp
@@ -277,7 +277,7 @@ map<string, string> sol_preset_types::mp = {
"count": 4,
"build policy": "red-black",
"move built group": "whole-pile",
- "spaces policy": "auto-reserve",
+ "spaces policy": "auto-reserve-then-waste",
"wraps": true
},
"foundations": {
@@ -307,7 +307,7 @@ map<string, string> sol_preset_types::mp = {
"build policy": "red-black",
"move built group": "yes",
"move built group": "whole-pile",
- "spaces policy": "auto-reserve",
+ "spaces policy": "auto-reserve-then-waste",
"wraps": true
},
"foundations": {
diff --git a/src/test/integration_tests/canfield_test.cpp b/src/test/integration_tests/canfield_test.cpp
index 6a045ea..406b23a 100644
--- a/src/test/integration_tests/canfield_test.cpp
+++ b/src/test/integration_tests/canfield_test.cpp
@@ -5,8 +5,14 @@
#include <gtest/gtest.h>
#include "../test_helper.h"
+#include "../../main/input-output/input/json-parsing/rules_parser.h"
+#include "../../main/game/search-state/game_state.h"
+
+using std::vector;
typedef test_helper th;
+typedef game_state::streamliner_options so;
+typedef std::initializer_list<std::initializer_list<std::string>> string_il;
const static std::string path = "resources/canfield/";
const static std::string type = "simple-canfield";
@@ -26,3 +32,99 @@ TEST(Canfield, SimpleUnsolvable) {
TEST(Canfield, ComplexUnsolvable) {
EXPECT_FALSE(th::is_solvable(path + "ComplexUnsolvable.json", type));
}
+
+TEST(Canfield, FoundationSingleCard) {
+ sol_rules sr = rules_parser::from_preset("canfield");
+ game_state gs(sr, 0, so::NONE);
+
+ ASSERT_EQ(1, test_helper::cards_in_founds(gs));
+}
+
+TEST(Canfield, FoundationWraps) {
+ sol_rules sr = rules_parser::from_preset("simple-canfield");
+
+ game_state gs(sr, string_il{
+ {"3C"},{},{},{}, // Foundations
+ {},{}, // Stock-waste
+ {}, // Reserve
+ {"AC"},{},{} // Tableau piles
+ });
+
+ vector<move> actual_moves = gs.get_legal_moves();
+ vector<move> exp_moves = {
+ move(move::mtype::regular, 7, 0, 1)
+ };
+
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
+}
+
+TEST(Canfield, MoveWholePile) {
+ sol_rules sr = rules_parser::from_preset("simple-canfield");
+
+ game_state gs(sr, string_il{
+ {"3C"},{},{},{}, // Foundations
+ {},{}, // Stock-waste
+ {}, // Reserve
+ {"2H","3S","AH"},{"AC"},{"2D"} // Tableau piles
+ });
+
+ vector<move> actual_moves = gs.get_legal_moves();
+ vector<move> exp_moves = {
+ move(move::mtype::built_group, 7, 8, 3)
+ };
+
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
+}
+
+TEST(Canfield, MoveWholePileNotSpace) {
+ sol_rules sr = rules_parser::from_preset("simple-canfield");
+
+ game_state gs(sr, string_il{
+ {"3C"},{},{},{}, // Foundations
+ {},{}, // Stock-waste
+ {}, // Reserve
+ {"2H","3S","AH"},{},{"2D"} // Tableau piles
+ });
+
+ vector<move> actual_moves = gs.get_legal_moves();
+ vector<move> exp_moves = {};
+
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
+}
+
+TEST(Canfield, AutoReserve) {
+ sol_rules sr = rules_parser::from_preset("simple-canfield");
+
+ game_state gs(sr, string_il{
+ {"3C"},{},{},{}, // Foundations
+ {"3D"},{"2D"}, // Stock-waste
+ {"3H"}, // Reserve
+ {"2H","3S","AH"},{},{"AC"} // Tableau piles
+ });
+
+ vector<move> actual_moves = gs.get_legal_moves();
+ vector<move> exp_moves = {
+ move(move::mtype::regular, 6, 8, 1)
+ };
+
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
+}
+
+TEST(Canfield, AutoReserveThenWaste) {
+ sol_rules sr = rules_parser::from_preset("simple-canfield");
+
+ game_state gs(sr, string_il{
+ {"3C"},{},{},{}, // Foundations
+ {"3D"},{"3H"}, // Stock-waste
+ {}, // Reserve
+ {"2H","3S","AH"},{},{"AC"} // Tableau piles
+ });
+
+ vector<move> actual_moves = gs.get_legal_moves();
+ vector<move> exp_moves = {
+ move(move::mtype::stock_k_plus, 4, 8, 1),
+ move(move::mtype::stock_k_plus, 4, 8, 2),
+ };
+
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
+}
diff --git a/src/test/test_helper.cpp b/src/test/test_helper.cpp
index c4f902e..33a81ca 100644
--- a/src/test/test_helper.cpp
+++ b/src/test/test_helper.cpp
@@ -124,6 +124,14 @@ void test_helper::k_plus_stock_test
ASSERT_EQ(gs.get_data(), game_state(sr, piles).get_data()) << gs;
}
+uint8_t test_helper::cards_in_founds(game_state& gs) {
+ uint8_t sz = 0;
+ for (auto found : gs.foundations) {
+ sz += gs.piles[found].size();
+ }
+ return sz;
+}
+
ostream& operator <<(ostream& os, const move& m) {
return os << "move:(" << int(m.from)
<< "," << int(m.to)
diff --git a/src/test/test_helper.h b/src/test/test_helper.h
index 564310e..89d28cb 100644
--- a/src/test/test_helper.h
+++ b/src/test/test_helper.h
@@ -11,6 +11,7 @@
#include "../main/game/card.h"
#include "../main/game/pile.h"
#include "../main/game/move.h"
+#include "../main/game/search-state/game_state.h"
class test_helper {
public:
@@ -30,6 +31,7 @@ public:
, card
);
static bool moves_eq(std::vector<move>&, std::vector<move>&);
+ static uint8_t cards_in_founds(game_state&);
};
std::ostream& operator <<(std::ostream&, const move&);