aboutsummaryrefslogtreecommitdiff
path: root/src/main/game
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/game')
-rw-r--r--src/main/game/game_state.cpp65
-rw-r--r--src/main/game/game_state.h6
-rw-r--r--src/main/game/game_state.legal_moves.cpp8
3 files changed, 42 insertions, 37 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