From 1b56ea2cc3ca6ab1058391d8205fefbdeb202c12 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Fri, 9 Mar 2018 00:36:07 +0000 Subject: Add new solution type logic --- src/main/game/game_state.cpp | 20 +++++++++++++++++++- src/main/game/game_state.h | 1 + 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/game/game_state.cpp b/src/main/game/game_state.cpp index 6067c15..52f35f8 100644 --- a/src/main/game/game_state.cpp +++ b/src/main/game/game_state.cpp @@ -440,10 +440,18 @@ bool game_state::is_valid_auto_foundation_move(pile_ref target_pile) const { bool game_state::is_solved() const { bool solved = true; - if (rules.hole) { + if (rules.solve_ord_tab) { + for (pile_ref tab_pr : tableau_piles) { + if (is_ordered_pile(tab_pr)) { + solved = false; + break; + } + } + } else if (rules.hole) { solved = piles[hole].size() == rules.max_rank * 4 * (rules.two_decks ? 2 : 1); } else { + assert(rules.foundations); for (auto f : foundations) { if (piles[f].size() != rules.max_rank) { solved = false; @@ -480,6 +488,16 @@ bool game_state::is_solved() const { return solved; } +bool game_state::is_ordered_pile(pile_ref pr) const { + if (piles[pr].size() != rules.max_rank) return false; + + card::suit_t s = piles[pr][0].get_suit(); + for (card::rank_t r = rules.max_rank; r >= 1; r--) { + if (piles[pr][r] != card(s, r)) return false; + } + return true; +} + const std::vector& game_state::get_data() const { return piles; } diff --git a/src/main/game/game_state.h b/src/main/game/game_state.h index aeabc10..409fee9 100644 --- a/src/main/game/game_state.h +++ b/src/main/game/game_state.h @@ -84,6 +84,7 @@ private: void add_empty_built_group_moves(std::vector&, pile_ref, pile_ref, card) const; bool dominance_blocks_foundation_move(pile_ref); + bool is_ordered_pile(pile_ref) const; void update_auto_foundation_moves(pile_ref); bool is_valid_auto_foundation_move(pile_ref) const; -- cgit v1.2.1