From 28c5a79425fa12f9466e27385404f429f76f7524 Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Thu, 19 Jul 2018 11:06:38 +0100 Subject: Update rules so new schema works w/ existing games --- src/main/game/search-state/game_state.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (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 0388d9c..10c8e20 100644 --- a/src/main/game/search-state/game_state.cpp +++ b/src/main/game/search-state/game_state.cpp @@ -38,6 +38,7 @@ typedef sol_rules::build_policy pol; typedef sol_rules::stock_deal_type sdt; typedef sol_rules::face_up_policy fu; typedef game_state::streamliner_options sos; +typedef sol_rules::foundations_init_type fit; ////////////////// // CONSTRUCTORS // @@ -139,7 +140,7 @@ game_state::game_state(const sol_rules& s_rules, int seed, streamliner_options s } // If the foundations begin filled, then fills them - if (rules.foundations_init_card) { + if (rules.foundations_init_cards == fit::ALL) { for (uint8_t f_idx = 0; f_idx < 4*(rules.two_decks ? 2:1); f_idx++) { card c = card(f_idx % uint8_t(4), 1); -- cgit v1.2.1 From 2775a9ba0ef4e698acd0c0d32179d6a1e404297a Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Thu, 19 Jul 2018 16:16:39 +0100 Subject: Add parsing of new rules --- src/main/game/search-state/game_state.cpp | 1 + 1 file changed, 1 insertion(+) (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 10c8e20..26910a1 100644 --- a/src/main/game/search-state/game_state.cpp +++ b/src/main/game/search-state/game_state.cpp @@ -49,6 +49,7 @@ typedef sol_rules::foundations_init_type fit; game_state::game_state(const sol_rules& s_rules, streamliner_options stream_opts_) : rules(s_rules) , stream_opts(stream_opts_) + , foundation_base(card::rank_t(0)) , stock(255) , waste(255) , hole (255) { -- cgit v1.2.1 From 5333895e0519c4425136bb299fedb5c19c5d4c0a Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Thu, 19 Jul 2018 16:58:31 +0100 Subject: Add random gen for Canfield --- src/main/game/search-state/game_state.cpp | 38 ++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 11 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 26910a1..d032632 100644 --- a/src/main/game/search-state/game_state.cpp +++ b/src/main/game/search-state/game_state.cpp @@ -49,7 +49,7 @@ typedef sol_rules::foundations_init_type fit; game_state::game_state(const sol_rules& s_rules, streamliner_options stream_opts_) : rules(s_rules) , stream_opts(stream_opts_) - , foundation_base(card::rank_t(0)) + , foundations_base(card::rank_t(0)) , stock(255) , waste(255) , hole (255) { @@ -132,7 +132,8 @@ game_state::game_state(const sol_rules& s_rules, const Document& doc, streamline // Constructs an initial game state from a seed game_state::game_state(const sol_rules& s_rules, int seed, streamliner_options s_opts) : game_state(s_rules, s_opts) { - vector deck = gen_shuffled_deck(seed, rules.max_rank, rules.two_decks); + auto rng = mt19937(seed); + vector deck = gen_shuffled_deck(rules.max_rank, rules.two_decks, rng); // If there is a hole, moves the ace of spades to it if (rules.hole) { @@ -140,14 +141,30 @@ game_state::game_state(const sol_rules& s_rules, int seed, streamliner_options s place_card(hole, card("AS")); } + // If the foundation base is random, selects a random rank and suit + card::suit_t rand_suit = 0; + if (!rules.foundations_base) { + boost::random::uniform_int_distribution distr_rank(1, rules.max_rank); + foundations_base = distr_rank(rng); + boost::random::uniform_int_distribution distr_suit(0, 3); + rand_suit = distr_suit(rng); + } + // If the foundations begin filled, then fills them - if (rules.foundations_init_cards == fit::ALL) { - for (uint8_t f_idx = 0; f_idx < 4*(rules.two_decks ? 2:1); f_idx++) { - card c = card(f_idx % uint8_t(4), 1); + uint8_t founds_to_fill = 0; + switch (rules.foundations_init_cards) { + case sol_rules::foundations_init_type::NONE: + break; + case sol_rules::foundations_init_type::ONE: + founds_to_fill = 1; break; + case sol_rules::foundations_init_type::ALL: + founds_to_fill = static_cast(4 * (rules.two_decks ? 2 : 1)); break; + } + for (uint8_t f_idx = 0; f_idx < founds_to_fill; f_idx++) { + card c = card((f_idx + rand_suit) % uint8_t(4), foundations_base); - deck.erase(find(begin(deck), end(deck), c)); - place_card(foundations[f_idx], c); - } + deck.erase(find(begin(deck), end(deck), c)); + place_card(foundations[(f_idx + rand_suit)], c); } // If there is a stock, deals to it and set up a waste pile too @@ -250,8 +267,8 @@ game_state::game_state(const sol_rules& s_rules, } // Generates a randomly ordered vector of cards -vector game_state::gen_shuffled_deck(int seed, card::rank_t max_rank, - bool two_decks) { +vector game_state::gen_shuffled_deck(card::rank_t max_rank, + bool two_decks, mt19937 rng) { vector deck; for (int deck_count = 1; deck_count <= (two_decks ? 2 : 1); deck_count++) { @@ -264,7 +281,6 @@ vector game_state::gen_shuffled_deck(int seed, card::rank_t max_rank, assert(deck.size() == pile::size_type(max_rank * (two_decks ? 8 : 4))); - auto rng = mt19937(seed); game_state::shuffle(begin(deck), end(deck), rng); return deck; } -- cgit v1.2.1 From 40843e8fc66cb0bdeeee1b6df43673c8f245e677 Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Thu, 19 Jul 2018 17:54:45 +0100 Subject: Add tableau wraps logic --- src/main/game/search-state/game_state.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 d032632..81fdd96 100644 --- a/src/main/game/search-state/game_state.cpp +++ b/src/main/game/search-state/game_state.cpp @@ -631,7 +631,7 @@ bool game_state::is_solved() const { } 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;) { - if (!is_next_legal_card(rules.sequence_build_pol, piles[sequences[i]][j-1], piles[sequences[i]][j])) { + if (!is_next_legal_card(rules.sequence_build_pol, piles[sequences[i]][j-1], piles[sequences[i]][j], false)) { // TODO solved = false; break; } -- cgit v1.2.1 From 390a3cb4f15d84cde2312411b16203b70dbb2df5 Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Mon, 23 Jul 2018 10:31:37 +0100 Subject: Add foundation wrap logic and fix top-of-waste bug --- src/main/game/search-state/game_state.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 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 81fdd96..dbb3ea1 100644 --- a/src/main/game/search-state/game_state.cpp +++ b/src/main/game/search-state/game_state.cpp @@ -4,7 +4,6 @@ #include #include -#include #include #include @@ -631,7 +630,7 @@ bool game_state::is_solved() const { } 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;) { - if (!is_next_legal_card(rules.sequence_build_pol, piles[sequences[i]][j-1], piles[sequences[i]][j], false)) { // TODO + if (!is_next_legal_card(rules.sequence_build_pol, piles[sequences[i]][j-1], piles[sequences[i]][j], false)) { solved = false; break; } -- cgit v1.2.1 From 357fab143bcb41d55fb9060bcfbf257a8586e03c Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Mon, 23 Jul 2018 12:54:47 +0100 Subject: Small bug fixes inc found. base card & whole piles --- src/main/game/search-state/game_state.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 dbb3ea1..78247bf 100644 --- a/src/main/game/search-state/game_state.cpp +++ b/src/main/game/search-state/game_state.cpp @@ -48,7 +48,7 @@ typedef sol_rules::foundations_init_type fit; game_state::game_state(const sol_rules& s_rules, streamliner_options stream_opts_) : rules(s_rules) , stream_opts(stream_opts_) - , foundations_base(card::rank_t(0)) + , foundations_base(card::rank_t(1)) , stock(255) , waste(255) , hole (255) { -- cgit v1.2.1 From 2acab3e51cabd8ba80738b1faf791980d2abf724 Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Tue, 24 Jul 2018 12:00:04 +0100 Subject: Fix canfield to pass all unit tests --- src/main/game/search-state/game_state.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (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 78247bf..17fdc29 100644 --- a/src/main/game/search-state/game_state.cpp +++ b/src/main/game/search-state/game_state.cpp @@ -263,6 +263,16 @@ game_state::game_state(const sol_rules& s_rules, } pr++; } + + // Sets foundations base appropriately + if (rules.foundations_present && rules.foundations_base == boost::none) { + for (auto f : foundations) { + if (!piles[f].empty()) { + foundations_base = piles[f].top_card().get_rank(); + return; + } + } + } } // Generates a randomly ordered vector of cards -- cgit v1.2.1