diff options
| author | Charlie Blake | 2018-06-26 10:42:19 +0100 |
|---|---|---|
| committer | GitHub | 2018-06-26 10:42:19 +0100 |
| commit | 3deb640852b04d8ea21bc777efe72e95e73b9070 (patch) | |
| tree | df43bd847c85ca4e6bd9abf70340de802f5af265 /src/main/game | |
| parent | Merge pull request #68 from thecharlesblake/full-streamliner-res (diff) | |
| parent | Correct face up rules parsing bug (diff) | |
| download | metasol-3deb640852b04d8ea21bc777efe72e95e73b9070.tar.gz metasol-3deb640852b04d8ea21bc777efe72e95e73b9070.zip | |
Merge pull request #69 from thecharlesblake/correct-klondike
Correct klondike
Diffstat (limited to 'src/main/game')
| -rw-r--r-- | src/main/game/card.cpp | 21 | ||||
| -rw-r--r-- | src/main/game/card.h | 11 | ||||
| -rw-r--r-- | src/main/game/search-state/game_state.cpp | 13 | ||||
| -rw-r--r-- | src/main/game/sol_rules.h | 6 |
4 files changed, 43 insertions, 8 deletions
diff --git a/src/main/game/card.cpp b/src/main/game/card.cpp index cfb94a9..12e577f 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])) { @@ -68,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; @@ -85,7 +88,17 @@ std::string card::to_string() const { return s; } -const card card::divider = card(0, 0); +bool card::is_face_up() const { + return true; +} + +void card::turn_face_up() { +} + +void card::turn_face_down() { +} + +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 a4c6b1e..ea808b4 100644 --- a/src/main/game/card.h +++ b/src/main/game/card.h @@ -31,14 +31,18 @@ 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; 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: @@ -46,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&); 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(); 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 |
