From f907ddd96ae6886b6c541d22c1f44628b64289d4 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Mon, 5 Feb 2018 15:57:39 +0000 Subject: Add foundations removable rule parsing --- src/main/game/sol_rules.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/main/game') diff --git a/src/main/game/sol_rules.h b/src/main/game/sol_rules.h index 067e107..8ebb73d 100644 --- a/src/main/game/sol_rules.h +++ b/src/main/game/sol_rules.h @@ -37,6 +37,7 @@ struct sol_rules { bool hole; bool foundations; bool foundations_init_card; + bool foundations_removable; bool diagonal_deal; uint8_t cells; uint8_t stock_size; -- cgit v1.2.1 From 8dba2d3a176d1381cf9c3ed31192c31a468608f1 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Mon, 5 Feb 2018 15:58:09 +0000 Subject: Add removable foundations logic to legal moves gen --- src/main/game/game_state.legal_moves.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/main/game') diff --git a/src/main/game/game_state.legal_moves.cpp b/src/main/game/game_state.legal_moves.cpp index 3043587..fb08abb 100644 --- a/src/main/game/game_state.legal_moves.cpp +++ b/src/main/game/game_state.legal_moves.cpp @@ -24,6 +24,14 @@ vector game_state::get_legal_moves() const { // Never removes a card from the hole, the waste, or an empty pile if (rem_ref == hole || piles[rem_ref].empty()) continue; + // If the foundations aren't removable, also skip them + if (rules.foundations + && !rules.foundations_removable + && rem_ref >= foundations.front() + && rem_ref <= foundations.back()) { + continue; + } + // Stock cards can only be moved to the waste (assuming there is a waste) if (rules.stock_size > 0 && rem_ref == stock) { if (rules.stock_deal_t == sdt::WASTE) { -- cgit v1.2.1 From e5760f55abea5f2170cba605405cc780b3effd9a Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Wed, 14 Feb 2018 16:42:10 +0000 Subject: Resolve name ambiguity in card class --- src/main/game/card.cpp | 24 ++++++++++++++++-------- src/main/game/card.h | 18 +++++++++--------- 2 files changed, 25 insertions(+), 17 deletions(-) (limited to 'src/main/game') diff --git a/src/main/game/card.cpp b/src/main/game/card.cpp index 271bf73..a19760b 100644 --- a/src/main/game/card.cpp +++ b/src/main/game/card.cpp @@ -11,12 +11,20 @@ using namespace std; using namespace boost; +const card::suit_t card::suit::Clubs = 0; +const card::suit_t card::suit::Hearts = 1; +const card::suit_t card::suit::Spades = 2; +const card::suit_t card::suit::Diamonds = 3; + +const card::colour_t card::colour::Black = 0; +const card::colour_t card::colour::Red = 1; + // A card can either be created using two int values (rank & suit), or // using a string (e.g. "AS") -card::card(suit_t s, rank_t r) : suit(s), rank(r) {} +card::card(suit_t s, rank_t r) : card_suit(s), card_rank(r) {} -card::card(const char* c) : suit(suit_from_str(c)), rank(rank_from_str(c)) {} +card::card(const char* c) : card_suit(suit_from_str(c)), card_rank(rank_from_str(c)) {} card::card() : card(0, 0) {} @@ -44,11 +52,11 @@ card::rank_t card::rank_from_str(const char* c) { } card::suit_t card::get_suit() const { - return suit; + return card_suit; } card::colour_t card::get_colour() const { - switch (suit) { + switch (card_suit) { case card::suit::Spades : case card::suit::Clubs : return card::colour::Black; default : return card::colour::Red; @@ -56,19 +64,19 @@ card::colour_t card::get_colour() const { } card::rank_t card::get_rank() const { - return rank; + return card_rank; } std::string card::to_string() const { string s; - switch(rank) { + switch(card_rank) { case 1 : s += "A"; break; case 11: s += "J"; break; case 12: s += "Q"; break; case 13: s += "K"; break; - default: s += std::to_string(rank); + default: s += std::to_string(card_rank); } - switch(suit) { + switch(card_suit) { case card::suit::Spades : s += "S"; break; case card::suit::Hearts : s += "H"; break; case card::suit::Clubs : s += "C"; break; diff --git a/src/main/game/card.h b/src/main/game/card.h index 74f513d..8d88df8 100644 --- a/src/main/game/card.h +++ b/src/main/game/card.h @@ -16,15 +16,15 @@ public: typedef uint8_t colour_t; struct suit { - static const suit_t Clubs = 0; - static const suit_t Hearts = 1; - static const suit_t Spades = 2; - static const suit_t Diamonds = 3; + static const suit_t Clubs; + static const suit_t Hearts; + static const suit_t Spades; + static const suit_t Diamonds; }; struct colour { - static const colour_t Black = 0; - static const colour_t Red = 1; + static const colour_t Black; + static const colour_t Red; }; const static card divider; @@ -32,7 +32,7 @@ public: // A card can either be created using two int values (rank & suit), or // using a string (e.g. "AS") card(suit_t, rank_t); - explicit card(const char*); + card(const char*); card(); suit_t get_suit() const; @@ -45,8 +45,8 @@ private: static suit_t suit_from_str(const char* c); static rank_t rank_from_str(const char* c); - suit_t suit : 4; - rank_t rank : 4; + suit_t card_suit : 4; + rank_t card_rank : 4; }; bool operator==(const card&, const card&); -- cgit v1.2.1 From 86ce38efc5ad3bf4fe06ef4c515591545e6fe925 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Wed, 14 Feb 2018 16:42:38 +0000 Subject: Update game rep to deal with foundation dominance --- src/main/game/game_state.cpp | 123 ++++++++++++++++++++++++++++++- src/main/game/game_state.h | 10 +++ src/main/game/game_state.legal_moves.cpp | 45 +++++++++++ src/main/game/pile.cpp | 2 + src/main/game/pile.h | 1 + 5 files changed, 177 insertions(+), 4 deletions(-) (limited to 'src/main/game') diff --git a/src/main/game/game_state.cpp b/src/main/game/game_state.cpp index a6186ff..3c92aa4 100644 --- a/src/main/game/game_state.cpp +++ b/src/main/game/game_state.cpp @@ -14,6 +14,7 @@ #include "game_state.h" #include "../input-output/input/json-parsing/deal_parser.h" #include "../input-output/output/state_printer.h" +#include "../input-output/output/log_helper.h" using namespace std; using namespace rapidjson; @@ -40,6 +41,7 @@ game_state::game_state(const sol_rules& s_rules) : rules(s_rules) { for (uint8_t i = 0; i < 4*(rules.two_decks ? 2:1); i++) { piles.emplace_back(); foundations.push_back(static_cast(piles.size() - 1)); + auto_foundation_moves.push_back(true); } } @@ -205,11 +207,18 @@ vector game_state::gen_shuffled_deck(int seed, card::rank_t max_rank, return deck; } +const pile::size_type game_state::move::dominance_flag = pile::max_size_type; + game_state::move::move(pile_ref f, pile_ref t, pile::size_type i) : from(f), to(t), count(i) { assert(i >= 1); } +// Returns true is the move has been flagged as a special 'dominance' move +bool game_state::move::is_dominance() const { + return count == dominance_flag; +} + ///////////////////////// // MODIFYING FUNCTIONS // @@ -222,15 +231,20 @@ void game_state::make_move(const move m) { // Handles special stock-to-tableau-piles move if (rules.stock_deal_t == sdt::TABLEAU_PILES && m.from == stock) { for (pile_ref tab_pr = original_tableau_piles.front(); - tab_pr < original_tableau_piles.front() + m.count; + tab_pr < pile_ref(original_tableau_piles.front() + m.count); tab_pr++) { place_card(tab_pr, take_card(stock)); } } // If this is not a built-pile move - else if (m.count == 1) { + else if (m.count == 1 || m.is_dominance()) { place_card(m.to, take_card(m.from)); - } else { +#ifndef NO_AUTO_FOUNDATIONS + assess_auto_foundation_moves(m.to); +#endif + } + // If this is a built-pile move + else { assert(m.count <= rules.max_rank); // Adds the cards to the 'to' pile for (auto pile_idx = m.count; pile_idx-- > 0;) { @@ -257,8 +271,11 @@ void game_state::undo_move(const move m) { } } // If this is not a built-pile move - else if (m.count == 1) { + else if (m.count == 1 || m.is_dominance()) { place_card(m.from, take_card(m.to)); +#ifndef NO_AUTO_FOUNDATIONS + assess_auto_foundation_moves(m.from); +#endif } else { assert(m.count <= rules.max_rank); // Adds the cards to the 'from' pile @@ -361,6 +378,100 @@ void game_state::eval_pile_order(list& pile_lst, pile_ref changed_pr, #endif } +// Decides which 'auto foundation' booleans should be 'true' currently +void game_state::assess_auto_foundation_moves(pile_ref target_pile) { + // If there are no foundations, or this is not a foundation move, do nothing + if (!rules.foundations + || target_pile < foundations.front() + || target_pile > foundations.back() + || rules.foundations_removable) { + return; + } + + // Turns the 'auto' boolean for the target foundation false + auto_foundation_moves[target_pile - foundations.front()] = false; + + // Repeats the cycle which attempts to turn one of the auto_foundation_move + // bools true for each foundation, until no change is made in a full scan + bool change_made = true; + while (change_made) { + change_made = false; + // Cycles through each of the foundations with a false 'auto' boolean, + // attempting to turn them true + for (card::suit_t suit = 0; suit < 4; suit++) { + if (auto_foundation_moves[suit]) continue; + + pile_ref foundation_ref = *(begin(foundations) + suit); + + // Empty foundations are automatically true + if(piles[foundation_ref].empty()) { + auto_foundation_moves[suit] = true; + // Restarts the loop + change_made = true; + break; + } + card::rank_t foundation_rank = piles[foundation_ref].top_card().get_rank(); + + // Creates the 'reliant' set. These are the cards that rely on the + // foundation's 'next' card to be able to move in the tableau piles + vector reliant_set; + switch (rules.build_pol) { + case pol::SAME_SUIT: + reliant_set.emplace_back(suit, foundation_rank); + break; + case pol::RED_BLACK: + if (suit == card::suit::Clubs || suit == card::suit::Spades) { + reliant_set.emplace_back(card::suit::Hearts, foundation_rank); + reliant_set.emplace_back(card::suit::Diamonds, foundation_rank); + } else { + reliant_set.emplace_back(card::suit::Clubs, foundation_rank); + reliant_set.emplace_back(card::suit::Spades, foundation_rank); + } + break; + case pol::ANY_SUIT: + reliant_set.emplace_back(card::suit::Hearts, foundation_rank); + reliant_set.emplace_back(card::suit::Diamonds, foundation_rank); + reliant_set.emplace_back(card::suit::Clubs, foundation_rank); + reliant_set.emplace_back(card::suit::Spades, foundation_rank); + break; + case pol::NO_BUILD: + break; + } + + // For each card in the reliant set, the foundation can only be + // true if the reliant card is already up, or legally could be put + // up + bool change_auto_foundation = true; + for (card reliant_card : reliant_set) { + pile_ref reliant_foundation = + *(begin(foundations) + reliant_card.get_suit()); + card::rank_t reliant_found_rank = + piles[reliant_foundation].empty() + ? card::rank_t(0) + : piles[reliant_foundation].top_card().get_rank(); + + bool reliant_card_already_up = reliant_found_rank + >= reliant_card.get_rank(); + bool reliant_card_auto_up = + reliant_found_rank == reliant_card.get_rank() - 1 + && auto_foundation_moves[reliant_card.get_suit()]; + + if (!reliant_card_already_up && !reliant_card_auto_up) { + change_auto_foundation = false; + break; + } + } + + if (change_auto_foundation) { + auto_foundation_moves[suit] = true; + // Restarts the loop + change_made = true; + break; + } + } + } +} + //////////////////////// // INSPECT GAME STATE // @@ -408,6 +519,10 @@ bool game_state::is_solved() const { return solved; } +const std::vector& game_state::get_data() const { + return piles; +} + /////////// // PRINT // diff --git a/src/main/game/game_state.h b/src/main/game/game_state.h index 9b0d7b5..2b68e8c 100644 --- a/src/main/game/game_state.h +++ b/src/main/game/game_state.h @@ -11,6 +11,7 @@ #include #include +#include #include "card.h" #include "pile.h" @@ -28,6 +29,9 @@ public: typedef uint8_t pile_ref; struct move { move(pile_ref, pile_ref, pile::size_type = 1); + bool is_dominance() const; + + const static pile::size_type dominance_flag; pile_ref from; pile_ref to; pile::size_type count; }; @@ -49,6 +53,8 @@ public: // Inspects state bool is_solved() const; + const std::vector& get_data() const; + boost::optional get_dominance_move() const; friend std::ostream& operator<< (std::ostream&, const game_state&); @@ -74,6 +80,8 @@ private: void add_empty_built_group_moves(std::vector&, pile_ref, pile_ref, card) const; + void assess_auto_foundation_moves(pile_ref); + // References to piles const sol_rules rules; std::list tableau_piles; @@ -90,6 +98,8 @@ private: std::vector original_cells; std::vector original_reserve; + std::vector auto_foundation_moves; + // The core piles std::vector piles; }; diff --git a/src/main/game/game_state.legal_moves.cpp b/src/main/game/game_state.legal_moves.cpp index fb08abb..36c5554 100644 --- a/src/main/game/game_state.legal_moves.cpp +++ b/src/main/game/game_state.legal_moves.cpp @@ -2,9 +2,12 @@ // Created by thecharlesblake on 1/3/18. // +#include + #include "game_state.h" using namespace std; +using namespace boost; typedef sol_rules::build_policy pol; typedef sol_rules::spaces_policy s_pol; @@ -279,3 +282,45 @@ void game_state::add_empty_built_group_moves(vector& moves, ); } while (piles[rem_ref][card_idx++] != bg_high); } + +///////////////////// +// Dominance Moves // +///////////////////// + +// Returns a dominance move if one is available +optional game_state::get_dominance_move() const { +#ifndef NO_AUTO_FOUNDATIONS + // If there are 2 decks or no foundations, return + if (!rules.foundations || rules.two_decks || rules.foundations_removable) + return none; + + // 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 + if ((pr >= foundations.front() && pr <= foundations.back()) + || (rules.hole && pr == hole) + || (rules.stock_size > 0 && pr == stock) + || (piles[pr].empty())) { + continue; + } + + card c = piles[pr].top_card(); + pile_ref target_foundation = foundations[c.get_suit()]; + + // If the card is the right rank and the auto-move boolean is true, then + // makes the move and restarts the search + 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() && + auto_foundation_moves[c.get_suit()]) { + + return move(pr, target_foundation, move::dominance_flag); + } + } +#endif + + return none; +} diff --git a/src/main/game/pile.cpp b/src/main/game/pile.cpp index 367f7a0..382fa50 100644 --- a/src/main/game/pile.cpp +++ b/src/main/game/pile.cpp @@ -9,6 +9,8 @@ using namespace std; +const pile::size_type pile::max_size_type = 255; + pile::pile(std::vector pv) : pile_vec(pv) { } diff --git a/src/main/game/pile.h b/src/main/game/pile.h index 7257738..654f5be 100644 --- a/src/main/game/pile.h +++ b/src/main/game/pile.h @@ -17,6 +17,7 @@ class pile { friend class cached_game_state; public: typedef uint8_t size_type; + const static size_type max_size_type; pile() = default; pile(std::vector); -- cgit v1.2.1 From 496d7a23cdaa0616b1453d54afb34a9108190f67 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Thu, 15 Feb 2018 12:44:42 +0000 Subject: Add simple auto-found + works w/ removable founds --- src/main/game/game_state.cpp | 119 ++++++++++--------------------- src/main/game/game_state.h | 6 +- src/main/game/game_state.legal_moves.cpp | 38 +++++++--- 3 files changed, 71 insertions(+), 92 deletions(-) (limited to 'src/main/game') diff --git a/src/main/game/game_state.cpp b/src/main/game/game_state.cpp index 3c92aa4..322bfcc 100644 --- a/src/main/game/game_state.cpp +++ b/src/main/game/game_state.cpp @@ -29,7 +29,10 @@ typedef sol_rules::stock_deal_type sdt; // 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) { +game_state::game_state(const sol_rules& s_rules) : rules(s_rules), + stock(255), + waste(255), + hole(255) { // If there is a hole, creates pile if (rules.hole) { piles.emplace_back(); @@ -240,7 +243,7 @@ void game_state::make_move(const move m) { else if (m.count == 1 || m.is_dominance()) { place_card(m.to, take_card(m.from)); #ifndef NO_AUTO_FOUNDATIONS - assess_auto_foundation_moves(m.to); + update_auto_foundation_moves(m.to); #endif } // If this is a built-pile move @@ -274,7 +277,7 @@ void game_state::undo_move(const move m) { else if (m.count == 1 || m.is_dominance()) { place_card(m.from, take_card(m.to)); #ifndef NO_AUTO_FOUNDATIONS - assess_auto_foundation_moves(m.from); + update_auto_foundation_moves(m.from); #endif } else { assert(m.count <= rules.max_rank); @@ -379,97 +382,49 @@ void game_state::eval_pile_order(list& pile_lst, pile_ref changed_pr, } // Decides which 'auto foundation' booleans should be 'true' currently -void game_state::assess_auto_foundation_moves(pile_ref target_pile) { +void game_state::update_auto_foundation_moves(pile_ref target_pile) { // If there are no foundations, or this is not a foundation move, do nothing if (!rules.foundations || target_pile < foundations.front() - || target_pile > foundations.back() - || rules.foundations_removable) { + || target_pile > foundations.back()) { return; } // Turns the 'auto' boolean for the target foundation false - auto_foundation_moves[target_pile - foundations.front()] = false; - - // Repeats the cycle which attempts to turn one of the auto_foundation_move - // bools true for each foundation, until no change is made in a full scan - bool change_made = true; - while (change_made) { - change_made = false; - // Cycles through each of the foundations with a false 'auto' boolean, - // attempting to turn them true - for (card::suit_t suit = 0; suit < 4; suit++) { - if (auto_foundation_moves[suit]) continue; - - pile_ref foundation_ref = *(begin(foundations) + suit); - - // Empty foundations are automatically true - if(piles[foundation_ref].empty()) { - auto_foundation_moves[suit] = true; - // Restarts the loop - change_made = true; - break; - } - card::rank_t foundation_rank = piles[foundation_ref].top_card().get_rank(); - - // Creates the 'reliant' set. These are the cards that rely on the - // foundation's 'next' card to be able to move in the tableau piles - vector reliant_set; - switch (rules.build_pol) { - case pol::SAME_SUIT: - reliant_set.emplace_back(suit, foundation_rank); - break; - case pol::RED_BLACK: - if (suit == card::suit::Clubs || suit == card::suit::Spades) { - reliant_set.emplace_back(card::suit::Hearts, foundation_rank); - reliant_set.emplace_back(card::suit::Diamonds, foundation_rank); - } else { - reliant_set.emplace_back(card::suit::Clubs, foundation_rank); - reliant_set.emplace_back(card::suit::Spades, foundation_rank); - } - break; - case pol::ANY_SUIT: - reliant_set.emplace_back(card::suit::Hearts, foundation_rank); - reliant_set.emplace_back(card::suit::Diamonds, foundation_rank); - reliant_set.emplace_back(card::suit::Clubs, foundation_rank); - reliant_set.emplace_back(card::suit::Spades, foundation_rank); - break; - case pol::NO_BUILD: - break; - } - // For each card in the reliant set, the foundation can only be - // true if the reliant card is already up, or legally could be put - // up - bool change_auto_foundation = true; - for (card reliant_card : reliant_set) { - pile_ref reliant_foundation = - *(begin(foundations) + reliant_card.get_suit()); - card::rank_t reliant_found_rank = - piles[reliant_foundation].empty() - ? card::rank_t(0) - : piles[reliant_foundation].top_card().get_rank(); - - bool reliant_card_already_up = reliant_found_rank - >= reliant_card.get_rank(); - bool reliant_card_auto_up = - reliant_found_rank == reliant_card.get_rank() - 1 - && auto_foundation_moves[reliant_card.get_suit()]; - - if (!reliant_card_already_up && !reliant_card_auto_up) { - change_auto_foundation = false; - break; - } - } + for (pile_ref pr : foundations) { + auto_foundation_moves[pr] = is_valid_auto_foundation_move(pr); + } +} - if (change_auto_foundation) { - auto_foundation_moves[suit] = true; - // Restarts the loop - change_made = true; - break; +bool game_state::is_valid_auto_foundation_move(pile_ref target_pile) const { + if (rules.build_pol == pol::ANY_SUIT || rules.build_pol == pol::RED_BLACK) { + 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 target_card = card(target_suit, target_rank); + + for (pile_ref pr : foundations) { + if (pr == target_pile) continue; + + card::suit_t foundation_suit(pr - foundations.front()); + card::rank_t foundation_rank = piles[pr].empty() ? card::rank_t(0) + : piles[pr].top_card().get_rank(); + card foundation_card = card(foundation_suit, foundation_rank); + int rank_diff = int(target_rank) + - int(foundation_card.get_rank()); + + if (rules.build_pol == pol::RED_BLACK + && foundation_card.get_colour() == target_card.get_colour()) { + if (rank_diff >= 3) { + return false; + } + } else if (rank_diff >= 2) { + return false; } } } + return true; } diff --git a/src/main/game/game_state.h b/src/main/game/game_state.h index 2b68e8c..b403bc7 100644 --- a/src/main/game/game_state.h +++ b/src/main/game/game_state.h @@ -49,7 +49,7 @@ public: void place_card(pile_ref, card); card take_card(pile_ref); - std::vector get_legal_moves() const; + std::vector get_legal_moves(); // Inspects state bool is_solved() const; @@ -79,8 +79,10 @@ private: void add_built_group_move(std::vector&, pile_ref, pile_ref) const; void add_empty_built_group_moves(std::vector&, pile_ref, pile_ref, card) const; + bool dominance_blocks_foundation_move(pile_ref); - void assess_auto_foundation_moves(pile_ref); + void update_auto_foundation_moves(pile_ref); + bool is_valid_auto_foundation_move(pile_ref) const; // References to piles const sol_rules rules; diff --git a/src/main/game/game_state.legal_moves.cpp b/src/main/game/game_state.legal_moves.cpp index 36c5554..c1a87e4 100644 --- a/src/main/game/game_state.legal_moves.cpp +++ b/src/main/game/game_state.legal_moves.cpp @@ -13,7 +13,7 @@ typedef sol_rules::build_policy pol; typedef sol_rules::spaces_policy s_pol; typedef sol_rules::stock_deal_type sdt; -vector game_state::get_legal_moves() const { +vector game_state::get_legal_moves() { // The next legal moves vector moves; @@ -25,14 +25,22 @@ vector game_state::get_legal_moves() const { // 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 || piles[rem_ref].empty()) continue; + if ((rules.hole && rem_ref == hole) || piles[rem_ref].empty()) continue; - // If the foundations aren't removable, also skip them + // If we have a foundations card as the rem_ref if (rules.foundations - && !rules.foundations_removable && rem_ref >= foundations.front() && rem_ref <= foundations.back()) { - continue; + + // If the foundations are removable, checks to see if a dominance + // prevents us from removing from it. Otherwise, skips the pile ref + if (!rules.foundations_removable +#ifndef NO_AUTO_FOUNDATIONS + || dominance_blocks_foundation_move(rem_ref) +#endif + ) { + continue; + } } // Stock cards can only be moved to the waste (assuming there is a waste) @@ -291,7 +299,7 @@ void game_state::add_empty_built_group_moves(vector& moves, optional game_state::get_dominance_move() const { #ifndef NO_AUTO_FOUNDATIONS // If there are 2 decks or no foundations, return - if (!rules.foundations || rules.two_decks || rules.foundations_removable) + if (!rules.foundations || rules.two_decks) return none; // Cycles through the piles and sees if any cards can be automatically moved @@ -309,14 +317,13 @@ optional game_state::get_dominance_move() const { pile_ref target_foundation = foundations[c.get_suit()]; // If the card is the right rank and the auto-move boolean is true, then - // makes the move and restarts the search + // 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() && auto_foundation_moves[c.get_suit()]) { - return move(pr, target_foundation, move::dominance_flag); } } @@ -324,3 +331,18 @@ optional game_state::get_dominance_move() const { return none; } + +// For games where the foundations can be removed from, this dominance blocks +// the foundations being removed from if the card that were to be removed would +// go 'automatically' up +bool game_state::dominance_blocks_foundation_move(pile_ref target_pile) { + assert(!piles[target_pile].empty()); + + card target_card = piles[target_pile].top_card(); + piles[target_pile].take(); + + bool blocked = is_valid_auto_foundation_move(target_pile); + piles[target_pile].place(target_card); + + return blocked; +} -- cgit v1.2.1