From 1ffa7dcf0c8df73d5b2affe8066c1cbeb324538e Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Fri, 5 Jan 2018 18:03:29 +0000 Subject: Add diagonal deal to game setup (somerset) --- src/main/game/game_state.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src/main') 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(); + } } } -- cgit v1.2.1