aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharlie Blake2018-06-08 14:21:53 +0100
committerCharlie Blake2018-06-08 14:22:04 +0100
commit04cbac28b7d62828dfa43cd77ed8dc790f24237c (patch)
tree8cb34b002b4de591452c632938c16208117c0115
parentMove auto found. logic into sep. file (diff)
downloadmetasol-04cbac28b7d62828dfa43cd77ed8dc790f24237c.tar.gz
metasol-04cbac28b7d62828dfa43cd77ed8dc790f24237c.zip

Fix built move bug and add unit tests

-rw-r--r--CMakeLists.txt3
-rw-r--r--resources/rules-presets/simple-alpha-star.json2
-rw-r--r--src/main/game/search-state/game_state.auto_foundation_moves.cpp1
-rw-r--r--src/main/game/search-state/game_state.h1
-rw-r--r--src/main/game/search-state/game_state.legal_moves.cpp29
-rw-r--r--src/main/input-output/input/sol_preset_types.cpp2
-rw-r--r--src/test/resources/alpha_star/ComplexSolvable.json6
-rw-r--r--src/test/resources/alpha_star/ComplexUnsolvable.json6
-rw-r--r--src/test/resources/alpha_star/SimpleSolvable.json6
-rw-r--r--src/test/resources/alpha_star/SimpleUnsolvable.json6
-rw-r--r--src/test/test_helper.cpp40
-rw-r--r--src/test/test_helper.h9
-rw-r--r--src/test/unit_tests/built_group_move_gen_test.cpp254
-rw-r--r--src/test/unit_tests/legal_move_gen_test.cpp62
14 files changed, 336 insertions, 91 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ba487e2..0fcbde8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -67,7 +67,8 @@ set(sources_test
src/test/unit_tests/rules_parser_test.cpp
src/test/unit_tests/card_test.cpp
src/test/unit_tests/pile_test.cpp
- src/test/unit_tests/legal_move_gen_test.cpp)
+ src/test/unit_tests/legal_move_gen_test.cpp
+ src/test/unit_tests/built_group_move_gen_test.cpp)
###############################################################################
## Rapid JSON setup ###########################################################
diff --git a/resources/rules-presets/simple-alpha-star.json b/resources/rules-presets/simple-alpha-star.json
index 9b15004..c80a82b 100644
--- a/resources/rules-presets/simple-alpha-star.json
+++ b/resources/rules-presets/simple-alpha-star.json
@@ -4,6 +4,6 @@
"build policy": "same-suit",
"move built group": true
},
- "max rank": 5,
+ "max rank": 6,
"foundations initial card": true
} \ No newline at end of file
diff --git a/src/main/game/search-state/game_state.auto_foundation_moves.cpp b/src/main/game/search-state/game_state.auto_foundation_moves.cpp
index e0eaf00..2faddd0 100644
--- a/src/main/game/search-state/game_state.auto_foundation_moves.cpp
+++ b/src/main/game/search-state/game_state.auto_foundation_moves.cpp
@@ -6,7 +6,6 @@
typedef sol_rules::build_policy pol;
-typedef sol_rules::stock_deal_type sdt;
using std::max;
diff --git a/src/main/game/search-state/game_state.h b/src/main/game/search-state/game_state.h
index c46f25b..3c6b192 100644
--- a/src/main/game/search-state/game_state.h
+++ b/src/main/game/search-state/game_state.h
@@ -75,7 +75,6 @@ private:
void get_built_group_moves(std::vector<move>&) const;
pile::size_type get_built_group_height(pile::ref) const;
bool valid_built_group_move(card, card, card) const;
- void add_built_group_move(std::vector<move>&, pile::ref, pile::ref) const;
void add_empty_built_group_moves(std::vector<move>&, pile::ref, pile::ref,
card) const;
bool dominance_blocks_foundation_move(pile::ref);
diff --git a/src/main/game/search-state/game_state.legal_moves.cpp b/src/main/game/search-state/game_state.legal_moves.cpp
index 85b9382..b6e110d 100644
--- a/src/main/game/search-state/game_state.legal_moves.cpp
+++ b/src/main/game/search-state/game_state.legal_moves.cpp
@@ -178,11 +178,7 @@ bool game_state::is_valid_tableau_move(const pile::ref rem_ref,
}
// Checks rank
- else if (rem_c.get_rank() + 1 != add_c.get_rank()) {
- return false;
- } else {
- return true;
- }
+ else return rem_c.get_rank() + 1 == add_c.get_rank();
}
bool game_state::is_valid_foundations_move(const pile::ref rem_ref,
@@ -253,7 +249,8 @@ void game_state::get_built_group_moves(vector<move>& moves) const {
// Adds the move to the list of moves, as a special built group move
if (valid_built_group_move(bg_low, bg_high, add_card)) {
- add_built_group_move(moves, rem_ref, add_ref);
+
+ moves.emplace_back(rem_ref, add_ref, built_group_height);
}
}
}
@@ -298,33 +295,19 @@ pile::size_type game_state::get_built_group_height(pile::ref ref) const {
bool game_state::valid_built_group_move(card bg_low, card bg_high, card add_card)
const {
- // The rank of the card we're moving the built group to must be greater than
- // the second-from-top card of the built group, and less than or equal to the
- // card that would come next at the top of the built pile
- if (add_card.get_rank() <= bg_low.get_rank() + 1
- || add_card.get_rank() > bg_high.get_rank() + 1) {
- return false;
- }
+ if (add_card.get_rank() != bg_high.get_rank() + 1) return false;
// Checks to see if the suits are correct
switch (rules.built_group_pol) {
case pol::SAME_SUIT:
return bg_low.get_suit() == add_card.get_suit();
-
case pol::RED_BLACK: {
- bool same_suit = bg_low.get_suit() == add_card.get_suit();
- bool even_diff = (add_card.get_rank() - bg_low.get_rank()) % 2 == 0;
- return (same_suit && even_diff) || (!same_suit && !even_diff);
+ return bg_high.get_colour() != add_card.get_colour();
}
default: return true;
}
}
-void game_state::add_built_group_move(vector<move>& moves, pile::ref rem_ref,
- pile::ref add_ref) const {
- moves.emplace_back(rem_ref, add_ref, 2);
-}
-
void game_state::add_empty_built_group_moves(vector<move>& moves,
pile::ref rem_ref,
pile::ref add_ref,
@@ -334,7 +317,7 @@ void game_state::add_empty_built_group_moves(vector<move>& moves,
pile::size_type card_idx = 1;
do {
moves.emplace_back(
- rem_ref, add_ref, static_cast<pile::ref>(card_idx + 1)
+ rem_ref, add_ref, static_cast<pile::size_type>(card_idx + 1)
);
} while (piles[rem_ref][card_idx++] != bg_high);
}
diff --git a/src/main/input-output/input/sol_preset_types.cpp b/src/main/input-output/input/sol_preset_types.cpp
index 07c824b..53141a8 100644
--- a/src/main/input-output/input/sol_preset_types.cpp
+++ b/src/main/input-output/input/sol_preset_types.cpp
@@ -312,7 +312,7 @@ map<string, string> sol_preset_types::mp = {
"build policy": "same-suit",
"move built group": true
},
- "max rank": 5,
+ "max rank": 6,
"foundations initial card": true
}
)"
diff --git a/src/test/resources/alpha_star/ComplexSolvable.json b/src/test/resources/alpha_star/ComplexSolvable.json
index e7eedd5..ab6b24e 100644
--- a/src/test/resources/alpha_star/ComplexSolvable.json
+++ b/src/test/resources/alpha_star/ComplexSolvable.json
@@ -1,7 +1,7 @@
{
"tableau piles": [
- ["3S","2C","3C","5C","5H","4H"],
- ["4S","4C","5S","2D","5D"],
- ["2S","2H","3H","4D","3D"]
+ ["6C","3S","2C","3C","5C","5H","4H"],
+ ["6S","4S","4C","5S","2D","5D"],
+ ["6H","6D","2S","2H","3H","4D","3D"]
]
} \ No newline at end of file
diff --git a/src/test/resources/alpha_star/ComplexUnsolvable.json b/src/test/resources/alpha_star/ComplexUnsolvable.json
index a01f2b5..56ea441 100644
--- a/src/test/resources/alpha_star/ComplexUnsolvable.json
+++ b/src/test/resources/alpha_star/ComplexUnsolvable.json
@@ -1,7 +1,7 @@
{
"tableau piles": [
- ["2S","2C","3C","5C","5H","4H"],
- ["4S","4C","5S","2D","5D"],
- ["3S","2H","3H","4D","3D"]
+ ["6C","2S","2C","3C","5C","5H","4H"],
+ ["6S","4S","4C","5S","2D","5D"],
+ ["6H","6D","3S","2H","3H","4D","3D"]
]
}
diff --git a/src/test/resources/alpha_star/SimpleSolvable.json b/src/test/resources/alpha_star/SimpleSolvable.json
index d160e42..7994021 100644
--- a/src/test/resources/alpha_star/SimpleSolvable.json
+++ b/src/test/resources/alpha_star/SimpleSolvable.json
@@ -1,7 +1,7 @@
{
"tableau piles": [
- ["5S","5C","4C","3C","2S","2C"],
- ["5D","4D","3S","3D","2D"],
- ["5H","4S","4H","3H","2H"]
+ ["6C","5S","5C","4C","3C","2S","2C"],
+ ["6S","6D","5D","4D","3S","3D","2D"],
+ ["6H","5H","4S","4H","3H","2H"]
]
}
diff --git a/src/test/resources/alpha_star/SimpleUnsolvable.json b/src/test/resources/alpha_star/SimpleUnsolvable.json
index 1097473..ac6741e 100644
--- a/src/test/resources/alpha_star/SimpleUnsolvable.json
+++ b/src/test/resources/alpha_star/SimpleUnsolvable.json
@@ -1,7 +1,7 @@
{
"tableau piles": [
- ["2S","2C","3C","4C","5S","5C"],
- ["2D","3D","4S","4D","5D"],
- ["2H","3S","3H","4H","5H"]
+ ["2S","2C","3C","4C","5S","5C","6C"],
+ ["2D","3D","4S","4D","5D","6S","6D"],
+ ["2H","3S","3H","4H","5H","6H"]
]
} \ No newline at end of file
diff --git a/src/test/test_helper.cpp b/src/test/test_helper.cpp
index 6f2a68d..18b36eb 100644
--- a/src/test/test_helper.cpp
+++ b/src/test/test_helper.cpp
@@ -14,7 +14,9 @@
#define ASSERT_(t_f, statement) ASSERT_TRUE((statement) == (t_f))
using namespace rapidjson;
-using namespace std;
+using std::initializer_list;
+using std::vector;
+using std::ostream;
bool test_helper::is_solvable(const std::string& input_file, const std::string& preset_type) {
const Document in_doc = json_helper::get_file_json(input_file);
@@ -57,3 +59,39 @@ void test_helper::run_foundations_dominance_test(sol_rules::build_policy policy,
}
ASSERT_TRUE(n->children.empty());
}
+
+void test_helper::run_built_group_test(sol_rules sr,
+ initializer_list<pile> piles,
+ vector<move> exp_moves) {
+ game_state gs(sr, piles);
+ vector<move> actual_moves = gs.get_legal_moves();
+
+ ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
+}
+
+bool test_helper::moves_eq(vector<move>& exp_moves, vector<move>& actual_moves) {
+ if (exp_moves.size() != actual_moves.size()) return false;
+
+ for (move m : actual_moves) {
+ auto it = find(begin(exp_moves), end(exp_moves), m);
+ bool found = it != end(exp_moves);
+
+ if (found) exp_moves.erase(it);
+ else return false;
+ }
+
+ return true;
+}
+ostream& operator <<(ostream& os, const move& m) {
+ return os << "move:(" << int(m.from)
+ << "," << int(m.to)
+ << "," << int(m.count)
+ << ")";
+}
+
+ostream& operator <<(ostream& os, const vector<move>& moves) {
+ for (const move m : moves) {
+ os << m << ",\n";
+ }
+ return os;
+}
diff --git a/src/test/test_helper.h b/src/test/test_helper.h
index b0199af..463a935 100644
--- a/src/test/test_helper.h
+++ b/src/test/test_helper.h
@@ -9,15 +9,20 @@
#include "../main/game/sol_rules.h"
#include "../main/game/card.h"
+#include "../main/game/pile.h"
+#include "../main/game/move.h"
class test_helper {
public:
static bool is_solvable(const std::string&, const std::string&);
- static void run_card_cache_test(sol_rules::build_policy, bool, bool);
-
static void run_foundations_dominance_test(sol_rules::build_policy policy,
std::vector<card> cards);
+ static void run_built_group_test(sol_rules sr, std::initializer_list<pile>, std::vector<move>);
+ static bool moves_eq(std::vector<move>&, std::vector<move>&);
};
+std::ostream& operator <<(std::ostream&, const move&);
+std::ostream& operator <<(std::ostream&, const std::vector<move>&);
+
#endif //SOLVITAIRE_TEST_HELPER_H
diff --git a/src/test/unit_tests/built_group_move_gen_test.cpp b/src/test/unit_tests/built_group_move_gen_test.cpp
new file mode 100644
index 0000000..0bdff4d
--- /dev/null
+++ b/src/test/unit_tests/built_group_move_gen_test.cpp
@@ -0,0 +1,254 @@
+//
+// Created by thecharlesblake on 1/11/18.
+//
+
+#include <gtest/gtest.h>
+
+#include "../test_helper.h"
+#include "../../main/game/search-state/game_state.h"
+#include "../../main/game/sol_rules.h"
+
+typedef sol_rules::build_policy pol;
+
+using std::vector;
+using std::ostream;
+using std::initializer_list;
+
+TEST(BuiltGroupMoveGen, SameSuitEmpty) {
+ sol_rules sr;
+ sr.tableau_pile_count = 5;
+ sr.built_group_pol = pol::SAME_SUIT;
+ sr.move_built_group = true;
+
+ test_helper::run_built_group_test(
+ sr,
+ {
+ {},
+ {"3C","2C","AC"}, // Same suit
+ {"3H","2S","AH"}, // Red black
+ {"3D","2D","AS"}, // Any suit
+ {}
+ },
+ {
+ // Regular moves
+ move(1, 0, 1),
+ move(2, 0, 1),
+ move(3, 0, 1),
+ move(1, 4, 1),
+ move(2, 4, 1),
+ move(3, 4, 1),
+
+ // Built pile moves
+ move(1, 0, 2),
+ move(1, 0, 3),
+ move(1, 4, 2),
+ move(1, 4, 3)
+ }
+ );
+}
+
+TEST(BuiltGroupMoveGen, RedBlackEmpty) {
+ sol_rules sr;
+ sr.tableau_pile_count = 5;
+ sr.built_group_pol = pol::RED_BLACK;
+ sr.move_built_group = true;
+
+ test_helper::run_built_group_test(
+ sr,
+ {
+ {},
+ {"3C","2C","AC"}, // Same suit
+ {"3H","2S","AH"}, // Red black
+ {"3D","2D","AS"}, // Any suit
+ {}
+ },
+ {
+ // Regular moves
+ move(1, 0, 1),
+ move(2, 0, 1),
+ move(3, 0, 1),
+ move(1, 4, 1),
+ move(2, 4, 1),
+ move(3, 4, 1),
+
+ // Built pile moves
+ move(2, 0, 2),
+ move(2, 0, 3),
+ move(2, 4, 2),
+ move(2, 4, 3),
+
+ move(3, 0, 2),
+ move(3, 4, 2)
+ }
+ );
+}
+
+TEST(BuiltGroupMoveGen, AnySuitEmpty) {
+ sol_rules sr;
+ sr.tableau_pile_count = 5;
+ sr.built_group_pol = pol::ANY_SUIT;
+ sr.move_built_group = true;
+
+ test_helper::run_built_group_test(
+ sr,
+ {
+ {},
+ {"3C","2C","AC"}, // Same suit
+ {"3H","2S","AH"}, // Red black
+ {"3D","2D","AS"}, // Any suit
+ {}
+ },
+ {
+ // Regular moves
+ move(1, 0, 1),
+ move(2, 0, 1),
+ move(3, 0, 1),
+ move(1, 4, 1),
+ move(2, 4, 1),
+ move(3, 4, 1),
+
+ // Built pile moves
+ move(1, 0, 2),
+ move(1, 0, 3),
+ move(1, 4, 2),
+ move(1, 4, 3),
+
+ move(2, 0, 2),
+ move(2, 0, 3),
+ move(2, 4, 2),
+ move(2, 4, 3),
+
+ move(3, 0, 2),
+ move(3, 0, 3),
+ move(3, 4, 2),
+ move(3, 4, 3),
+ }
+ );
+}
+
+TEST(BuiltGroupMoveGen, CantMove) {
+ sol_rules sr;
+ sr.tableau_pile_count = 5;
+ sr.built_group_pol = pol::ANY_SUIT;
+ sr.move_built_group = false;
+
+ test_helper::run_built_group_test(
+ sr,
+ {
+ {},
+ {"3C","2C","AC"}, // Same suit
+ {"3H","2S","AH"}, // Red black
+ {"3D","2D","AS"}, // Any suit
+ {}
+ },
+ {
+ // Regular moves
+ move(1, 0, 1),
+ move(2, 0, 1),
+ move(3, 0, 1),
+ move(1, 4, 1),
+ move(2, 4, 1),
+ move(3, 4, 1)
+ }
+ );
+}
+
+TEST(BuiltGroupMoveGen, SameSuitOccupied) {
+ sol_rules sr;
+ sr.tableau_pile_count = 5;
+ sr.built_group_pol = pol::SAME_SUIT;
+ sr.move_built_group = true;
+
+ test_helper::run_built_group_test(
+ sr,
+ {
+ {"4C"},
+ {"3C","2C","AC"}, // Same suit
+ {"3H","2S","AH"}, // Red black
+ {"3D","2D","AS"}, // Any suit
+ {}
+ },
+ {
+ // Regular moves
+ move(1, 4, 1),
+ move(2, 4, 1),
+ move(3, 4, 1),
+ move(0, 4, 1),
+
+ // Built pile moves
+ move(1, 0, 3),
+ move(1, 4, 2),
+ move(1, 4, 3)
+ }
+ );
+}
+
+TEST(BuiltGroupMoveGen, RedBlackOccupied) {
+ sol_rules sr;
+ sr.tableau_pile_count = 5;
+ sr.built_group_pol = pol::RED_BLACK;
+ sr.move_built_group = true;
+
+ test_helper::run_built_group_test(
+ sr,
+ {
+ {"4C"},
+ {"3C","2C","AC"}, // Same suit
+ {"3H","2S","AH"}, // Red black
+ {"3D","2D","AS"}, // Any suit
+ {}
+ },
+ {
+ // Regular moves
+ move(1, 4, 1),
+ move(2, 4, 1),
+ move(3, 4, 1),
+ move(0, 4, 1),
+
+ // Built pile moves
+ move(2, 0, 3),
+ move(2, 4, 2),
+ move(2, 4, 3),
+ move(3, 4, 2)
+ }
+ );
+}
+
+TEST(BuiltGroupMoveGen, AnySuitOccupied) {
+ sol_rules sr;
+ sr.tableau_pile_count = 5;
+ sr.built_group_pol = pol::ANY_SUIT;
+ sr.move_built_group = true;
+
+ test_helper::run_built_group_test(
+ sr,
+ {
+ {"4C"},
+ {"3C","2C","AC"}, // Same suit
+ {"3H","2S","AH"}, // Red black
+ {"3D","2D","AS"}, // Any suit
+ {}
+ },
+ {
+ // Regular moves
+ move(1, 4, 1),
+ move(2, 4, 1),
+ move(3, 4, 1),
+ move(0, 4, 1),
+
+ // Built pile moves
+ move(1, 0, 3),
+ move(2, 0, 3),
+ move(3, 0, 3),
+
+ move(1, 4, 2),
+ move(1, 4, 3),
+
+ move(2, 4, 2),
+ move(2, 4, 3),
+
+ move(3, 4, 2),
+ move(3, 4, 3),
+ }
+ );
+}
diff --git a/src/test/unit_tests/legal_move_gen_test.cpp b/src/test/unit_tests/legal_move_gen_test.cpp
index 84755f6..f8c9a63 100644
--- a/src/test/unit_tests/legal_move_gen_test.cpp
+++ b/src/test/unit_tests/legal_move_gen_test.cpp
@@ -16,10 +16,6 @@ using std::vector;
using std::ostream;
using std::initializer_list;
-bool moves_eq(vector<move>&, vector<move>&);
-ostream& operator <<(ostream&, const move&);
-ostream& operator <<(ostream&, const vector<move>&);
-
TEST(LegalMoveGen, BuildPolAnySuit) {
sol_rules sr;
sr.build_pol = pol::ANY_SUIT;
@@ -41,7 +37,7 @@ TEST(LegalMoveGen, BuildPolAnySuit) {
move(4,3)
};
- ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}
TEST(LegalMoveGen, BuildPolRedBlack) {
@@ -63,7 +59,7 @@ TEST(LegalMoveGen, BuildPolRedBlack) {
move(4,3)
};
- ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}
TEST(LegalMoveGen, BuildPolSameSuit) {
@@ -84,7 +80,7 @@ TEST(LegalMoveGen, BuildPolSameSuit) {
move(4,0)
};
- ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}
TEST(LegalMoveGen, BuildPolNoBuild) {
@@ -104,7 +100,7 @@ TEST(LegalMoveGen, BuildPolNoBuild) {
vector<move> exp_moves = {
};
- ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}
TEST(LegalMoveGen, SpacesPolAny) {
@@ -122,7 +118,7 @@ TEST(LegalMoveGen, SpacesPolAny) {
move(1, 0)
};
- ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}
TEST(LegalMoveGen, SpacesPolKings) {
@@ -141,7 +137,7 @@ TEST(LegalMoveGen, SpacesPolKings) {
move(2, 0)
};
- ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}
TEST(LegalMoveGen, SpacesPolNoBuild) {
@@ -158,7 +154,7 @@ TEST(LegalMoveGen, SpacesPolNoBuild) {
vector<move> exp_moves = {
};
- ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}
TEST(LegalMoveGen, MoveBuiltGroupTrue) {
@@ -177,7 +173,7 @@ TEST(LegalMoveGen, MoveBuiltGroupTrue) {
move(1, 0, 2)
};
- ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}
TEST(LegalMoveGen, MoveBuiltGroupFalse) {
@@ -195,7 +191,7 @@ TEST(LegalMoveGen, MoveBuiltGroupFalse) {
move(1, 0, 1)
};
- ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}
TEST(LegalMoveGen, Foundations) {
@@ -219,7 +215,7 @@ TEST(LegalMoveGen, Foundations) {
move(7, 3)
};
- ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}
TEST(LegalMoveGen, FoundationsRemovable) {
@@ -241,7 +237,7 @@ TEST(LegalMoveGen, FoundationsRemovable) {
move(0, 4)
};
- ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}
TEST(LegalMoveGen, Cells) {
@@ -261,7 +257,7 @@ TEST(LegalMoveGen, Cells) {
move(2, 1)
};
- ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}
TEST(LegalMoveGen, StockDealToWaste) {
@@ -283,7 +279,7 @@ TEST(LegalMoveGen, StockDealToWaste) {
move(4, 5)
};
- ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}
TEST(LegalMoveGen, StockDealToTableau) {
@@ -304,35 +300,5 @@ TEST(LegalMoveGen, StockDealToTableau) {
move(4, 255, 2) // Special stock-to-tableau syntax
};
- ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
-}
-
-
-
-bool moves_eq(vector<move>& exp_moves, vector<move>& actual_moves) {
- if (exp_moves.size() != actual_moves.size()) return false;
-
- for (move m : actual_moves) {
- auto it = find(begin(exp_moves), end(exp_moves), m);
- bool found = it != end(exp_moves);
-
- if (found) exp_moves.erase(it);
- else return false;
- }
-
- return true;
-}
-
-ostream& operator <<(ostream& os, const move& m) {
- return os << "move:(" << int(m.from)
- << "," << int(m.to)
- << "," << int(m.count)
- << ")";
-}
-
-ostream& operator <<(ostream& os, const vector<move>& moves) {
- for (const move m : moves) {
- os << m << ",\n";
- }
- return os;
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}