aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/game/search-state/game_state.cpp10
-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)21
-rw-r--r--src/main/game/search-state/game_state.h3
-rw-r--r--src/main/game/search-state/game_state.legal_moves.cpp58
-rw-r--r--src/main/input-output/input/sol_preset_types.cpp4
5 files changed, 69 insertions, 27 deletions
diff --git a/src/main/game/search-state/game_state.cpp b/src/main/game/search-state/game_state.cpp
index 78247bf..17fdc29 100644
--- a/src/main/game/search-state/game_state.cpp
+++ b/src/main/game/search-state/game_state.cpp
@@ -263,6 +263,16 @@ 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
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 b2b55b3..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
@@ -9,9 +9,10 @@
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)
@@ -65,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;
@@ -107,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;
diff --git a/src/main/game/search-state/game_state.h b/src/main/game/search-state/game_state.h
index f6fc666..d8d9f12 100644
--- a/src/main/game/search-state/game_state.h
+++ b/src/main/game/search-state/game_state.h
@@ -111,6 +111,7 @@ 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;
@@ -121,6 +122,7 @@ private:
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, bool) const;
bool is_next_legal_card(std::vector<sol_rules::accordion_policy>, card, card) const;
@@ -128,6 +130,7 @@ private:
/* 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);
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 09a32fa..f97814a 100644
--- a/src/main/game/search-state/game_state.legal_moves.cpp
+++ b/src/main/game/search-state/game_state.legal_moves.cpp
@@ -74,9 +74,7 @@ vector<move> game_state::get_legal_moves(move parent_move) {
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);
@@ -87,17 +85,14 @@ 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
+ // Stock-waste to tableau moves
if (rules.stock_size > 0 && rules.stock_deal_t == sdt::WASTE)
add_stock_to_tableau_moves(moves);
+ // Tableau built group moves
switch (rules.move_built_group) {
case sol_rules::built_group_type::YES:
add_built_group_moves(moves);
@@ -115,11 +110,7 @@ vector<move> game_state::get_legal_moves(move parent_move) {
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);
}
}
@@ -132,11 +123,7 @@ 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
@@ -233,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);
+ }
+ }
}
}
@@ -313,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)
@@ -320,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() == rules.foundations_base;
+ return rem_c.get_rank() == foundations_base;
else
- return rem_c.get_rank() == (piles[add_ref].top_card().get_rank() + 1) % rules.max_rank;
+ 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 {
@@ -345,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);
@@ -383,6 +387,7 @@ 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) {
@@ -534,6 +539,13 @@ 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;
+}
///////////////////////
diff --git a/src/main/input-output/input/sol_preset_types.cpp b/src/main/input-output/input/sol_preset_types.cpp
index d3daf40..0aee219 100644
--- a/src/main/input-output/input/sol_preset_types.cpp
+++ b/src/main/input-output/input/sol_preset_types.cpp
@@ -290,7 +290,7 @@ map<string, string> sol_preset_types::mp = {
"redeal": true
},
"reserve": {
- "size": 14,
+ "size": 13,
"stacked": true
}
}
@@ -314,7 +314,7 @@ map<string, string> sol_preset_types::mp = {
"base card": "random"
},
"stock": {
- "size": 1,
+ "size": 6,
"deal count": 3,
"redeal": true
},