diff options
Diffstat (limited to 'src/main')
| -rw-r--r-- | src/main/game/game_state.cpp | 65 | ||||
| -rw-r--r-- | src/main/game/game_state.h | 6 | ||||
| -rw-r--r-- | src/main/game/game_state.legal_moves.cpp | 8 | ||||
| -rw-r--r-- | src/main/input-output/input/sol_preset_types.cpp | 14 | ||||
| -rw-r--r-- | src/main/solver/solver.cpp | 4 |
5 files changed, 56 insertions, 41 deletions
diff --git a/src/main/game/game_state.cpp b/src/main/game/game_state.cpp index 50b8f19..9c32b4f 100644 --- a/src/main/game/game_state.cpp +++ b/src/main/game/game_state.cpp @@ -450,33 +450,48 @@ void game_state::update_auto_foundation_moves(pile_ref target_pile) { } 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; - } +#ifndef AUTO_FOUNDATIONS_STREAMLINER + if (rules.build_pol == pol::NO_BUILD || rules.build_pol == pol::SAME_SUIT) +#endif + 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(); + // The card to be moved up + card move_up_card(target_suit, card::rank_t(target_rank + 1)); + + // The max difference between the 'move up' card and the foundations of the + // same colour and the other colour + int same_col_rank_diff = 0; + int other_col_rank_diff = 0; + for (pile_ref pr : foundations) { + if (pr == target_pile) continue; + + card::suit_t s(pr - foundations.front()); + card::rank_t r = piles[pr].empty() ? card::rank_t(0) + : piles[pr].top_card().get_rank(); + card c(s, r); + + auto rank_diff = int(move_up_card.get_rank() - r); + if (move_up_card.get_colour() == c.get_colour()) { + same_col_rank_diff = rank_diff; + } else { + other_col_rank_diff = max(other_col_rank_diff, rank_diff); } } - return true; + + bool other_col_within_1 = other_col_rank_diff <= 1; + bool other_col_within_2 = other_col_rank_diff <= 2; + bool same_col_within_3 = same_col_rank_diff <= 3; + + if (rules.build_pol == pol::RED_BLACK) { + return other_col_within_1 || (other_col_within_2 && same_col_within_3); + } else { + assert(rules.build_pol == pol::ANY_SUIT); + return other_col_within_2; + } } diff --git a/src/main/game/game_state.h b/src/main/game/game_state.h index 0be07ae..1e527ea 100644 --- a/src/main/game/game_state.h +++ b/src/main/game/game_state.h @@ -50,11 +50,7 @@ public: void place_card(pile_ref, card); card take_card(pile_ref); - std::vector<move> get_legal_moves( -#ifndef NO_CARD_JUST_MOVED - move = move(255, 255, 255) -#endif - ); + std::vector<move> get_legal_moves(move = move(255, 255, 255)); // Inspects state bool is_solved() const; diff --git a/src/main/game/game_state.legal_moves.cpp b/src/main/game/game_state.legal_moves.cpp index 24304a1..5a49ec9 100644 --- a/src/main/game/game_state.legal_moves.cpp +++ b/src/main/game/game_state.legal_moves.cpp @@ -13,11 +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::move> game_state::get_legal_moves( -#ifndef NO_CARD_JUST_MOVED - move parent_move -#endif -) { +vector<game_state::move> game_state::get_legal_moves(move parent_move) { // The next legal moves vector<move> moves; @@ -45,11 +41,9 @@ vector<game_state::move> game_state::get_legal_moves( // just moved a card to if ((rules.hole && rem_ref == hole) || piles[rem_ref].empty() -#ifndef NO_CARD_JUST_MOVED || (rem_ref == parent_move.to && parent_move.count <= 1 && parent_move.from != stock) -#endif ) continue; // If we have a foundations card as the rem_ref diff --git a/src/main/input-output/input/sol_preset_types.cpp b/src/main/input-output/input/sol_preset_types.cpp index 08f79e7..e4d06a3 100644 --- a/src/main/input-output/input/sol_preset_types.cpp +++ b/src/main/input-output/input/sol_preset_types.cpp @@ -623,6 +623,20 @@ map<string, string> sol_preset_types::mp = { R"( { "tableau piles": { + "build policy": "same-suit", + "spaces policy": "kings" + }, + "cells": 8 +} +)" + + }, + { + "eight-off-any-card-spaces", + + R"( +{ + "tableau piles": { "build policy": "same-suit" }, "cells": 8 diff --git a/src/main/solver/solver.cpp b/src/main/solver/solver.cpp index 60b1351..884b2e5 100644 --- a/src/main/solver/solver.cpp +++ b/src/main/solver/solver.cpp @@ -118,11 +118,7 @@ void solver::add_children(std::vector<game_state::move>& moves) { } vector<game_state::move> solver::get_next_moves() { -#ifndef NO_CARD_JUST_MOVED return state.get_legal_moves(current_node->move); -#else - return state.get_legal_moves(); -#endif } void solver::add_child(game_state::move move) { |
