aboutsummaryrefslogtreecommitdiff
path: root/src/main/game/game_state.legal_moves.cpp
diff options
context:
space:
mode:
authorthecharlesblake2018-02-14 16:42:38 +0000
committerthecharlesblake2018-02-14 16:59:07 +0000
commit86ce38efc5ad3bf4fe06ef4c515591545e6fe925 (patch)
tree538d77e74fef34fb460326875e9b861401f4b3e8 /src/main/game/game_state.legal_moves.cpp
parentResolve name ambiguity in card class (diff)
downloadmetasol-86ce38efc5ad3bf4fe06ef4c515591545e6fe925.tar.gz
metasol-86ce38efc5ad3bf4fe06ef4c515591545e6fe925.zip

Update game rep to deal with foundation dominance

Diffstat (limited to 'src/main/game/game_state.legal_moves.cpp')
-rw-r--r--src/main/game/game_state.legal_moves.cpp45
1 files changed, 45 insertions, 0 deletions
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 <boost/optional.hpp>
+
#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<move>& moves,
);
} while (piles[rem_ref][card_idx++] != bg_high);
}
+
+/////////////////////
+// Dominance Moves //
+/////////////////////
+
+// Returns a dominance move if one is available
+optional<game_state::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 || 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;
+}