aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorthecharlesblake2017-12-27 00:04:32 +0000
committerthecharlesblake2017-12-27 00:04:32 +0000
commitf8931f348ef456d9fac78b5cadad280f81dfcfc6 (patch)
treeb3df3f6bda5dfd0c6e7bfdeefc62a1eacd6295f4 /src/main
parentAdd basic outline for spanish patience testing (diff)
downloadmetasol-f8931f348ef456d9fac78b5cadad280f81dfcfc6.tar.gz
metasol-f8931f348ef456d9fac78b5cadad280f81dfcfc6.zip

First sp test working

Diffstat (limited to 'src/main')
-rw-r--r--src/main/game/game_state.cpp38
-rw-r--r--src/main/game/sol_rules.cpp5
-rw-r--r--src/main/input-output/command_line_helper.cpp6
-rw-r--r--src/main/input-output/deal_parser.cpp17
-rw-r--r--src/main/input-output/deal_parser.h4
-rw-r--r--src/main/solver/solver.cpp4
-rw-r--r--src/main/solver/solver.h4
7 files changed, 37 insertions, 41 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: