diff options
| author | Charlie Blake | 2018-02-24 11:12:45 +0000 |
|---|---|---|
| committer | GitHub | 2018-02-24 11:12:45 +0000 |
| commit | 2db3586f42af5174a14e8a6f693334f3f4f75e14 (patch) | |
| tree | 4983a8a72065056e693b418510e64abdbdb0f2b7 /src/main/game | |
| parent | Merge pull request #40 from thecharlesblake/test-optimisations (diff) | |
| parent | Add card just moved optimisation to game logic (diff) | |
| download | metasol-2db3586f42af5174a14e8a6f693334f3f4f75e14.tar.gz metasol-2db3586f42af5174a14e8a6f693334f3f4f75e14.zip | |
Merge pull request #41 from thecharlesblake/profile-improve
Profile improve
Diffstat (limited to 'src/main/game')
| -rw-r--r-- | src/main/game/game_state.cpp | 12 | ||||
| -rw-r--r-- | src/main/game/game_state.h | 6 | ||||
| -rw-r--r-- | src/main/game/game_state.legal_moves.cpp | 20 |
3 files changed, 30 insertions, 8 deletions
diff --git a/src/main/game/game_state.cpp b/src/main/game/game_state.cpp index 322bfcc..6067c15 100644 --- a/src/main/game/game_state.cpp +++ b/src/main/game/game_state.cpp @@ -228,11 +228,11 @@ bool game_state::move::is_dominance() const { ///////////////////////// void game_state::make_move(const move m) { - assert(m.from < piles.size()); - assert(m.to < piles.size()); - // Handles special stock-to-tableau-piles move if (rules.stock_deal_t == sdt::TABLEAU_PILES && m.from == stock) { + assert(m.from == stock); + assert(m.count == 255 ); + for (pile_ref tab_pr = original_tableau_piles.front(); tab_pr < pile_ref(original_tableau_piles.front() + m.count); tab_pr++) { @@ -241,6 +241,9 @@ void game_state::make_move(const move m) { } // If this is not a built-pile move else if (m.count == 1 || m.is_dominance()) { + assert(m.from < piles.size()); + assert(m.to < piles.size()); + place_card(m.to, take_card(m.from)); #ifndef NO_AUTO_FOUNDATIONS update_auto_foundation_moves(m.to); @@ -248,7 +251,10 @@ void game_state::make_move(const move m) { } // If this is a built-pile move else { + assert(m.from < piles.size() ); + assert(m.to < piles.size() ); assert(m.count <= rules.max_rank); + // Adds the cards to the 'to' pile for (auto pile_idx = m.count; pile_idx-- > 0;) { place_card(m.to, piles[m.from][pile_idx]); diff --git a/src/main/game/game_state.h b/src/main/game/game_state.h index b403bc7..aeabc10 100644 --- a/src/main/game/game_state.h +++ b/src/main/game/game_state.h @@ -49,7 +49,11 @@ public: void place_card(pile_ref, card); card take_card(pile_ref); - std::vector<move> get_legal_moves(); + std::vector<move> get_legal_moves( +#ifndef NO_CARD_JUST_MOVED + move +#endif + ); // 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 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 |
