diff options
Diffstat (limited to 'src/main/game/search-state')
| -rw-r--r-- | src/main/game/search-state/game_state.auto_foundation_moves.cpp | 6 | ||||
| -rw-r--r-- | src/main/game/search-state/game_state.cpp | 24 | ||||
| -rw-r--r-- | src/main/game/search-state/game_state.legal_moves.cpp | 7 |
3 files changed, 23 insertions, 14 deletions
diff --git a/src/main/game/search-state/game_state.auto_foundation_moves.cpp b/src/main/game/search-state/game_state.auto_foundation_moves.cpp index 43f8911..b74948a 100644 --- a/src/main/game/search-state/game_state.auto_foundation_moves.cpp +++ b/src/main/game/search-state/game_state.auto_foundation_moves.cpp @@ -12,7 +12,7 @@ using std::max; bool game_state::is_valid_auto_foundation_move(pile::ref target_pile) const { - if (rules.foundations_comp_piles) + if (rules.foundations_only_comp_piles) return false; else if ( stream_opts == sos::AUTO_FOUNDATIONS || stream_opts == sos::BOTH @@ -65,7 +65,7 @@ bool game_state::is_valid_auto_foundation_move(pile::ref target_pile) const { boost::optional<move> 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) + if (!rules.foundations_present || rules.two_decks) return boost::none; // Cycles through the piles and sees if any cards can be automatically moved @@ -132,7 +132,7 @@ bool game_state::dominance_blocks_foundation_move(pile::ref target_pile) { // Decides which 'auto foundation' booleans should be 'true' currently 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 + if (!rules.foundations_present || target_pile < foundations.front() || target_pile > foundations.back()) { return; diff --git a/src/main/game/search-state/game_state.cpp b/src/main/game/search-state/game_state.cpp index a1d60bf..169c96e 100644 --- a/src/main/game/search-state/game_state.cpp +++ b/src/main/game/search-state/game_state.cpp @@ -58,7 +58,7 @@ game_state::game_state(const sol_rules& s_rules, streamliner_options stream_opts } // If there are foundation piles, creates the relevant pile vectors - if (rules.foundations) { + if (rules.foundations_present) { for (uint8_t i = 0; i < 4*(rules.two_decks ? 2:1); i++) { piles.emplace_back(); foundations.push_back(static_cast<pile::ref>(piles.size() - 1)); @@ -389,9 +389,8 @@ void game_state::make_stock_k_plus_move(const move m) { // Index of the card to be moved auto count = m.count % (piles[stock].size() + piles[waste].size()); - for (int i = 0; i <= count; i++) { - if (i < count) place_card(waste, take_card(stock)); - else place_card(m.to, take_card(stock)); + for (int i = 0; i < count; i++) { + place_card(waste, take_card(stock)); if (rules.stock_redeal) { // If the stock is empty, flips it @@ -402,6 +401,11 @@ void game_state::make_stock_k_plus_move(const move m) { } } + place_card(m.to, take_card(stock)); + if (rules.stock_redeal && piles[stock].empty() && count != 0) + while (!piles[waste].empty()) + place_card(stock, take_card(waste)); + #ifndef NDEBUG auto sz_after = piles[stock].size() + piles[waste].size(); assert(sz_before == sz_after + 1); @@ -420,7 +424,12 @@ void game_state::undo_stock_k_plus_move(move m) { auto count = m.count % (piles[stock].size() + piles[waste].size() + 1); - for (int i = count; i >= 0; i--) { + if (rules.stock_redeal && piles[waste].empty() && count != 0) + while (!piles[stock].empty()) + place_card(waste, take_card(stock)); + place_card(stock, take_card(m.to)); + + for (int i = 0; i < count; i++) { if (rules.stock_redeal) { // If the waste is empty, flips it // (invariant: no search state has an empty stock if rules.stock_size > 0 && rules.stock_redeal) @@ -429,8 +438,7 @@ void game_state::undo_stock_k_plus_move(move m) { place_card(waste, take_card(stock)); } - if (i < count) place_card(stock, take_card(waste)); - else place_card(stock, take_card(m.to )); + place_card(stock, take_card(waste)); } #ifndef NDEBUG @@ -514,7 +522,7 @@ bool game_state::is_solved() const { solved = piles[hole].size() == rules.max_rank * 4 * (rules.two_decks ? 2 : 1); } else { - assert(rules.foundations); + assert(rules.foundations_present); for (auto f : foundations) { if (piles[f].size() != rules.max_rank) { solved = false; 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 7dd75d8..f68df0b 100644 --- a/src/main/game/search-state/game_state.legal_moves.cpp +++ b/src/main/game/search-state/game_state.legal_moves.cpp @@ -119,7 +119,7 @@ vector<move> game_state::get_legal_moves(move parent_move) { } // Tableau / cells / reserve / stock-waste to hole / foundation moves - if (rules.hole || (rules.foundations && !rules.foundations_comp_piles)) { + 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()) add_stock_to_hole_foundation_moves(moves); @@ -139,7 +139,7 @@ vector<move> game_state::get_legal_moves(move parent_move) { } } - if (rules.foundations_comp_piles) // i.e. Spider-type winning condition + if (rules.foundations_only_comp_piles) // i.e. Spider-type winning condition add_foundation_complete_piles_moves(moves); if (rules.tableau_pile_count > 0 && rules.face_up != fu::ALL) @@ -190,6 +190,7 @@ set<pile::size_type> game_state::generate_stock_moves_to_check() const { for (auto i = piles[stock].size() - 1 + rules.stock_deal_count; i < piles[stock].size() + stock_waste_sz - 1; i += rules.stock_deal_count) { + if (i == stock_waste_sz - 1) continue; // No need to add top of waste card as it is a regular move stock_moves_to_check.insert(static_cast<pile::size_type>(i % stock_waste_sz)); } } @@ -308,7 +309,7 @@ bool game_state::is_next_tableau_card(card a, card b) const { bool game_state::is_valid_foundations_move(const pile::ref rem_ref, const pile::ref add_ref) const { - if (rem_ref == add_ref || rules.foundations_comp_piles) return false; + if (rem_ref == add_ref || rules.foundations_only_comp_piles) return false; return is_valid_foundations_move(piles[rem_ref].top_card(), add_ref); } |
