diff options
| author | thecharlesblake | 2018-01-05 18:03:29 +0000 |
|---|---|---|
| committer | thecharlesblake | 2018-01-05 18:03:29 +0000 |
| commit | 1ffa7dcf0c8df73d5b2affe8066c1cbeb324538e (patch) | |
| tree | 424f3e612cb4be311c25c4bca1b9bc4196064a13 /src/main/game | |
| parent | Add diagonal deal to rules parser (somerset) (diff) | |
| download | metasol-1ffa7dcf0c8df73d5b2affe8066c1cbeb324538e.tar.gz metasol-1ffa7dcf0c8df73d5b2affe8066c1cbeb324538e.zip | |
Add diagonal deal to game setup (somerset)
Diffstat (limited to 'src/main/game')
| -rw-r--r-- | src/main/game/game_state.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/main/game/game_state.cpp b/src/main/game/game_state.cpp index 8da5bac..83b9672 100644 --- a/src/main/game/game_state.cpp +++ b/src/main/game/game_state.cpp @@ -132,11 +132,26 @@ game_state::game_state(const sol_rules& s_rules, int seed) : // Deals to the tableau piles (row-by-row) for (int t = 0; !deck.empty(); t++) { card c = deck.back(); - deck.pop_back(); // Add the randomly generated card to the tableau piles - pile_ref tableau_pile = tableau_piles[t % tableau_piles.size()]; - piles[tableau_pile].place(c); + auto p = t % tableau_piles.size(); + + // If we are doing a diagonal deal, each row should have one fewer card. + // Leftover cards are dealt normally in full rows. + auto row_idx = t / tableau_piles.size(); + if (rules.diagonal_deal && row_idx < tableau_piles.size()) { + p = tableau_piles.size()-p-1; + pile_ref tableau_pile = tableau_piles[p]; + + if (p >= row_idx) { + piles[tableau_pile].place(c); + deck.pop_back(); + } + } else { + pile_ref tableau_pile = tableau_piles[p]; + piles[tableau_pile].place(c); + deck.pop_back(); + } } } |
