From 2b92783762c2824e519b881afbf5d66a606c394f Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Mon, 25 Jun 2018 11:50:34 +0100 Subject: Add card face down unit tests --- src/main/game/card.cpp | 10 ++++++++++ src/main/game/card.h | 4 ++++ src/main/game/sol_rules.h | 6 ++++++ 3 files changed, 20 insertions(+) (limited to 'src/main/game') diff --git a/src/main/game/card.cpp b/src/main/game/card.cpp index cfb94a9..710b394 100644 --- a/src/main/game/card.cpp +++ b/src/main/game/card.cpp @@ -85,6 +85,16 @@ std::string card::to_string() const { return s; } +bool card::is_face_up() const { + return true; +} + +void card::turn_face_up() { +} + +void card::turn_face_down() { +} + const card card::divider = card(0, 0); bool operator==(const card& l, const card& r) { diff --git a/src/main/game/card.h b/src/main/game/card.h index a4c6b1e..ad14d2b 100644 --- a/src/main/game/card.h +++ b/src/main/game/card.h @@ -39,6 +39,10 @@ public: colour_t get_colour() const; rank_t get_rank() const; + bool is_face_up() const; + void turn_face_up(); + void turn_face_down(); + std::string to_string() const; private: diff --git a/src/main/game/sol_rules.h b/src/main/game/sol_rules.h index adab00d..a7b9ae6 100644 --- a/src/main/game/sol_rules.h +++ b/src/main/game/sol_rules.h @@ -28,6 +28,10 @@ struct sol_rules { WASTE, TABLEAU_PILES }; + enum class face_up_policy { + ALL, + TOP_CARDS + }; uint8_t tableau_pile_count; build_policy build_pol; @@ -49,6 +53,8 @@ struct sol_rules { bool stock_redeal; uint8_t reserve_size; bool reserve_stacked; + face_up_policy face_up; + }; #endif //SOLVITAIRE_SOL_RULES_H -- cgit v1.2.1 From 8167f678fcbfc34982458b0311346bbeb04da9af Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Mon, 25 Jun 2018 12:25:02 +0100 Subject: Add face down deal parsing --- src/main/game/card.cpp | 9 +++++---- src/main/game/card.h | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'src/main/game') diff --git a/src/main/game/card.cpp b/src/main/game/card.cpp index 710b394..21bbd2f 100644 --- a/src/main/game/card.cpp +++ b/src/main/game/card.cpp @@ -22,11 +22,12 @@ const card::colour_t card::colour::Red = 1; // A card can either be created using two int values (rank & suit), or // using a string (e.g. "AS") -card::card(suit_t s, rank_t r) : card_rank(r), card_suit(s) {} +card::card(suit_t s, rank_t r, bool fd) : card_rank(r), card_suit(s), face_down(fd) {} -card::card(const char* c) : card_rank(rank_from_str(c)), card_suit(suit_from_str(c)) {} +card::card(const char* c, bool face_down_possible) : + card_rank(rank_from_str(c)), card_suit(suit_from_str(c)), face_down(face_down_possible) {} // TODO: CHANGE! -card::card() : card(0, 0) {} +card::card() : card(0, 0, false) {} card::suit_t card::suit_from_str(const char* c) { switch(tolower(c[strlen(c) - 1])) { @@ -95,7 +96,7 @@ void card::turn_face_up() { void card::turn_face_down() { } -const card card::divider = card(0, 0); +const card card::divider = card(); bool operator==(const card& l, const card& r) { return l.get_rank() == r.get_rank() && l.get_suit() == r.get_suit(); diff --git a/src/main/game/card.h b/src/main/game/card.h index ad14d2b..ea808b4 100644 --- a/src/main/game/card.h +++ b/src/main/game/card.h @@ -31,8 +31,8 @@ public: // A card can either be created using two int values (rank & suit), or // using a string (e.g. "AS") - card(suit_t, rank_t); - card(const char*); + card(suit_t, rank_t, bool face_down=false); + card(const char*, bool face_down_possible=false); card(); suit_t get_suit() const; @@ -50,7 +50,8 @@ private: static rank_t rank_from_str(const char* c); rank_t card_rank : 4; - suit_t card_suit : 4; + suit_t card_suit : 2; + bool face_down : 1; }; bool operator==(const card&, const card&); -- cgit v1.2.1 From a99b32bf9f62c4efa6c959bdd6ee4d4e52054bd0 Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Mon, 25 Jun 2018 12:30:23 +0100 Subject: Add game state face down random gen --- src/main/game/search-state/game_state.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/main/game') diff --git a/src/main/game/search-state/game_state.cpp b/src/main/game/search-state/game_state.cpp index 82e413b..8a1298b 100644 --- a/src/main/game/search-state/game_state.cpp +++ b/src/main/game/search-state/game_state.cpp @@ -18,6 +18,7 @@ #include "../../input-output/output/state_printer.h" #include "../../input-output/output/log_helper.h" #include "../move.h" +#include "../sol_rules.h" using namespace rapidjson; using std::vector; @@ -34,6 +35,7 @@ using std::mt19937; typedef sol_rules::build_policy pol; typedef sol_rules::stock_deal_type sdt; +typedef sol_rules::face_up_policy fu; ////////////////// // CONSTRUCTORS // @@ -155,7 +157,10 @@ game_state::game_state(const sol_rules& s_rules, int seed, bool streamliners_) for (int t = 0; !deck.empty(); t++) { card c = deck.back(); - // Add the randomly generated card to the tableau piles + // If only the top cards are face up, initially deals all face down + if (rules.face_up == fu::TOP_CARDS) c.turn_face_down(); + + // Adds the randomly generated card to the tableau piles auto p = t % original_tableau_piles.size(); // If we are doing a diagonal deal, each row should have one fewer card. @@ -176,6 +181,12 @@ game_state::game_state(const sol_rules& s_rules, int seed, bool streamliners_) } } + // Now if necessary, turns the top cards face up + if (rules.face_up == fu::TOP_CARDS) + for (auto& p : piles) + if (!p.empty()) + p[0].turn_face_up(); + // The size of all piles must equal the deck size int piles_sz = 0; for (auto& p : piles) piles_sz += p.size(); -- cgit v1.2.1 From b3cd52e5b844414f66a2e9fde996ddeaf0b68fec Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Mon, 25 Jun 2018 12:31:41 +0100 Subject: Add state printing for face down cards --- src/main/game/card.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/main/game') diff --git a/src/main/game/card.cpp b/src/main/game/card.cpp index 21bbd2f..12e577f 100644 --- a/src/main/game/card.cpp +++ b/src/main/game/card.cpp @@ -69,6 +69,8 @@ card::rank_t card::get_rank() const { } std::string card::to_string() const { + if (face_down) return "##"; + string s; switch(card_rank) { case 1 : s += "A"; break; -- cgit v1.2.1