diff options
| author | Charlie Blake | 2018-04-05 15:54:20 +0100 |
|---|---|---|
| committer | GitHub | 2018-04-05 15:54:20 +0100 |
| commit | 4c4bf8a2e153b0ead77931285704aa7a0d2b7475 (patch) | |
| tree | 716b8cc644945daaa1d9665f7ffc98a25d4a36d4 /src/main/game/game_state.cpp | |
| parent | Merge pull request #48 from thecharlesblake/wider-testing (diff) | |
| parent | Add cmd line opts to list games and describe rules (diff) | |
| download | metasol-4c4bf8a2e153b0ead77931285704aa7a0d2b7475.tar.gz metasol-4c4bf8a2e153b0ead77931285704aa7a0d2b7475.zip | |
Merge pull request #49 from thecharlesblake/add-more-games
Add more games
Diffstat (limited to 'src/main/game/game_state.cpp')
| -rw-r--r-- | src/main/game/game_state.cpp | 71 |
1 files changed, 55 insertions, 16 deletions
diff --git a/src/main/game/game_state.cpp b/src/main/game/game_state.cpp index 23ba50d..897adf1 100644 --- a/src/main/game/game_state.cpp +++ b/src/main/game/game_state.cpp @@ -228,17 +228,35 @@ bool game_state::move::is_dominance() const { ///////////////////////// void game_state::make_move(const move m) { - // Handles special stock-to-tableau-piles move - if (rules.stock_deal_t == sdt::TABLEAU_PILES && m.from == stock) { - assert(m.from == stock); - assert(m.to == 255 ); - - for (pile_ref tab_pr = original_tableau_piles.front(); - tab_pr < pile_ref(original_tableau_piles.front() + m.count); - tab_pr++) { - place_card(tab_pr, take_card(stock)); + // Handles stock moves + if (m.from == stock) { + // Handles special stock-to-tableau-piles move + if (rules.stock_deal_t == sdt::TABLEAU_PILES) { + assert(m.from == stock); + assert(m.to == 255); + + for (pile_ref tab_pr = original_tableau_piles.front(); + tab_pr < pile_ref(original_tableau_piles.front() + m.count); + tab_pr++) { + place_card(tab_pr, take_card(stock)); + } + } + // Handles stock-to-waste moves + else { + if (piles[stock].empty()) { + // Re-deal waste back to stock + while (!piles[waste].empty()) { + place_card(stock, take_card(waste)); + } + } else { + assert(m.to == waste); + for (int i = 0; i < m.count; i++) { + place_card(waste, take_card(stock)); + } + } } } + // If this is not a built-pile move else if (m.count == 1 || m.is_dominance()) { assert(m.from < piles.size()); @@ -249,6 +267,7 @@ void game_state::make_move(const move m) { update_auto_foundation_moves(m.to); #endif } + // If this is a built-pile move else { assert(m.from < piles.size() ); @@ -270,14 +289,31 @@ void game_state::make_move(const move m) { void game_state::undo_move(const move m) { assert(m.from < piles.size()); - // Handles special stock-to-tableau-piles move - if (rules.stock_deal_t == sdt::TABLEAU_PILES && m.from == stock) { - for (pile_ref tab_pr = original_tableau_piles.front() + m.count; - tab_pr-- > original_tableau_piles.front(); - ) { - place_card(stock, take_card(tab_pr)); + // Handles stock moves + if (m.from == stock) { + // Handles special stock-to-tableau-piles move + if (rules.stock_deal_t == sdt::TABLEAU_PILES) { + for (pile_ref tab_pr = original_tableau_piles.front() + m.count; + tab_pr-- > original_tableau_piles.front(); + ) { + place_card(stock, take_card(tab_pr)); + } + } + // Handles stock-to-waste moves + else { + if (piles[waste].empty()) { + // Re-deal waste back to stock + while (!piles[stock].empty()) { + place_card(waste, take_card(stock)); + } + } else { + for (int i = 0; i < m.count; i++) { + place_card(stock, take_card(waste)); + } + } } } + // If this is not a built-pile move else if (m.count == 1 || m.is_dominance()) { assert(m.to < piles.size()); @@ -285,7 +321,10 @@ void game_state::undo_move(const move m) { #ifndef NO_AUTO_FOUNDATIONS update_auto_foundation_moves(m.from); #endif - } else { + } + + // If this is a built-pile move + else { assert(m.to < piles.size()); assert(m.count <= rules.max_rank); // Adds the cards to the 'from' pile |
