aboutsummaryrefslogtreecommitdiff
path: root/src/main/game
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/game')
-rw-r--r--src/main/game/card.cpp10
-rw-r--r--src/main/game/card.h2
-rw-r--r--src/main/game/game_state.cpp246
-rw-r--r--src/main/game/game_state.h33
-rw-r--r--src/main/game/pile.cpp110
-rw-r--r--src/main/game/pile.h34
-rw-r--r--src/main/game/sol_rules.cpp35
-rw-r--r--src/main/game/sol_rules.h32
8 files changed, 219 insertions, 283 deletions
diff --git a/src/main/game/card.cpp b/src/main/game/card.cpp
index 4ea9991..0f9809d 100644
--- a/src/main/game/card.cpp
+++ b/src/main/game/card.cpp
@@ -55,6 +55,16 @@ card::rank_t card::get_rank() const {
return rank;
}
+card::suit_t card::to_suit(uint8_t v) {
+ switch (v) {
+ case 0: return suit_t::Clubs;
+ case 1: return suit_t::Diamonds;
+ case 2: return suit_t::Hearts;
+ case 3: return suit_t::Spades;
+ default: assert(false); return suit_t::Clubs;
+ }
+}
+
bool operator==(const card& l, const card& r) {
return l.get_rank() == r.get_rank() && l.get_suit() == r.get_suit();
}
diff --git a/src/main/game/card.h b/src/main/game/card.h
index cc5a993..9c43350 100644
--- a/src/main/game/card.h
+++ b/src/main/game/card.h
@@ -14,6 +14,8 @@ public:
enum class colour_t {Black, Red};
typedef uint8_t rank_t;
+ static suit_t to_suit(uint8_t);
+
// A card can either be created using two int values (rank & suit), or
// using a string (e.g. "AS")
card(suit_t, rank_t);
diff --git a/src/main/game/game_state.cpp b/src/main/game/game_state.cpp
index 319bf5d..14867f8 100644
--- a/src/main/game/game_state.cpp
+++ b/src/main/game/game_state.cpp
@@ -22,62 +22,53 @@ typedef sol_rules::build_order ord;
typedef sol_rules::build_policy pol;
typedef sol_rules::spaces_policy s_pol;
+
+//////////////////
+// CONSTRUCTORS //
+//////////////////
+
// A private constructor used by both of the public ones. Initializes all of the
// piles and pile refs specified by the rules
game_state::game_state(const sol_rules& s_rules) :
- rules(s_rules) {
+ rules(s_rules),
+ stock(PILE_REF_MAX),
+ waste(PILE_REF_MAX),
+ hole(PILE_REF_MAX) {
- // Creates the tableau piles
- for (uint8_t i = 0; i < rules.tableau_pile_count; i++) {
- piles.push_back(pile::tableau_factory(rules.build_ord, rules.build_pol,
- rules.spaces_pol));
- tableau_piles.push_back(static_cast<pile_ref>(piles.size() - 1));
+ // If there is a hole, creates pile
+ if (rules.hole) {
+ piles.emplace_back();
+ hole = static_cast<pile_ref>(piles.size() - 1);
}
// If there are foundation piles, creates the relevant pile vectors
if (rules.foundations) {
for (uint8_t i = 0; i < 4; i++) {
- piles.push_back(pile::foundation_factory(pol(i)));
+ piles.emplace_back();
foundations.push_back(static_cast<pile_ref>(piles.size() - 1));
}
}
- // If there are cell piles, creates the relevant cell vectors
- if (rules.cells > 0) {
- for (uint8_t i = 0; i < rules.cells; i++) {
- piles.push_back(pile::cell_factory());
- cells.push_back(static_cast<pile_ref>(piles.size() - 1));
- }
- }
-
- // If there is a reserve, creates a reserve pile
- if (rules.reserve_size > 0) {
- piles.push_back(pile::reserve_factory());
- reserve = static_cast<pile_ref>(piles.size() - 1);
- }
-
// If there is a stock & waste, creates piles
if (rules.stock_size > 0) {
- piles.push_back(pile::stock_factory());
+ piles.emplace_back();
stock = static_cast<pile_ref>(piles.size() - 1);
- piles.push_back(pile::waste_factory());
+ piles.emplace_back();
waste = static_cast<pile_ref>(piles.size() - 1);
}
- if (rules.hole) {
- piles.push_back(pile::hole_factory(s_rules.max_rank));
- hole = static_cast<pile_ref>(piles.size() - 1);
+ // If there are cell piles, creates the relevant cell vectors
+ if (rules.cells > 0) {
+ for (uint8_t i = 0; i < rules.cells; i++) {
+ piles.emplace_back();
+ cells.push_back(static_cast<pile_ref>(piles.size() - 1));
+ }
}
- for (pile_ref pr = 0; pr < piles.size(); pr++) {
- if (rules.stock_size > 0 && pr == waste) continue;
-
- if (piles[pr].can_remove()) {
- removable_piles.emplace_back(pr);
- }
- if (piles[pr].get_build_order() != ord::NO_BUILD) {
- addable_piles.emplace_back(pr);
- }
+ // Creates the tableau piles
+ for (uint8_t i = 0; i < rules.tableau_pile_count; i++) {
+ piles.emplace_back();
+ tableau_piles.push_back(static_cast<pile_ref>(piles.size() - 1));
}
}
@@ -96,7 +87,7 @@ game_state::game_state(const sol_rules& s_rules, int seed) :
// If there is a hole, moves the ace of spades to it
if (rules.hole) {
deck.erase(find(begin(deck), end(deck), card("AS")));
- piles[hole].place(card("AS"));
+ piles[hole].place("AS");
}
// If there is a stock, deals to it and set up a waste pile too
@@ -107,14 +98,6 @@ game_state::game_state(const sol_rules& s_rules, int seed) :
}
}
- // If there is a reserve, deals to it
- if (rules.reserve_size > 0) {
- for (unsigned int i = 0; i < rules.reserve_size; i++) {
- piles[reserve].place(deck.back());
- deck.pop_back();
- }
- }
-
// Deals to the tableau piles (row-by-row)
for (int t = 0; !deck.empty(); t++) {
card c = deck.back();
@@ -147,16 +130,16 @@ vector<card> game_state::gen_shuffled_deck(int seed, int max_rank = 13) {
card::suit_t s;
switch ((*i) / max_rank) {
case 0 : s = card::suit_t::Clubs;
- break;
+ break;
case 1 : s = card::suit_t::Diamonds;
- break;
+ break;
case 2 : s = card::suit_t::Hearts;
- break;
+ break;
case 3 : s = card::suit_t::Spades;
- break;
+ break;
default : assert(false);
- s = card::suit_t::Clubs;
- break;
+ s = card::suit_t::Clubs;
+ break;
}
deck.emplace_back(card(s, r));
@@ -165,6 +148,11 @@ vector<card> game_state::gen_shuffled_deck(int seed, int max_rank = 13) {
return deck;
}
+
+/////////////////////////
+// MODIFYING FUNCTIONS //
+/////////////////////////
+
void game_state::make_move(const move m) {
piles[m.second].place(piles[m.first].take());
}
@@ -173,33 +161,140 @@ void game_state::undo_move(const move m) {
piles[m.first].place(piles[m.second].take());
}
+
+///////////////////////////
+// LEGAL MOVE GENERATION //
+///////////////////////////
+
vector<game_state::move> game_state::get_legal_moves() const {
- // The next legal states
+ // The next legal moves
vector<move> moves;
- // Dealing from the stock to the waste
- if (rules.stock_size > 0 && !piles[stock].empty()) {
- moves.emplace_back(stock, waste);
- }
+ // Cycles through each pile which we may be able to remove a card from
+ for (pile_ref rem_ref = 0; rem_ref < piles.size(); rem_ref++) {
+ // Never removes a card from the hole, the waste, or an empty pile
+ if (rem_ref == hole
+ || rem_ref == waste
+ || piles[rem_ref].empty()) continue;
+
+ // Stock cards can only be moved to the waste
+ if (stock != PILE_REF_MAX && rem_ref == stock) {
+ moves.emplace_back(stock, waste);
+ continue;
+ }
- // Moving from and to the 'can remove' and 'can add' piles
- // Note traversal order. Solver evaluates backwards, so we reverse traversal
- // order of removable piles, but not addable. This moves from tableau piles
- // to foundations first if possible
- for (auto rem_it = removable_piles.rbegin(); rem_it != removable_piles.rend(); ++rem_it) {
- if (piles[*rem_it].empty()) continue;
+ // For each tableau pile, check if moving from the rem pile is a valid
+ // tableau move according to the rules
+ for (auto add_ref : tableau_piles) {
+ if (is_valid_tableau_move(rem_ref, add_ref)) {
+ moves.emplace_back(rem_ref, add_ref);
+ }
+ }
- for (const pile_ref add_pile : addable_piles) {
- if (add_pile != *rem_it &&
- piles[add_pile].can_place(piles[*rem_it].top_card())) {
- moves.emplace_back(*rem_it, add_pile);
+ // Any card can be moved to a cell, so long as the cell isn't full
+ for (auto add_ref : cells) {
+ if (add_ref != rem_ref && piles[add_ref].empty()) {
+ moves.emplace_back(rem_ref, add_ref);
}
}
+
+ // Any card can be added to the waste
+ if (waste != PILE_REF_MAX && waste != rem_ref) {
+ moves.emplace_back(rem_ref, waste);
+ }
+
+ // For each foundation pile, check if moving from the rem pile is a valid
+ // move according to the rules
+ for (auto add_ref : foundations) {
+ if (is_valid_foundations_move(rem_ref, add_ref)) {
+ moves.emplace_back(rem_ref, add_ref);
+ }
+ }
+
+ // Does the same for the hole
+ if (hole != PILE_REF_MAX && is_valid_hole_move(rem_ref)) {
+ moves.emplace_back(rem_ref, hole);
+ }
}
return moves;
}
+// If a tableau pile is empty and the space policy is
+// no-build, do not add. Otherwise any card with the right
+// suit/rank can be moved to a tableau
+bool game_state::is_valid_tableau_move(const pile_ref rem_ref,
+ const pile_ref add_ref) const {
+ if (rem_ref == add_ref) return false;
+
+ else if (rules.build_pol == pol::NO_BUILD) return false;
+
+ else if (piles[add_ref].empty()) {
+ return rules.spaces_pol == s_pol::ANY;
+ }
+
+ card rem_c = piles[rem_ref].top_card();
+ card add_c = piles[add_ref].top_card();
+
+ // Checks violation of same suit policy
+ if (rules.build_pol == pol::SAME_SUIT
+ && rem_c.get_suit() != add_c.get_suit()) {
+ return false;
+ }
+
+ // Checks violation of red-black suit policy
+ else if (rules.build_pol == pol::RED_BLACK
+ && rem_c.get_colour() == add_c.get_colour()) {
+ return false;
+ }
+
+ // Checks rank
+ else if (rules.build_ord == ord::DESCENDING
+ && rem_c.get_rank() + 1 != add_c.get_rank()) {
+ return false;
+ } else if (rules.build_ord == ord::ASCENDING
+ && rem_c.get_rank() - 1 != add_c.get_rank()) {
+ return false;
+ } else {
+ return true;
+ }
+}
+
+bool game_state::is_valid_foundations_move(const pile_ref rem_ref,
+ const pile_ref add_ref) const {
+ if (rem_ref == add_ref) return false;
+
+ card rem_c = piles[rem_ref].top_card();
+
+ // Checks violation of same suit policy
+ if (rem_c.get_suit() != card::to_suit(add_ref - foundations.front())) {
+ return false;
+ }
+
+ // Checks rank
+ else {
+ card::rank_t add_rank = piles[add_ref].empty()
+ ? card::rank_t(0)
+ : piles[add_ref].top_card().get_rank();
+ return rem_c.get_rank() - 1 == add_rank;
+ }
+}
+
+bool game_state::is_valid_hole_move(const pile_ref rem_ref) const {
+ if (rem_ref == hole) return false;
+ card::rank_t rank = piles[rem_ref].top_card().get_rank();
+ card::rank_t hole_rank = piles[hole].top_card().get_rank();
+ return rank + 1 == hole_rank
+ || rank - 1 == hole_rank
+ || (rank == rules.max_rank && hole_rank == 1)
+ || (rank == 1 && hole_rank == rules.max_rank);
+}
+
+
+////////////////////////
+// INSPECT GAME STATE //
+////////////////////////
+
bool game_state::is_solved() const {
for (auto f : foundations) {
if (piles[f].size() != rules.max_rank) {
@@ -214,6 +309,11 @@ const vector<pile>& game_state::get_data() const {
return piles;
}
+
+//////////////
+// PRINTING //
+//////////////
+
ostream& game_state::print(ostream& stream) const {
if (rules.foundations) {
print_header(stream, "Foundations");
@@ -223,10 +323,6 @@ ostream& game_state::print(ostream& stream) const {
print_header(stream, "Cells");
print_piles(stream, cells);
}
- if (rules.reserve_size > 0) {
- print_header(stream, "Reserve");
- print_pile(stream, reserve);
- }
if (rules.tableau_pile_count > 0) {
print_header(stream, "Tableau Piles");
print_piles(stream, tableau_piles);
@@ -307,14 +403,19 @@ void game_state::print_top_of_pile(ostream& stream, const pile_ref pile_r) const
bool operator==(const game_state& a, const game_state& b) {
return a.tableau_piles == b.tableau_piles
- && a.foundations == b.foundations
- && a.hole == b.hole;
+ && a.foundations == b.foundations
+ && a.hole == b.hole;
}
ostream& operator <<(ostream& stream, const game_state& gs) {
return gs.print(stream);
}
+
+////////////////////
+// HASH FUNCTIONS //
+////////////////////
+
size_t hash_value(game_state const& gs) {
size_t seed = 0;
@@ -328,9 +429,6 @@ size_t hash_value(game_state const& gs) {
hash_combine(seed, gs.tableau_piles);
}
- if (gs.rules.reserve_size > 0) {
- hash_combine(seed, gs.piles[gs.reserve]);
- }
if (gs.rules.stock_size > 0) {
hash_combine(seed, gs.piles[gs.stock]);
hash_combine(seed, gs.piles[gs.waste]);
diff --git a/src/main/game/game_state.h b/src/main/game/game_state.h
index 8adc9d6..28d849e 100644
--- a/src/main/game/game_state.h
+++ b/src/main/game/game_state.h
@@ -5,7 +5,8 @@
#ifndef SOLVITAIRE_GAME_STATE_H
#define SOLVITAIRE_GAME_STATE_H
-#define NULL_MOVE (game_state::move(255, 255))
+#define NULL_MOVE (game_state::move(PILE_REF_MAX, PILE_REF_MAX))
+#define PILE_REF_MAX (255)
#include <vector>
#include <ostream>
@@ -15,28 +16,35 @@
#include <boost/functional/hash.hpp>
#include "card.h"
-#include "sol_rules.h"
#include "pile.h"
+#include "sol_rules.h"
class deal_parser;
class game_state {
friend class deal_parser;
public:
+ // Defines types
typedef uint8_t pile_ref;
typedef std::pair<pile_ref, pile_ref> move;
- // Create a game state representation from a JSON doc
+ // Constructors
+ // Creates a game state representation from a JSON doc
game_state(const sol_rules&, const rapidjson::Document&);
- // Do the same from a 'rules' object
+ // Does the same from a 'rules' object
game_state(const sol_rules&, int seed);
+ // Alters state
void make_move(move);
void undo_move(move);
+
std::vector<move> get_legal_moves() const;
+
+ // Inspects state
bool is_solved() const;
const std::vector<pile>& get_data() const;
+ // Prints
std::ostream& print(std::ostream&) const;
friend bool operator==(const game_state&, const game_state&);
@@ -47,26 +55,31 @@ public:
private:
static std::vector<card> gen_shuffled_deck(int, int);
+ // Private constructor
explicit game_state(const sol_rules&);
+ // Used in get_legal_moves()
+ bool is_valid_tableau_move(pile_ref, pile_ref) const;
+ bool is_valid_foundations_move(pile_ref, pile_ref) const;
+ bool is_valid_hole_move(pile_ref) const;
+
+ // Prints
void print_header(std::ostream&, const char*) const;
void print_piles(std::ostream&, const std::vector<pile_ref>&) const;
void print_pile(std::ostream&, pile_ref) const;
void print_top_of_piles(std::ostream&, const std::vector<pile_ref>&) const;
void print_top_of_pile(std::ostream&, pile_ref) const;
+ // References to piles
sol_rules rules;
- std::vector<pile_ref> foundations;
- std::vector<pile_ref> cells;
std::vector<pile_ref> tableau_piles;
- pile_ref reserve;
+ std::vector<pile_ref> cells;
pile_ref stock;
pile_ref waste;
+ std::vector<pile_ref> foundations;
pile_ref hole;
- std::vector<pile_ref> addable_piles;
- std::vector<pile_ref> removable_piles;
-
+ // The core piles
std::vector<pile> piles;
};
diff --git a/src/main/game/pile.cpp b/src/main/game/pile.cpp
index 2b97591..3b53950 100644
--- a/src/main/game/pile.cpp
+++ b/src/main/game/pile.cpp
@@ -12,114 +12,11 @@
using namespace std;
using namespace boost;
-typedef sol_rules::build_order ord;
-typedef sol_rules::build_policy pol;
-typedef sol_rules::spaces_policy s_pol;
-
-////////////
-// Static //
-////////////
-
-pile pile::tableau_factory(ord o, pol p, s_pol sp) {
- return pile(o, p, sp);
-}
-pile pile::cell_factory() {
- return pile(ord::SINGLE_CARD, pol::N_A);
-}
-pile pile::reserve_factory() {
- return pile(ord::NO_BUILD, pol::N_A);
-}
-pile pile::stock_factory() {
- return pile(ord::NO_BUILD, pol::N_A);
-}
-pile pile::waste_factory() {
- return pile(ord::NO_BUILD, pol::N_A);
-}
-pile pile::foundation_factory(pol p) {
- return pile(ord::ASCENDING, p);
-}
-pile pile::hole_factory(int max_rank) {
- return pile(ord::BOTH, pol::ANY_SUIT, s_pol::ANY, false, true, max_rank);
-}
-
-////////////////
-// Non-static //
-////////////////
-
-pile::pile(ord bo, pol bp, s_pol sp, bool r, bool l, int mr) :
- build_order(bo),
- build_policy(bp),
- spaces_policy(sp),
- removable(r),
- build_order_loops(l),
- max_rank(mr) {
-}
-
-bool pile::can_place(const card c) const {
- if (build_order == ord::ANY) {
- return true;
- } else if (build_order == ord::NO_BUILD) {
- return false;
- } else if (build_order == ord::SINGLE_CARD) {
- return empty();
- }
-
- if (empty()) {
- if (spaces_policy == s_pol::NO_BUILD) {
- return false;
- }
- if (sol_rules::is_suit(build_policy)) {
- return c.get_suit() == sol_rules::suit_val(build_policy)
- && c.get_rank() == 1;
- } else {
- return true;
- }
- }
-
- card top_c = top_card();
-
- // Checks violation of same suit policy
- if (build_policy == pol::SAME_SUIT && c.get_suit() != top_c.get_suit()) {
- return false;
- }
- // Checks violation of specific suit policy
- if (sol_rules::is_suit(build_policy) && c.get_suit()
- != sol_rules::suit_val(build_policy)) {
- return false;
- }
- // Checks violation of red-black suit policy
- if (build_policy == pol::RED_BLACK && c.get_colour() == top_c.get_colour()) {
- return false;
- }
-
- int tc_r = top_c.get_rank();
- int comp_r = c.get_rank();
-
- if (build_order == ord::ASCENDING) {
- return one_lt(tc_r, comp_r);
- } else if (build_order == ord::DESCENDING) {
- return one_lt(comp_r, tc_r);
- } else if (build_order == ord::BOTH) {
- return one_lt(tc_r, comp_r) || one_lt(comp_r, tc_r);
- } else {
- return false;
- }
-}
-
-bool pile::one_lt(int a, int b) const {
- return (a == b - 1) || (build_order_loops && a == max_rank && b == 1);
-}
-
-
-
card pile::top_card() const {
+ assert(!empty());
return pile_vec.back();
}
-bool pile::can_remove() const {
- return removable;
-}
-
bool pile::empty() const {
return pile_vec.empty();
}
@@ -128,10 +25,6 @@ uint8_t pile::size() const {
return static_cast<uint8_t>(pile_vec.size());
}
-ord pile::get_build_order() const {
- return build_order;
-}
-
card& pile::operator[] (vector<card>::size_type i) {
return pile_vec[i];
}
@@ -139,7 +32,6 @@ card pile::operator[] (vector<card>::size_type i) const {
return pile_vec[i];
}
-
void pile::place(const card c) {
pile_vec.emplace_back(c);
}
diff --git a/src/main/game/pile.h b/src/main/game/pile.h
index a064693..a51e0f4 100644
--- a/src/main/game/pile.h
+++ b/src/main/game/pile.h
@@ -12,34 +12,13 @@
class pile {
public:
- // Factory methods
- static pile tableau_factory(sol_rules::build_order, sol_rules::build_policy,
- sol_rules::spaces_policy);
- static pile cell_factory();
- static pile reserve_factory();
- static pile stock_factory();
- static pile waste_factory();
- static pile foundation_factory(sol_rules::build_policy);
- static pile hole_factory(int);
-
- // Constructors
- pile(sol_rules::build_order bo = sol_rules::build_order::DESCENDING,
- sol_rules::build_policy bp = sol_rules::build_policy::ANY_SUIT,
- sol_rules::spaces_policy sp = sol_rules::spaces_policy::ANY,
- bool removable = true,
- bool loops = false,
- int max_rank = 13);
-
// Inspect
- bool can_place(const card) const;
- bool can_remove() const;
card top_card() const;
bool empty() const;
uint8_t size() const;
- sol_rules::build_order get_build_order() const;
// Modify
- void place(const card);
+ void place(card);
card take();
void clear();
@@ -49,18 +28,7 @@ public:
friend bool operator==(const pile&, const pile&);
friend std::size_t hash_value(pile const&);
-
private:
- bool one_lt(int, int) const;
-
- // const pile properties
- const sol_rules::build_order build_order;
- const sol_rules::build_policy build_policy;
- const sol_rules::spaces_policy spaces_policy;
- const bool removable;
- const bool build_order_loops;
- const int max_rank;
-
// Underlying vector
std::vector<card> pile_vec;
};
diff --git a/src/main/game/sol_rules.cpp b/src/main/game/sol_rules.cpp
index 87d556f..a1567f7 100644
--- a/src/main/game/sol_rules.cpp
+++ b/src/main/game/sol_rules.cpp
@@ -22,25 +22,6 @@ using namespace rapidjson;
typedef sol_rules::build_policy pol;
-bool sol_rules::is_suit(pol bp) {
- switch (bp) {
- case pol::CLUBS :
- case pol::DIAMONDS :
- case pol::HEARTS :
- case pol::SPADES : return true;
- default : return false;
- }
-}
-card::suit_t sol_rules::suit_val(pol bp) {
- switch (bp) {
- case pol::CLUBS : return card::suit_t::Clubs;
- case pol::DIAMONDS : return card::suit_t::Diamonds;
- case pol::HEARTS : return card::suit_t::Hearts;
- case pol::SPADES : return card::suit_t::Spades;
- default: assert(false); return card::suit_t::Spades;
- }
-}
-
const sol_rules sol_rules::from_file(const string rules_file) {
sol_rules sr = get_default();
Document d = util::get_file_json(rules_file);
@@ -96,8 +77,8 @@ void sol_rules::modify_sol_rules(sol_rules& sr, Document& d) {
if (d["tableau piles"]["build order"].IsString()) {
string bo_str = d["tableau piles"]["build order"].GetString();
- if (bo_str == "no-build") {
- sr.build_ord = build_order::NO_BUILD;
+ if (bo_str == "ascending") {
+ sr.build_ord = build_order::ASCENDING;
} else if (bo_str == "descending") {
sr.build_ord = build_order::DESCENDING;
} else {
@@ -117,6 +98,10 @@ void sol_rules::modify_sol_rules(sol_rules& sr, Document& d) {
sr.build_pol = build_policy::ANY_SUIT;
} else if (bp_str == "red-black") {
sr.build_pol = build_policy::RED_BLACK;
+ } else if (bp_str == "same-suit") {
+ sr.build_pol = build_policy::SAME_SUIT;
+ } else if (bp_str == "no-build") {
+ sr.build_pol = build_policy::NO_BUILD;
} else {
util::json_parse_err("[tableau piles][build policy] is invalid");
}
@@ -180,14 +165,6 @@ void sol_rules::modify_sol_rules(sol_rules& sr, Document& d) {
}
}
- if (d.HasMember("reserve size")) {
- if (d["reserve size"].IsInt()) {
- sr.reserve_size = static_cast<uint8_t>(d["reserve size"].GetInt());
- } else {
- util::json_parse_err("[reserve size] must be an integer");
- }
- }
-
if (d.HasMember("stock size")) {
if (d["stock size"].IsInt()) {
sr.stock_size = static_cast<uint8_t>(d["stock size"].GetInt());
diff --git a/src/main/game/sol_rules.h b/src/main/game/sol_rules.h
index 96c10d5..3d4995d 100644
--- a/src/main/game/sol_rules.h
+++ b/src/main/game/sol_rules.h
@@ -15,42 +15,22 @@
class sol_rules {
public:
- enum class valid_sol {
- BLACK_HOLE,
- SIMPLE_BLACK_HOLE,
- SPANISH_PATIENCE,
- SIMPLE_SPANISH_PATIENCE,
- FREE_CELL,
- SIMPLE_FREE_CELL,
- CANFIELD,
- SIMPLE_CANFIELD
- };
+ // Tableau policies
enum class build_order {
- NO_BUILD,
DESCENDING,
- ASCENDING,
- BOTH,
- SINGLE_CARD,
- ANY
+ ASCENDING
};
enum class build_policy {
- CLUBS,
- DIAMONDS,
- HEARTS,
- SPADES,
- ANY_SUIT,
+ NO_BUILD,
SAME_SUIT,
RED_BLACK,
- N_A
+ ANY_SUIT
};
enum class spaces_policy {
NO_BUILD,
ANY
};
- static bool is_suit(build_policy);
- static card::suit_t suit_val(build_policy);
-
static const sol_rules from_preset(std::string);
static const sol_rules from_file(std::string);
@@ -62,15 +42,11 @@ public:
bool hole;
bool foundations;
uint8_t cells;
- uint8_t reserve_size;
uint8_t stock_size;
private:
static sol_rules get_default();
static void modify_sol_rules(sol_rules&, rapidjson::Document&);
- static void parse_err(const std::string&);
-
- static valid_sol valid_sol_enum(const std::string&);
};
#endif //SOLVITAIRE_SOL_RULES_H