aboutsummaryrefslogtreecommitdiff
path: root/src/main/game
diff options
context:
space:
mode:
authorCharlie Blake2018-07-24 16:17:44 +0100
committerGitHub2018-07-24 16:17:44 +0100
commit6ffee36ea973433723359321dfffd43c65febf88 (patch)
treecb3841d736ff353c5d8aea6a4faf81861ef83f5c /src/main/game
parentMerge pull request #77 from thecharlesblake/add-accordion (diff)
parentFix canfield to pass all unit tests (diff)
downloadmetasol-6ffee36ea973433723359321dfffd43c65febf88.tar.gz
metasol-6ffee36ea973433723359321dfffd43c65febf88.zip

Merge pull request #78 from thecharlesblake/add-canfield

Add canfield

Diffstat (limited to 'src/main/game')
-rw-r--r--src/main/game/search-state/game_state.cpp51
-rw-r--r--src/main/game/search-state/game_state.dominance_moves.cpp (renamed from src/main/game/search-state/game_state.auto_foundation_moves.cpp)50
-rw-r--r--src/main/game/search-state/game_state.h12
-rw-r--r--src/main/game/search-state/game_state.legal_moves.cpp133
-rw-r--r--src/main/game/sol_rules.cpp8
-rw-r--r--src/main/game/sol_rules.h21
6 files changed, 207 insertions, 68 deletions
diff --git a/src/main/game/search-state/game_state.cpp b/src/main/game/search-state/game_state.cpp
index 0388d9c..17fdc29 100644
--- a/src/main/game/search-state/game_state.cpp
+++ b/src/main/game/search-state/game_state.cpp
@@ -4,7 +4,6 @@
#include <vector>
#include <ostream>
-#include <random>
#include <algorithm>
#include <functional>
@@ -38,6 +37,7 @@ typedef sol_rules::build_policy pol;
typedef sol_rules::stock_deal_type sdt;
typedef sol_rules::face_up_policy fu;
typedef game_state::streamliner_options sos;
+typedef sol_rules::foundations_init_type fit;
//////////////////
// CONSTRUCTORS //
@@ -48,6 +48,7 @@ typedef game_state::streamliner_options sos;
game_state::game_state(const sol_rules& s_rules, streamliner_options stream_opts_)
: rules(s_rules)
, stream_opts(stream_opts_)
+ , foundations_base(card::rank_t(1))
, stock(255)
, waste(255)
, hole (255) {
@@ -130,7 +131,8 @@ game_state::game_state(const sol_rules& s_rules, const Document& doc, streamline
// Constructs an initial game state from a seed
game_state::game_state(const sol_rules& s_rules, int seed, streamliner_options s_opts)
: game_state(s_rules, s_opts) {
- vector<card> deck = gen_shuffled_deck(seed, rules.max_rank, rules.two_decks);
+ auto rng = mt19937(seed);
+ vector<card> deck = gen_shuffled_deck(rules.max_rank, rules.two_decks, rng);
// If there is a hole, moves the ace of spades to it
if (rules.hole) {
@@ -138,14 +140,30 @@ game_state::game_state(const sol_rules& s_rules, int seed, streamliner_options s
place_card(hole, card("AS"));
}
+ // If the foundation base is random, selects a random rank and suit
+ card::suit_t rand_suit = 0;
+ if (!rules.foundations_base) {
+ boost::random::uniform_int_distribution<card::rank_t> distr_rank(1, rules.max_rank);
+ foundations_base = distr_rank(rng);
+ boost::random::uniform_int_distribution<card::suit_t> distr_suit(0, 3);
+ rand_suit = distr_suit(rng);
+ }
+
// If the foundations begin filled, then fills them
- if (rules.foundations_init_card) {
- for (uint8_t f_idx = 0; f_idx < 4*(rules.two_decks ? 2:1); f_idx++) {
- card c = card(f_idx % uint8_t(4), 1);
+ uint8_t founds_to_fill = 0;
+ switch (rules.foundations_init_cards) {
+ case sol_rules::foundations_init_type::NONE:
+ break;
+ case sol_rules::foundations_init_type::ONE:
+ founds_to_fill = 1; break;
+ case sol_rules::foundations_init_type::ALL:
+ founds_to_fill = static_cast<uint8_t>(4 * (rules.two_decks ? 2 : 1)); break;
+ }
+ for (uint8_t f_idx = 0; f_idx < founds_to_fill; f_idx++) {
+ card c = card((f_idx + rand_suit) % uint8_t(4), foundations_base);
- deck.erase(find(begin(deck), end(deck), c));
- place_card(foundations[f_idx], c);
- }
+ deck.erase(find(begin(deck), end(deck), c));
+ place_card(foundations[(f_idx + rand_suit)], c);
}
// If there is a stock, deals to it and set up a waste pile too
@@ -245,11 +263,21 @@ game_state::game_state(const sol_rules& s_rules,
}
pr++;
}
+
+ // Sets foundations base appropriately
+ if (rules.foundations_present && rules.foundations_base == boost::none) {
+ for (auto f : foundations) {
+ if (!piles[f].empty()) {
+ foundations_base = piles[f].top_card().get_rank();
+ return;
+ }
+ }
+ }
}
// Generates a randomly ordered vector of cards
-vector<card> game_state::gen_shuffled_deck(int seed, card::rank_t max_rank,
- bool two_decks) {
+vector<card> game_state::gen_shuffled_deck(card::rank_t max_rank,
+ bool two_decks, mt19937 rng) {
vector<card> deck;
for (int deck_count = 1; deck_count <= (two_decks ? 2 : 1); deck_count++) {
@@ -262,7 +290,6 @@ vector<card> game_state::gen_shuffled_deck(int seed, card::rank_t max_rank,
assert(deck.size() == pile::size_type(max_rank * (two_decks ? 8 : 4)));
- auto rng = mt19937(seed);
game_state::shuffle(begin(deck), end(deck), rng);
return deck;
}
@@ -613,7 +640,7 @@ bool game_state::is_solved() const {
} else if (rules.sequence_count > 0) {
for (pile::ref i = 0; i < sequences.size() && solved; i++) {
for (pile::ref j = piles[sequences[i]].size(); j-- > 2;) {
- if (!is_next_legal_card(rules.sequence_build_pol, piles[sequences[i]][j-1], piles[sequences[i]][j])) {
+ if (!is_next_legal_card(rules.sequence_build_pol, piles[sequences[i]][j-1], piles[sequences[i]][j], false)) {
solved = false;
break;
}
diff --git a/src/main/game/search-state/game_state.auto_foundation_moves.cpp b/src/main/game/search-state/game_state.dominance_moves.cpp
index b74948a..b7e6e15 100644
--- a/src/main/game/search-state/game_state.auto_foundation_moves.cpp
+++ b/src/main/game/search-state/game_state.dominance_moves.cpp
@@ -3,13 +3,16 @@
//
#include "game_state.h"
+#include "../sol_rules.h"
typedef sol_rules::build_policy pol;
typedef game_state::streamliner_options sos;
+typedef sol_rules::stock_deal_type sdt;
+typedef sol_rules::spaces_policy s_pol;
using std::max;
-
+using boost::optional;
bool game_state::is_valid_auto_foundation_move(pile::ref target_pile) const {
if (rules.foundations_only_comp_piles)
@@ -21,11 +24,12 @@ bool game_state::is_valid_auto_foundation_move(pile::ref target_pile) const {
return true;
card::suit_t target_suit(target_pile - foundations.front());
- card::rank_t target_rank = piles[target_pile].empty()
- ? card::rank_t(0)
- : piles[target_pile].top_card().get_rank();
+ card::rank_t move_up_rank = piles[target_pile].empty()
+ ? card::rank_t(1)
+ : foundation_base_convert(piles[target_pile].top_card().get_rank() + card::rank_t(1));
+
// The card to be moved up
- card move_up_card(target_suit, card::rank_t(target_rank + 1));
+ card move_up_card(target_suit, move_up_rank);
// The max difference between the 'move up' card and the foundations of the
// same colour and the other colour
@@ -36,7 +40,7 @@ bool game_state::is_valid_auto_foundation_move(pile::ref target_pile) const {
card::suit_t s(pr - foundations.front());
card::rank_t r = piles[pr].empty() ? card::rank_t(0)
- : piles[pr].top_card().get_rank();
+ : foundation_base_convert(piles[pr].top_card().get_rank());
card c(s, r);
auto rank_diff = int(move_up_card.get_rank() - r);
@@ -62,8 +66,13 @@ bool game_state::is_valid_auto_foundation_move(pile::ref target_pile) const {
}
// Returns a dominance move if one is available
-boost::optional<move> game_state::get_dominance_move() const {
+optional<move> game_state::get_dominance_move() const {
#ifndef NO_AUTO_FOUNDATIONS
+ if (rules.spaces_pol == s_pol::AUTO_RESERVE_THEN_WASTE) {
+ optional<move> arm = auto_reserve_move();
+ if (arm) return arm;
+ }
+
// If there are 2 decks or no foundations, return
if (!rules.foundations_present || rules.two_decks)
return boost::none;
@@ -71,10 +80,11 @@ boost::optional<move> game_state::get_dominance_move() const {
// Cycles through the piles and sees if any cards can be automatically moved
// to the foundations
for (pile::ref pr = 0; pr < piles.size(); pr++) {
- // Don't move foundation cards, hole or stock cards to the foundations
+ // Don't move foundation cards, hole, waste or stock cards to the foundations
if ((pr >= foundations.front() && pr <= foundations.back())
|| (rules.hole && pr == hole)
|| (rules.stock_size > 0 && pr == stock)
+ || (rules.stock_size > 0 && rules.stock_deal_t == sdt::WASTE && pr == waste)
|| (piles[pr].empty())) {
continue;
}
@@ -85,10 +95,9 @@ boost::optional<move> game_state::get_dominance_move() const {
// If the card is the right rank and the auto-move boolean is true, then
// returns the move
card::rank_t target_rank = piles[target_foundation].empty()
- ? card::rank_t(1) :
- piles[target_foundation].top_card().get_rank()
- + card::rank_t(1);
- if (target_rank == c.get_rank() &&
+ ? card::rank_t(1)
+ : foundation_base_convert(piles[target_foundation].top_card().get_rank() + card::rank_t(1));
+ if (target_rank == foundation_base_convert(c.get_rank()) &&
auto_foundation_moves[c.get_suit()]) {
move m(move::mtype::dominance, pr, target_foundation);
@@ -104,6 +113,17 @@ boost::optional<move> game_state::get_dominance_move() const {
return boost::none;
}
+optional<move> game_state::auto_reserve_move() const {
+ if (rules.spaces_pol == s_pol::AUTO_RESERVE_THEN_WASTE && !piles[reserve.front()].empty()) {
+ for (auto to : tableau_piles) {
+ if (piles[to].empty()) {
+ return move(move::mtype::dominance, reserve.front(), to);
+ }
+ }
+ }
+ return boost::none;
+}
+
bool game_state::is_ordered_pile(pile::ref pr) const {
if (piles[pr].size() != rules.max_rank) return false;
@@ -144,3 +164,9 @@ void game_state::update_auto_foundation_moves(pile::ref target_pile) {
auto_foundation_moves[pr] = is_valid_auto_foundation_move(pr);
}
}
+
+card::rank_t game_state::foundation_base_convert(card::rank_t r) const {
+ card::rank_t s = r - (foundations_base - card::rank_t(1));
+ if (s < 1) s += rules.max_rank;
+ return s;
+}
diff --git a/src/main/game/search-state/game_state.h b/src/main/game/search-state/game_state.h
index cbd72b4..d8d9f12 100644
--- a/src/main/game/search-state/game_state.h
+++ b/src/main/game/search-state/game_state.h
@@ -8,6 +8,7 @@
#include <vector>
#include <list>
#include <string>
+#include <random>
#include <boost/functional/hash.hpp>
#include <boost/optional/optional.hpp>
@@ -62,7 +63,7 @@ private:
/* Constructors (& helper function) */
explicit game_state(const sol_rules&, streamliner_options);
- static std::vector<card> gen_shuffled_deck(int, card::rank_t, bool);
+ static std::vector<card> gen_shuffled_deck(card::rank_t, bool, std::mt19937);
template<class RandomIt, class URBG> static void shuffle(RandomIt, RandomIt, URBG&&);
/* Pile order logic */
@@ -110,30 +111,37 @@ private:
bool is_valid_hole_move(pile::ref) const;
bool is_valid_hole_move(card) const;
+ void add_valid_tableau_moves(std::vector<move>&, pile::ref) const;
void add_built_group_moves(std::vector<move>&) const;
void add_built_group_moves(std::vector<move>&, pile::ref, pile::size_type) const;
+ void add_whole_pile_moves(std::vector<move>&) const;
+ void add_whole_pile_moves(std::vector<move>&, pile::ref, pile::size_type) const;
pile::size_type get_built_group_height(pile::ref) const;
bool is_next_built_group_card(card, card) const;
void add_empty_built_group_moves(std::vector<move>&, pile::ref, pile::ref, pile::size_type, bool) const;
void add_kings_only_built_group_move(std::vector<move>&, pile::ref, pile::ref, pile::size_type, bool) const;
void add_non_empty_built_group_move(std::vector<move>&, pile::ref, pile::ref, pile::size_type, bool) const;
void add_sequence_moves(std::vector<move>&) const;
+ bool tableau_space_and_auto_reserve() const;
- bool is_next_legal_card(sol_rules::build_policy, card, card) const;
+ bool is_next_legal_card(sol_rules::build_policy, card, card, bool) const;
bool is_next_legal_card(std::vector<sol_rules::accordion_policy>, card, card) const;
void turn_face_down_cards(std::vector<move>&) const;
/* Auto-foundation moves */
+ boost::optional<move> auto_reserve_move() const;
bool is_valid_auto_foundation_move(pile::ref) const;
bool is_ordered_pile(pile::ref) const;
bool dominance_blocks_foundation_move(pile::ref);
void update_auto_foundation_moves(pile::ref);
+ card::rank_t foundation_base_convert(card::rank_t) const;
/* Game rules */
const sol_rules rules;
streamliner_options stream_opts;
+ card::rank_t foundations_base;
/* Pile references */
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 e1cbc8e..f97814a 100644
--- a/src/main/game/search-state/game_state.legal_moves.cpp
+++ b/src/main/game/search-state/game_state.legal_moves.cpp
@@ -22,6 +22,7 @@ typedef sol_rules::accordion_policy acc_pol;
typedef sol_rules::stock_deal_type sdt;
typedef sol_rules::face_up_policy fu;
typedef sol_rules::direction dir;
+typedef sol_rules::built_group_type bgt;
////////////////////////////////
// MAIN LEGAL MOVE GEN CYCLE ///
@@ -64,18 +65,16 @@ vector<move> game_state::get_legal_moves(move parent_move) {
if (!piles[r].empty())
moves.emplace_back(move::mtype::regular, r, empty_cell);
- if (rules.stock_size > 0 && rules.stock_deal_t == sdt::WASTE && !piles[stock].empty())
+ if (rules.stock_size > 0 && rules.stock_deal_t == sdt::WASTE)
add_stock_to_cell_move(moves, empty_cell);
}
- // Foundation to tableau moves
+ // Foundation to tableau / empty cell moves
if (rules.foundations_removable) {
for (auto f : foundations) {
if (piles[f].empty() || parent_move.to == f || dominance_blocks_foundation_move(f)) continue;
- for (auto t : tableau_piles)
- if (is_valid_tableau_move(f, t))
- moves.emplace_back(move::mtype::regular, f, t);
+ add_valid_tableau_moves(moves, f);
if (empty_cell != 255)
moves.emplace_back(move::mtype::regular, f, empty_cell);
@@ -86,28 +85,32 @@ vector<move> game_state::get_legal_moves(move parent_move) {
for (auto r : reserve) {
if (piles[r].empty()) continue;
- for (auto t : tableau_piles) {
- if (is_valid_tableau_move(r, t)) {
- moves.emplace_back(move::mtype::regular, r, t);
- }
- }
+ add_valid_tableau_moves(moves, r);
}
- // Stock to tableau moves
- if (rules.stock_size > 0 && rules.stock_deal_t == sdt::WASTE && !piles[stock].empty())
+ // Stock-waste to tableau moves
+ if (rules.stock_size > 0 && rules.stock_deal_t == sdt::WASTE)
add_stock_to_tableau_moves(moves);
- if (rules.move_built_group)
- add_built_group_moves(moves);
+ // Tableau built group moves
+ switch (rules.move_built_group) {
+ case sol_rules::built_group_type::YES:
+ add_built_group_moves(moves);
+ break;
+ case sol_rules::built_group_type::WHOLE_PILE:
+ add_whole_pile_moves(moves);
+ break;
+ case sol_rules::built_group_type::NO:
+ break;
+ }
// Tableau to tableau moves
- for (auto t_from : tableau_piles) {
- if (piles[t_from].empty() || parent_move.to == t_from) continue;
+ // If only whole pile moves are available, doesn't make regular ones
+ if (rules.move_built_group != bgt::WHOLE_PILE) {
+ for (auto t_from : tableau_piles) {
+ if (piles[t_from].empty() || parent_move.to == t_from) continue;
- for (auto t_to : tableau_piles) {
- if (is_valid_tableau_move(t_from, t_to)) {
- moves.emplace_back(move::mtype::regular, t_from, t_to);
- }
+ add_valid_tableau_moves(moves, t_from);
}
}
@@ -120,17 +123,13 @@ vector<move> game_state::get_legal_moves(move parent_move) {
for (auto c : cells) {
if (piles[c].empty() || parent_move.to == c) continue;
- for (auto t : tableau_piles) {
- if (is_valid_tableau_move(c, t)) {
- moves.emplace_back(move::mtype::regular, c, t);
- }
- }
+ add_valid_tableau_moves(moves, c);
}
// Tableau / cells / reserve / stock-waste to hole / foundation moves
if (rules.hole || (rules.foundations_present && !rules.foundations_only_comp_piles)) {
// Stock
- if (rules.stock_size > 0 && rules.stock_deal_t == sdt::WASTE && !piles[stock].empty())
+ if (rules.stock_size > 0 && rules.stock_deal_t == sdt::WASTE)
add_stock_to_hole_foundation_moves(moves);
list<pile::ref> from_piles = tableau_piles;
@@ -187,7 +186,8 @@ set<pair<int8_t, bool>> game_state::generate_k_plus_moves_to_check() const {
set<pair<int8_t, bool>> stock_moves_to_check;
// If the waste isn't empty, adds the move from the top of the current waste
- if (piles[waste].size() != 0) stock_moves_to_check.insert(pair<int8_t, bool>(0, false));
+ if (!piles[waste].empty()) stock_moves_to_check.insert(pair<int8_t, bool>(0, false));
+ else if (piles[stock].empty()) return stock_moves_to_check;
// Adds multiples of deal count (excluding last card)
for (int8_t count = rules.stock_deal_count;
@@ -220,9 +220,14 @@ void game_state::add_stock_to_tableau_moves(std::vector<move>& moves) const {
for (auto k_plus_mv : generate_k_plus_moves_to_check()) {
card from = stock_card_from_count(k_plus_mv.first);
- for (auto t : tableau_piles)
- if (is_valid_tableau_move(from, t))
+ // Obeys the auto-reserve restriction unless the reserve is empty
+ if (!piles[reserve.front()].empty() && tableau_space_and_auto_reserve()) return;
+
+ for (auto t : tableau_piles) {
+ if (is_valid_tableau_move(from, t)) {
moves.emplace_back(move::mtype::stock_k_plus, stock, t, k_plus_mv.first, false, k_plus_mv.second);
+ }
+ }
}
}
@@ -288,7 +293,7 @@ bool game_state::is_valid_tableau_move(const card rem_c,
}
bool game_state::is_next_tableau_card(card a, card b) const {
- return is_next_legal_card(rules.build_pol, a, b);
+ return is_next_legal_card(rules.build_pol, a, b, rules.tableau_wraps);
}
bool game_state::is_valid_foundations_move(const pile::ref rem_ref,
@@ -300,6 +305,8 @@ bool game_state::is_valid_foundations_move(const pile::ref rem_ref,
bool game_state::is_valid_foundations_move(const card rem_c,
const pile::ref add_ref) const {
+ if (piles[add_ref].size() == rules.max_rank) return false;
+
// Checks same suit policy
uint8_t suit_idx = (add_ref - foundations.front()) % uint8_t(4);
if (rem_c.get_suit() != suit_idx)
@@ -307,9 +314,9 @@ bool game_state::is_valid_foundations_move(const card rem_c,
// Checks rank
if (piles[add_ref].empty())
- return rem_c.get_rank() == 1;
+ return rem_c.get_rank() == foundations_base;
else
- return rem_c.get_rank() == piles[add_ref].top_card().get_rank() + 1;
+ return rem_c.get_rank() == (piles[add_ref].top_card().get_rank() % rules.max_rank) + 1;
}
bool game_state::is_valid_hole_move(const pile::ref rem_ref) const {
@@ -332,6 +339,16 @@ bool game_state::is_valid_hole_move(const card c) const {
// BUILT-GROUP MOVE GEN FUNCTIONS //
////////////////////////////////////
+void game_state::add_valid_tableau_moves(std::vector<move>& moves, pile::ref from) const {
+ if (tableau_space_and_auto_reserve()) return;
+
+ for (auto to : tableau_piles) {
+ if (is_valid_tableau_move(from, to)) {
+ moves.emplace_back(move::mtype::regular, from, to);
+ }
+ }
+}
+
void game_state::add_built_group_moves(vector<move>& moves) const {
assert(rules.built_group_pol != pol::NO_BUILD);
@@ -368,6 +385,37 @@ void game_state::add_built_group_moves(vector<move>& moves, pile::ref rem_ref, p
}
}
+void game_state::add_whole_pile_moves(vector<move>& moves) const {
+ assert(rules.built_group_pol != pol::NO_BUILD);
+ if (tableau_space_and_auto_reserve()) return;
+
+ // Cycles through each pile to see if it contains a whole-pile built group
+ for (auto rem_ref : tableau_piles) {
+ auto built_group_height = get_built_group_height(rem_ref);
+
+ if (built_group_height == piles[rem_ref].size()) {
+ add_whole_pile_moves(moves, rem_ref, built_group_height);
+ }
+ }
+}
+
+void game_state::add_whole_pile_moves(vector<move>& moves, pile::ref rem_ref, pile::size_type built_group_height) const {
+ // We have found a built group. Cycles through each pile to see if it can be added
+ for (auto add_ref : tableau_piles) {
+ if (add_ref == rem_ref) continue;
+
+ card bg_high = piles[rem_ref][built_group_height - 1];
+
+ if (piles[add_ref].empty()) {
+ if (rules.spaces_pol == s_pol::ANY || (rules.spaces_pol == s_pol::KINGS && bg_high.get_rank() == 13)) {
+ moves.emplace_back(move::mtype::built_group, rem_ref, add_ref, built_group_height);
+ }
+ } else if (is_next_built_group_card(piles[add_ref].top_card(), bg_high)) {
+ moves.emplace_back(move::mtype::built_group, rem_ref, add_ref, built_group_height);
+ }
+ }
+}
+
// Finds the size of the built group at the top of a pile
pile::size_type game_state::get_built_group_height(pile::ref ref) const {
pile::size_type i = 1;
@@ -379,7 +427,7 @@ pile::size_type game_state::get_built_group_height(pile::ref ref) const {
}
bool game_state::is_next_built_group_card(card a, card b) const {
- return is_next_legal_card(rules.built_group_pol, a, b);
+ return is_next_legal_card(rules.built_group_pol, a, b, rules.tableau_wraps);
}
// Loops through each possible built group move to an empty pile and adds it to the list
@@ -448,7 +496,7 @@ void game_state::add_sequence_moves(std::vector<move>& moves) const {
// Otherwise must agree with left neighbour
else {
card neighbour_card = piles[sequences[space_loc.first]][space_loc.second + 1];
- if (neighbour_card != "AS" && is_next_legal_card(rules.sequence_build_pol, from_card, neighbour_card))
+ if (neighbour_card != "AS" && is_next_legal_card(rules.sequence_build_pol, from_card, neighbour_card, false))
moves.emplace_back(move::mtype::sequence, from_idx, space_idx);
}
}
@@ -462,7 +510,7 @@ void game_state::add_sequence_moves(std::vector<move>& moves) const {
// Otherwise must agree with right neighbour
else {
card neighbour_card = piles[sequences[space_loc.first]][space_loc.second - 1];
- if (neighbour_card != "AS" && is_next_legal_card(rules.sequence_build_pol, neighbour_card, from_card))
+ if (neighbour_card != "AS" && is_next_legal_card(rules.sequence_build_pol, neighbour_card, from_card, false))
moves.emplace_back(move::mtype::sequence, from_idx, space_idx);
}
}
@@ -491,10 +539,17 @@ void game_state::add_accordion_moves(vector<move>& moves) const {
}
}
+// If auto-reserve is enabled and there is a space, returns
+bool game_state::tableau_space_and_auto_reserve() const {
+ if (rules.spaces_pol == s_pol::AUTO_RESERVE_THEN_WASTE)
+ for (auto to : tableau_piles)
+ if (piles[to].empty()) return true;
+ return false;
+}
///////////////////////
-bool game_state::is_next_legal_card(pol p, card a, card b) const {
+bool game_state::is_next_legal_card(pol p, card a, card b, bool wraps) const {
// Checks build pol violations
switch(p) {
case sol_rules::build_policy::SAME_SUIT:
@@ -506,7 +561,11 @@ bool game_state::is_next_legal_card(pol p, card a, card b) const {
default:;
}
// Checks rank
- return b.get_rank() + 1 == a.get_rank();
+ if (wraps) {
+ return (b.get_rank() % rules.max_rank) + 1 == a.get_rank();
+ } else {
+ return b.get_rank() + 1 == a.get_rank();
+ }
}
bool game_state::is_next_legal_card(vector<acc_pol> vp, card a, card b) const {
diff --git a/src/main/game/sol_rules.cpp b/src/main/game/sol_rules.cpp
index 0ea998e..2778241 100644
--- a/src/main/game/sol_rules.cpp
+++ b/src/main/game/sol_rules.cpp
@@ -9,6 +9,8 @@ typedef sol_rules::spaces_policy s_pol;
typedef sol_rules::stock_deal_type sdt;
typedef sol_rules::direction dir;
typedef sol_rules::face_up_policy fu;
+typedef sol_rules::built_group_type bgt;
+typedef sol_rules::foundations_init_type fit;
// Note that the 'default' sol rules are set up by parsing the default json
// rules description. This initialisation is really just for testing purposes.
@@ -16,13 +18,15 @@ sol_rules::sol_rules() :
tableau_pile_count(0),
build_pol(pol::ANY_SUIT),
spaces_pol(s_pol::ANY),
- move_built_group(false),
+ move_built_group(bgt::NO),
built_group_pol(pol::ANY_SUIT),
+ tableau_wraps(false),
two_decks(false),
max_rank(13),
hole(false),
foundations_present(false),
- foundations_init_card(false),
+ foundations_init_cards(fit::NONE),
+ foundations_base(1),
foundations_only_comp_piles(false),
diagonal_deal(false),
cells(0),
diff --git a/src/main/game/sol_rules.h b/src/main/game/sol_rules.h
index 0673771..2384b21 100644
--- a/src/main/game/sol_rules.h
+++ b/src/main/game/sol_rules.h
@@ -7,7 +7,9 @@
#include <string>
#include <vector>
+#include <boost/optional.hpp>
+#include "card.h"
#include "../../../lib/rapidjson/document.h"
struct sol_rules {
@@ -23,7 +25,8 @@ struct sol_rules {
enum class spaces_policy {
NO_BUILD,
KINGS,
- ANY
+ ANY,
+ AUTO_RESERVE_THEN_WASTE
};
enum class accordion_policy {
SAME_RANK,
@@ -44,17 +47,29 @@ struct sol_rules {
RIGHT,
BOTH
};
+ enum class built_group_type {
+ YES,
+ NO,
+ WHOLE_PILE
+ };
+ enum class foundations_init_type {
+ NONE,
+ ONE,
+ ALL
+ };
uint8_t tableau_pile_count;
build_policy build_pol;
spaces_policy spaces_pol;
- bool move_built_group;
+ built_group_type move_built_group;
build_policy built_group_pol;
+ bool tableau_wraps;
bool two_decks;
uint8_t max_rank;
bool hole;
bool foundations_present;
- bool foundations_init_card;
+ foundations_init_type foundations_init_cards;
+ boost::optional<card::rank_t> foundations_base;
bool foundations_removable;
bool foundations_only_comp_piles;
bool diagonal_deal;