diff options
| author | Ian Gent | 2018-06-26 11:21:28 +0100 |
|---|---|---|
| committer | Ian Gent | 2018-06-26 11:21:28 +0100 |
| commit | 9ed82b8bbdc1d7b0265a9009950a4dc4916d91bb (patch) | |
| tree | c98a9fb4bac9d74a059987929f3dfb93f7e5a8c3 /src/main | |
| parent | Raglan deal (diff) | |
| parent | Merge pull request #69 from thecharlesblake/correct-klondike (diff) | |
| download | metasol-9ed82b8bbdc1d7b0265a9009950a4dc4916d91bb.tar.gz metasol-9ed82b8bbdc1d7b0265a9009950a4dc4916d91bb.zip | |
Merge branch ‘master’ of github.com:thecharlesblake/Solvitaire
Diffstat (limited to 'src/main')
| -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 | ||||
| -rw-r--r-- | src/main/input-output/input/json-parsing/deal_parser.cpp | 4 | ||||
| -rw-r--r-- | src/main/input-output/input/json-parsing/rules_parser.cpp | 24 | ||||
| -rw-r--r-- | src/main/input-output/input/sol_preset_types.cpp | 9 |
7 files changed, 75 insertions, 13 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 diff --git a/src/main/input-output/input/json-parsing/deal_parser.cpp b/src/main/input-output/input/json-parsing/deal_parser.cpp index 29ac3b1..e776cbd 100644 --- a/src/main/input-output/input/json-parsing/deal_parser.cpp +++ b/src/main/input-output/input/json-parsing/deal_parser.cpp @@ -5,11 +5,13 @@ #include "deal_parser.h" #include "../../../game/search-state/game_state.h" #include "json_helper.h" +#include "../../../game/sol_rules.h" using namespace std; using namespace rapidjson; typedef sol_rules::build_policy pol; +typedef sol_rules::face_up_policy fu; void deal_parser::parse(game_state &gs, const rapidjson::Document& doc) { // There are two stages to reading in the supplied deal. It is both put @@ -100,7 +102,7 @@ void deal_parser::parse_tableau_piles(game_state &gs, const rapidjson::Document& for (auto& json_card : p.first->GetArray()) { assert(json_card.IsString()); - gs.place_card(*p.second, card(json_card.GetString())); + gs.place_card(*p.second, card(json_card.GetString(), gs.rules.face_up != fu::ALL)); } } } diff --git a/src/main/input-output/input/json-parsing/rules_parser.cpp b/src/main/input-output/input/json-parsing/rules_parser.cpp index d4879de..29e755b 100644 --- a/src/main/input-output/input/json-parsing/rules_parser.cpp +++ b/src/main/input-output/input/json-parsing/rules_parser.cpp @@ -9,6 +9,7 @@ #include "json_helper.h" #include "../sol_preset_types.h" #include "../../../game/card.h" +#include "../../../game/sol_rules.h" using namespace std; using namespace rapidjson; @@ -20,6 +21,7 @@ using namespace rapidjson; typedef sol_rules::build_policy pol; typedef sol_rules::spaces_policy s_pol; typedef sol_rules::stock_deal_type sdt; +typedef sol_rules::face_up_policy fu; const sol_rules rules_parser::from_file(const string rules_file) { sol_rules sr = get_default(); @@ -160,6 +162,25 @@ void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) { } } + string face_up_str; + if (d["tableau piles"].HasMember("face up cards")) { + if (d["tableau piles"]["face up cards"].IsString()) { + face_up_str = d["tableau piles"]["face up cards"].GetString(); + + if (face_up_str == "all") { + sr.face_up = fu::ALL; + } else if (face_up_str == "top") { + sr.face_up = fu::TOP_CARDS; + } else { + string err = "[tableau piles][face up cards] is invalid: " + face_up_str; + json_helper::json_parse_err(err); + } + + } else { + json_helper::json_parse_err("[tableau piles][face up cards] must be a string"); + } + } + } else { json_helper::json_parse_err("[tableau piles] must be an object"); } @@ -318,7 +339,8 @@ string rules_parser::rules_schema_json() { "spaces policy": {"type": "string", "enum": ["any", "no-build", "kings"]}, "diagonal deal": {"type": "boolean"}, "move built group": {"type": "boolean"}, - "move built group policy": {"type": "string", "enum": ["same-as-build", "any-suit", "red-black", "same-suit", "no-build"]} + "move built group policy": {"type": "string", "enum": ["same-as-build", "any-suit", "red-black", "same-suit", "no-build"]}, + "face up cards": {"type": "string", "enum": ["all", "top"]} }, "additionalProperties": false }, "max rank": {"type": "integer", "minimum": 1, "maximum": 13}, diff --git a/src/main/input-output/input/sol_preset_types.cpp b/src/main/input-output/input/sol_preset_types.cpp index 5b751af..a10df54 100644 --- a/src/main/input-output/input/sol_preset_types.cpp +++ b/src/main/input-output/input/sol_preset_types.cpp @@ -26,7 +26,8 @@ map<string, string> sol_preset_types::mp = { "spaces policy": "any", "diagonal deal": false, "move built group": false, - "move built group policy": "same-as-build" + "move built group policy": "same-as-build", + "face up cards": "all" }, "max rank": 13, "two decks": false, @@ -388,7 +389,8 @@ map<string, string> sol_preset_types::mp = { "build policy": "red-black", "spaces policy": "kings", "move built group": true, - "diagonal deal": true + "diagonal deal": true, + "face up cards": "top" }, "stock size": 24, "stock deal count": 1, @@ -408,7 +410,8 @@ map<string, string> sol_preset_types::mp = { "build policy": "red-black", "spaces policy": "kings", "move built group": true, - "diagonal deal": true + "diagonal deal": true, + "face up cards": "top" }, "stock size": 24, "stock deal count": 3, |
