diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/game/game_state.cpp | 38 | ||||
| -rw-r--r-- | src/main/game/sol_rules.cpp | 5 | ||||
| -rw-r--r-- | src/main/input-output/command_line_helper.cpp | 6 | ||||
| -rw-r--r-- | src/main/input-output/deal_parser.cpp | 17 | ||||
| -rw-r--r-- | src/main/input-output/deal_parser.h | 4 | ||||
| -rw-r--r-- | src/main/solver/solver.cpp | 4 | ||||
| -rw-r--r-- | src/main/solver/solver.h | 4 | ||||
| -rw-r--r-- | src/test/resources/SPTestName.json | 7 | ||||
| -rw-r--r-- | src/test/spanish_patience_test.cpp | 6 | ||||
| -rw-r--r-- | src/test/test_helper.cpp | 18 | ||||
| -rw-r--r-- | src/test/test_helper.h | 2 |
11 files changed, 66 insertions, 45 deletions
diff --git a/src/main/game/game_state.cpp b/src/main/game/game_state.cpp index 01a17fb..b851f2a 100644 --- a/src/main/game/game_state.cpp +++ b/src/main/game/game_state.cpp @@ -28,6 +28,25 @@ game_state::game_state(const sol_rules& s_rules) : stock(pile::stock_factory()), waste(pile::waste_factory()), hole(pile::hole_factory(s_rules.max_rank)) { + + // Creates the tableau piles + for (unsigned int i = 0; i < rules.tableau_pile_count; i++) { + tableau_piles.push_back(pile::tableau_factory(rules.build_ord)); + } + + // If there are foundation piles, create the relevant pile vectors + if (rules.foundations) { + for (int i = 0; i < 4; i++) { + foundations.push_back(pile::foundation_factory(pol(i))); + } + } + + // If there are cell piles, create the relevant cell vectors + if (rules.cells > 0) { + for (unsigned int i = 0; i < rules.cells; i++) { + cells.push_back(pile::cell_factory()); + } + } } // Construct an initial game state from a JSON doc @@ -64,11 +83,6 @@ game_state::game_state(const sol_rules& s_rules, int seed) : } } - // Creates the tableau piles - for (unsigned int i = 0; i < rules.tableau_pile_count; i++) { - tableau_piles.push_back(pile::tableau_factory(rules.build_ord)); - } - // Deal to the tableau piles (row-by-row) unsigned int t = 0; while (!deck.empty()) { @@ -78,20 +92,6 @@ game_state::game_state(const sol_rules& s_rules, int seed) : // Add the randomly generated card to the tableau piles tableau_piles[t++ % rules.tableau_pile_count].place(c); } - - // If there are foundation piles, create the relevant pile vectors - if (rules.foundations) { - for (int i = 0; i < 4; i++) { - foundations.push_back(pile::foundation_factory(pol(i))); - } - } - - // If there are cell piles, create the relevant cell vectors - if (rules.cells > 0) { - for (unsigned int i = 0; i < rules.cells; i++) { - cells.push_back(pile::cell_factory()); - } - } } // Generate a randomly ordered vector of cards diff --git a/src/main/game/sol_rules.cpp b/src/main/game/sol_rules.cpp index 66543de..91b00c1 100644 --- a/src/main/game/sol_rules.cpp +++ b/src/main/game/sol_rules.cpp @@ -5,13 +5,12 @@ #include <string> #include <vector> #include <algorithm> -#include <input-output/log_helper.h> #include "rapidjson/error/en.h" -#include "util/util.h" #include "sol_rules.h" -#include "input-output/sol_preset_types.h" +#include "../util/util.h" +#include "../input-output/sol_preset_types.h" using namespace std; using namespace boost; diff --git a/src/main/input-output/command_line_helper.cpp b/src/main/input-output/command_line_helper.cpp index 49bb300..97751a4 100644 --- a/src/main/input-output/command_line_helper.cpp +++ b/src/main/input-output/command_line_helper.cpp @@ -6,11 +6,11 @@ #include <vector> #include <boost/program_options.hpp> -#include <input-output/sol_preset_types.h> #include "command_line_helper.h" -#include "game/sol_rules.h" -#include "input-output/log_helper.h" +#include "../game/sol_rules.h" +#include "log_helper.h" +#include "sol_preset_types.h" using namespace std; diff --git a/src/main/input-output/deal_parser.cpp b/src/main/input-output/deal_parser.cpp index 3ad973f..fecc7d9 100644 --- a/src/main/input-output/deal_parser.cpp +++ b/src/main/input-output/deal_parser.cpp @@ -24,17 +24,16 @@ void deal_parser::parse_tableau_piles(game_state &gs, const rapidjson::Document& const Value& json_tab_piles = doc["tableau piles"]; assert(json_tab_piles.IsArray()); - for (auto& json_tab : json_tab_piles.GetArray()) { - pile tableau_pile(true, gs.rules.build_ord, pol::ANY_SUIT, false); - - for (auto& json_card : json_tab.GetArray()) { - tableau_pile.place(card(json_card.GetString())); - } + if (gs.tableau_piles.size() != gs.rules.tableau_pile_count) { + util::json_parse_err("Incorrect number of tableau piles"); + } - gs.tableau_piles.push_back(tableau_pile); + for (auto p = std::make_pair(begin(json_tab_piles.GetArray()), begin(gs.tableau_piles)); + p.second != end(gs.tableau_piles); + ++p.first, ++p.second) { - if (gs.tableau_piles.size() != gs.rules.tableau_pile_count) { - util::json_parse_err("Incorrect number of tableau piles"); + for (auto& json_card : p.first->GetArray()) { + p.second->place(card(json_card.GetString())); } } } diff --git a/src/main/input-output/deal_parser.h b/src/main/input-output/deal_parser.h index e8b817f..93d30fc 100644 --- a/src/main/input-output/deal_parser.h +++ b/src/main/input-output/deal_parser.h @@ -11,8 +11,8 @@ #include <rapidjson/document.h> #include <rapidjson/schema.h> -#include "game/card.h" -#include "game/sol_rules.h" +#include "../game/card.h" +#include "../game/sol_rules.h" class game_state; diff --git a/src/main/solver/solver.cpp b/src/main/solver/solver.cpp index 02b9c20..c487c29 100644 --- a/src/main/solver/solver.cpp +++ b/src/main/solver/solver.cpp @@ -7,10 +7,8 @@ #include <iostream> #include <algorithm> -#include <gperftools/profiler.h> - #include "solver.h" -#include "input-output/log_helper.h" +#include "../input-output/log_helper.h" using namespace std; using namespace boost; diff --git a/src/main/solver/solver.h b/src/main/solver/solver.h index 73e5e24..bb5f8cf 100644 --- a/src/main/solver/solver.h +++ b/src/main/solver/solver.h @@ -14,8 +14,8 @@ #include <boost/multi_index/identity.hpp> #include <boost/multi_index/sequenced_index.hpp> -#include "game/game_state.h" -#include "game/sol_rules.h" +#include "../game/game_state.h" +#include "../game/sol_rules.h" class solver { public: diff --git a/src/test/resources/SPTestName.json b/src/test/resources/SPTestName.json new file mode 100644 index 0000000..6d1586c --- /dev/null +++ b/src/test/resources/SPTestName.json @@ -0,0 +1,7 @@ +{ + "tableau piles": [ + ["2S", "AS", "AD"], + ["2D", "2H", "AH"], + ["2C", "AC"] + ] +}
\ No newline at end of file diff --git a/src/test/spanish_patience_test.cpp b/src/test/spanish_patience_test.cpp index f75fc8b..4168193 100644 --- a/src/test/spanish_patience_test.cpp +++ b/src/test/spanish_patience_test.cpp @@ -6,6 +6,10 @@ #include "test_helper.h" +typedef test_helper th; + +const static std::string type = "simple-spanish-patience"; + TEST(SpanishPatience, SPTestName) { - EXPECT_TRUE(test_helper::is_solvable("i", "simple-spanish-patience")); + EXPECT_TRUE(th::is_solvable("SPTestName", type)); } diff --git a/src/test/test_helper.cpp b/src/test/test_helper.cpp index 5e08bc3..2e08829 100644 --- a/src/test/test_helper.cpp +++ b/src/test/test_helper.cpp @@ -2,8 +2,22 @@ // Created by thecharlesblake on 12/26/17. // +#include <rapidjson/document.h> + #include "test_helper.h" +#include "../main/game/game_state.h" +#include "../main/solver/solver.h" +#include "../main/util/util.h" + +using namespace rapidjson; +using namespace std; + +bool test_helper::is_solvable(const std::string& input_file, const std::string& preset_type) { + const Document in_doc = util::get_file_json("resources/" + input_file + ".json"); + const sol_rules rules = sol_rules::from_preset(preset_type); + + game_state gs(rules, in_doc); + solver sol(gs, rules); -bool test_helper::is_solvable(std::string, std::string) { - return false; + return sol.run() ? true : false; } diff --git a/src/test/test_helper.h b/src/test/test_helper.h index 38bdfc0..5b8e755 100644 --- a/src/test/test_helper.h +++ b/src/test/test_helper.h @@ -9,7 +9,7 @@ class test_helper { public: - static bool is_solvable(std::string, std::string); + static bool is_solvable(const std::string&, const std::string&); }; |
