aboutsummaryrefslogtreecommitdiff
path: root/src/main/game/game_state.legal_moves.cpp
diff options
context:
space:
mode:
authorthecharlesblake2018-02-24 11:10:54 +0000
committerthecharlesblake2018-02-24 11:10:54 +0000
commit5c168518766037ef7129cc28febdd03afb8e11ee (patch)
tree4983a8a72065056e693b418510e64abdbdb0f2b7 /src/main/game/game_state.legal_moves.cpp
parentAdd NO_CARD_JUST_MOVED optimisation flag to CMAKE (diff)
downloadmetasol-5c168518766037ef7129cc28febdd03afb8e11ee.tar.gz
metasol-5c168518766037ef7129cc28febdd03afb8e11ee.zip

Add card just moved optimisation to game logic

Diffstat (limited to 'src/main/game/game_state.legal_moves.cpp')
-rw-r--r--src/main/game/game_state.legal_moves.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/main/game/game_state.legal_moves.cpp b/src/main/game/game_state.legal_moves.cpp
index c1a87e4..99431e3 100644
--- a/src/main/game/game_state.legal_moves.cpp
+++ b/src/main/game/game_state.legal_moves.cpp
@@ -13,7 +13,11 @@ 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() {
+vector<game_state::move> game_state::get_legal_moves(
+#ifndef NO_CARD_JUST_MOVED
+ move parent_move
+#endif
+) {
// The next legal moves
vector<move> moves;
@@ -24,8 +28,16 @@ vector<game_state::move> game_state::get_legal_moves() {
// 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 ((rules.hole && rem_ref == hole) || piles[rem_ref].empty()) continue;
+ // Never removes a card from the hole, an empty pile, or the pile we
+ // 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
if (rules.foundations
@@ -100,7 +112,7 @@ game_state::move game_state::get_stock_tableau_move() const {
: piles[stock].size();
assert(stock_moves > 0 && stock_moves <= piles[stock].size());
- return {stock, 0, stock_moves};
+ return {stock, 255, stock_moves};
}
// If a tableau pile is empty and the space policy is