From df6b4405801f762cc536ed441c673e4bd1675620 Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Sun, 15 Jul 2018 01:16:38 +0100 Subject: Add accordion move making --- src/main/game/search-state/game_state.cpp | 32 ++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'src/main/game/search-state/game_state.cpp') diff --git a/src/main/game/search-state/game_state.cpp b/src/main/game/search-state/game_state.cpp index b1a8e5e..0388d9c 100644 --- a/src/main/game/search-state/game_state.cpp +++ b/src/main/game/search-state/game_state.cpp @@ -184,8 +184,8 @@ game_state::game_state(const sol_rules& s_rules, int seed, streamliner_options s // Deals to the accordion if (rules.accordion_size > 0) { - for (unsigned int i = 0; i < rules.accordion_size; i++) { - place_card(accordion[i], deck.back()); + for (auto pr : accordion) { + place_card(pr, deck.back()); deck.pop_back(); } } @@ -305,6 +305,9 @@ void game_state::make_move(const move m) { case move::mtype::sequence: make_sequence_move(m); break; + case move::mtype::accordion: + make_accordion_move(m); + break; case move::mtype::null: assert(false); break; @@ -333,6 +336,9 @@ void game_state::undo_move(const move m) { case move::mtype::sequence: undo_sequence_move(m); break; + case move::mtype::accordion: + undo_accordion_move(m); + break; case move::mtype::null: assert(false); break; @@ -377,10 +383,8 @@ void game_state::undo_regular_move(const move m) { } void game_state::make_built_group_move(move m) { - assert(rules.move_built_group); 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;) { @@ -400,9 +404,7 @@ void game_state::make_built_group_move(move m) { } void game_state::undo_built_group_move(move m) { - assert(rules.move_built_group); assert(m.to < piles.size()); - assert(m.count <= rules.max_rank); if (m.reveal_move) { assert(!piles[m.from].empty()); @@ -540,6 +542,16 @@ void game_state::undo_sequence_move(const move m) { piles[from_seq_ref][from_card_idx] = to_card; } +void game_state::make_accordion_move(move m) { + make_built_group_move(m); + accordion.remove(m.from); +} + +void game_state::undo_accordion_move(move m) { + accordion.insert(upper_bound(begin(accordion), end(accordion), m.from), m.from); + undo_built_group_move(m); +} + // Places a card on a pile and if it is on a tableau, cell or reserve pile, // reorders the pile refs so that the largest pile is first void game_state::place_card(pile::ref pr, card c) { @@ -595,9 +607,9 @@ bool game_state::is_solved() const { } else if (rules.foundations_present) { for (auto f : foundations) { if (piles[f].size() != rules.max_rank) { - solved = false; - } -} + solved = false; + } + } } else if (rules.sequence_count > 0) { for (pile::ref i = 0; i < sequences.size() && solved; i++) { for (pile::ref j = piles[sequences[i]].size(); j-- > 2;) { @@ -608,6 +620,8 @@ bool game_state::is_solved() const { } if (piles[sequences[i]].top_card() != "AS") solved = false; } + } else if (rules.accordion_size > 0) { + return accordion.size() == 1; } else { assert(false); } -- cgit v1.2.1