From a33fce2a22243fc3d29571c88be6f3c3cef91bec Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Mon, 25 Jun 2018 10:50:50 +0100 Subject: Add face up cards json rule --- src/main/input-output/input/sol_preset_types.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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 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 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 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, -- cgit v1.2.1 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 --- CMakeLists.txt | 3 +- src/main/game/card.cpp | 10 + src/main/game/card.h | 4 + src/main/game/sol_rules.h | 6 + src/test/test_helper.cpp | 6 +- src/test/test_helper.h | 2 +- src/test/unit_tests/built_group_move_gen_test.cpp | 56 ++--- src/test/unit_tests/face_up_cards_test.cpp | 273 ++++++++++++++++++++++ 8 files changed, 327 insertions(+), 33 deletions(-) create mode 100644 src/test/unit_tests/face_up_cards_test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 73b7fcc..d1da3ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,7 +72,8 @@ set(sources_test src/test/unit_tests/card_test.cpp src/test/unit_tests/pile_test.cpp src/test/unit_tests/legal_move_gen_test.cpp - src/test/unit_tests/built_group_move_gen_test.cpp) + src/test/unit_tests/built_group_move_gen_test.cpp + src/test/unit_tests/face_up_cards_test.cpp) ############################################################################### ## Rapid JSON setup ########################################################### 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 diff --git a/src/test/test_helper.cpp b/src/test/test_helper.cpp index ab9e0cb..e1aa0a7 100644 --- a/src/test/test_helper.cpp +++ b/src/test/test_helper.cpp @@ -62,9 +62,9 @@ void test_helper::run_foundations_dominance_test(sol_rules::build_policy policy, ASSERT_TRUE(i->child_moves.empty()); } -void test_helper::run_built_group_test(sol_rules sr, - initializer_list piles, - vector exp_moves) { +void test_helper::expected_moves_test(sol_rules sr, + initializer_list piles, + vector exp_moves) { game_state gs(sr, piles); vector actual_moves = gs.get_legal_moves(); diff --git a/src/test/test_helper.h b/src/test/test_helper.h index 463a935..0690d0e 100644 --- a/src/test/test_helper.h +++ b/src/test/test_helper.h @@ -17,7 +17,7 @@ public: static bool is_solvable(const std::string&, const std::string&); static void run_foundations_dominance_test(sol_rules::build_policy policy, std::vector cards); - static void run_built_group_test(sol_rules sr, std::initializer_list, std::vector); + static void expected_moves_test(sol_rules sr, std::initializer_list, std::vector); static bool moves_eq(std::vector&, std::vector&); }; diff --git a/src/test/unit_tests/built_group_move_gen_test.cpp b/src/test/unit_tests/built_group_move_gen_test.cpp index 34e2b07..37a2cf0 100644 --- a/src/test/unit_tests/built_group_move_gen_test.cpp +++ b/src/test/unit_tests/built_group_move_gen_test.cpp @@ -20,13 +20,13 @@ TEST(BuiltGroupMoveGen, SameSuitEmpty) { sr.built_group_pol = pol::SAME_SUIT; sr.move_built_group = true; - test_helper::run_built_group_test( + test_helper::expected_moves_test( sr, { {}, - {"3C","2C","AC"}, // Same suit - {"3H","2S","AH"}, // Red black - {"3D","2D","AS"}, // Any suit + {"3C", "2C", "AC"}, // Same suit + {"3H", "2S", "AH"}, // Red black + {"3D", "2D", "AS"}, // Any suit {} }, { @@ -53,13 +53,13 @@ TEST(BuiltGroupMoveGen, RedBlackEmpty) { sr.built_group_pol = pol::RED_BLACK; sr.move_built_group = true; - test_helper::run_built_group_test( + test_helper::expected_moves_test( sr, { {}, - {"3C","2C","AC"}, // Same suit - {"3H","2S","AH"}, // Red black - {"3D","2D","AS"}, // Any suit + {"3C", "2C", "AC"}, // Same suit + {"3H", "2S", "AH"}, // Red black + {"3D", "2D", "AS"}, // Any suit {} }, { @@ -89,13 +89,13 @@ TEST(BuiltGroupMoveGen, AnySuitEmpty) { sr.built_group_pol = pol::ANY_SUIT; sr.move_built_group = true; - test_helper::run_built_group_test( + test_helper::expected_moves_test( sr, { {}, - {"3C","2C","AC"}, // Same suit - {"3H","2S","AH"}, // Red black - {"3D","2D","AS"}, // Any suit + {"3C", "2C", "AC"}, // Same suit + {"3H", "2S", "AH"}, // Red black + {"3D", "2D", "AS"}, // Any suit {} }, { @@ -132,13 +132,13 @@ TEST(BuiltGroupMoveGen, CantMove) { sr.built_group_pol = pol::ANY_SUIT; sr.move_built_group = false; - test_helper::run_built_group_test( + test_helper::expected_moves_test( sr, { {}, - {"3C","2C","AC"}, // Same suit - {"3H","2S","AH"}, // Red black - {"3D","2D","AS"}, // Any suit + {"3C", "2C", "AC"}, // Same suit + {"3H", "2S", "AH"}, // Red black + {"3D", "2D", "AS"}, // Any suit {} }, { @@ -159,13 +159,13 @@ TEST(BuiltGroupMoveGen, SameSuitOccupied) { sr.built_group_pol = pol::SAME_SUIT; sr.move_built_group = true; - test_helper::run_built_group_test( + test_helper::expected_moves_test( sr, { {"4C"}, - {"3C","2C","AC"}, // Same suit - {"3H","2S","AH"}, // Red black - {"3D","2D","AS"}, // Any suit + {"3C", "2C", "AC"}, // Same suit + {"3H", "2S", "AH"}, // Red black + {"3D", "2D", "AS"}, // Any suit {} }, { @@ -189,13 +189,13 @@ TEST(BuiltGroupMoveGen, RedBlackOccupied) { sr.built_group_pol = pol::RED_BLACK; sr.move_built_group = true; - test_helper::run_built_group_test( + test_helper::expected_moves_test( sr, { {"4C"}, - {"3C","2C","AC"}, // Same suit - {"3H","2S","AH"}, // Red black - {"3D","2D","AS"}, // Any suit + {"3C", "2C", "AC"}, // Same suit + {"3H", "2S", "AH"}, // Red black + {"3D", "2D", "AS"}, // Any suit {} }, { @@ -220,13 +220,13 @@ TEST(BuiltGroupMoveGen, AnySuitOccupied) { sr.built_group_pol = pol::ANY_SUIT; sr.move_built_group = true; - test_helper::run_built_group_test( + test_helper::expected_moves_test( sr, { {"4C"}, - {"3C","2C","AC"}, // Same suit - {"3H","2S","AH"}, // Red black - {"3D","2D","AS"}, // Any suit + {"3C", "2C", "AC"}, // Same suit + {"3H", "2S", "AH"}, // Red black + {"3D", "2D", "AS"}, // Any suit {} }, { diff --git a/src/test/unit_tests/face_up_cards_test.cpp b/src/test/unit_tests/face_up_cards_test.cpp new file mode 100644 index 0000000..6e2d6a3 --- /dev/null +++ b/src/test/unit_tests/face_up_cards_test.cpp @@ -0,0 +1,273 @@ +// +// Created by thecharlesblake on 1/11/18. +// + +#include + +#include "../test_helper.h" +#include "../../main/game/search-state/game_state.h" +#include "../../main/game/sol_rules.h" + +typedef sol_rules::build_policy pol; +typedef sol_rules::face_up_policy fu; +typedef move::mtype mt; + +using std::vector; +using std::ostream; +using std::initializer_list; + +#define ASSERT_FACE_UP(card) ASSERT_TRUE(card.is_face_up()) << card.to_string() << " should be face up" +#define ASSERT_FACE_DOWN(card) ASSERT_FALSE(card.is_face_up()) << card.to_string() << " should be face down" + + +TEST(FaceUpCards, CapsFaceUpIfFaceUpNotAll) { + sol_rules sr; + sr.tableau_pile_count = 3; + sr.built_group_pol = pol::SAME_SUIT; + sr.build_pol = pol::SAME_SUIT; + sr.move_built_group = true; + sr.face_up = fu::TOP_CARDS; + + initializer_list piles = { + {"3S"}, + {"2s","AS"}, + {} + }; + + game_state gs(sr, piles); + + ASSERT_FACE_UP(gs.get_data()[0][0]); + ASSERT_FACE_UP(gs.get_data()[1][0]); + ASSERT_FACE_DOWN(gs.get_data()[1][1]); +} + +TEST(FaceUpCards, IgnoreCapsIfFaceUpAll) { + sol_rules sr; + sr.tableau_pile_count = 3; + sr.built_group_pol = pol::SAME_SUIT; + sr.build_pol = pol::SAME_SUIT; + sr.move_built_group = true; + sr.face_up = fu::ALL; + + initializer_list piles = { + {"3S"}, + {"2s","AS"}, + {} + }; + + game_state gs(sr, piles); + + ASSERT_FACE_UP(gs.get_data()[0][0]); + ASSERT_FACE_UP(gs.get_data()[1][0]); + ASSERT_FACE_UP(gs.get_data()[1][1]); +} + +TEST(FaceUpCards, MoveTurnsFaceUp) { + sol_rules sr; + sr.tableau_pile_count = 3; + sr.built_group_pol = pol::SAME_SUIT; + sr.build_pol = pol::SAME_SUIT; + sr.move_built_group = true; + sr.face_up = fu::TOP_CARDS; + + initializer_list piles = { + {"3S"}, + {"2s","AS"}, // from + {} // to + }; + + game_state gs(sr, piles); + gs.make_move(move(mt::regular, 1, 2)); + + ASSERT_FACE_UP(gs.get_data()[0][0]); + ASSERT_FACE_UP(gs.get_data()[1][0]); + ASSERT_FACE_UP(gs.get_data()[2][0]); +} + +TEST(FaceUpCards, BuiltGroupMoveTurnsFaceUp) { + sol_rules sr; + sr.tableau_pile_count = 3; + sr.built_group_pol = pol::SAME_SUIT; + sr.build_pol = pol::SAME_SUIT; + sr.move_built_group = true; + sr.face_up = fu::TOP_CARDS; + + initializer_list piles = { + {"4S"}, + {"3s","2S","AS"}, // from + {} // to + }; + + game_state gs(sr, piles); + gs.make_move(move(mt::built_group, 1, 2, 2)); + + ASSERT_FACE_UP(gs.get_data()[0][0]); + ASSERT_FACE_UP(gs.get_data()[1][0]); + ASSERT_FACE_UP(gs.get_data()[2][0]); + ASSERT_FACE_UP(gs.get_data()[2][1]); +} + +TEST(FaceUpCards, MoveAlreadyFaceUpNoChange) { + sol_rules sr; + sr.tableau_pile_count = 3; + sr.built_group_pol = pol::SAME_SUIT; + sr.build_pol = pol::SAME_SUIT; + sr.move_built_group = true; + sr.face_up = fu::TOP_CARDS; + + initializer_list piles = { + {"3S"}, + {"2S","AS"}, // from + {} // to + }; + + game_state gs(sr, piles); + gs.make_move(move(mt::regular, 1, 2)); + + ASSERT_FACE_UP(gs.get_data()[0][0]); + ASSERT_FACE_UP(gs.get_data()[1][0]); + ASSERT_FACE_UP(gs.get_data()[2][0]); +} + +TEST(FaceUpCards, FaceDownNoBuiltGroup) { + sol_rules sr; + sr.tableau_pile_count = 3; + sr.built_group_pol = pol::SAME_SUIT; + sr.build_pol = pol::SAME_SUIT; + sr.move_built_group = true; + sr.face_up = fu::TOP_CARDS; + + initializer_list piles = { + {"3S"}, + {"2s","AS"}, + {} + }; + + test_helper::expected_moves_test( + sr, + { + {"3S"}, + {"2s","AS"}, + {} + }, + { + // Regular moves + move(move::mtype::regular, 0, 2, 1), + move(move::mtype::regular, 1, 2, 1), + } + ); +} + +TEST(FaceUpCards, FaceUpBuiltGroup) { + sol_rules sr; + sr.tableau_pile_count = 3; + sr.built_group_pol = pol::SAME_SUIT; + sr.build_pol = pol::SAME_SUIT; + sr.move_built_group = true; + sr.face_up = fu::TOP_CARDS; + + initializer_list piles = { + {"3S"}, + {"2s","AS"}, + {} + }; + + test_helper::expected_moves_test( + sr, + { + {"3S"}, + {"2S","AS"}, + {} + }, + { + // Regular moves + move(mt::regular, 0, 2, 1), + move(mt::regular, 1, 2, 1), + + // Built group moves + move(mt::built_group, 1, 0, 2), + move(mt::built_group, 1, 2, 2) + } + ); +} + +TEST(FaceUpCards, FaceUpBuiltGroup2Not3) { + sol_rules sr; + sr.tableau_pile_count = 3; + sr.built_group_pol = pol::SAME_SUIT; + sr.build_pol = pol::SAME_SUIT; + sr.move_built_group = true; + sr.face_up = fu::TOP_CARDS; + + initializer_list piles = { + {"3S"}, + {"2s","AS"}, + {} + }; + + test_helper::expected_moves_test( + sr, + { + {"4S"}, + {"3s","2S","AS"}, + {} + }, + { + // Regular moves + move(mt::regular, 0, 2, 1), + move(mt::regular, 1, 2, 1), + + // Built group moves + move(mt::built_group, 1, 2, 2) + } + ); +} + +TEST(FaceUpCards, UndoTurnsBackFaceDown) { + sol_rules sr; + sr.tableau_pile_count = 3; + sr.built_group_pol = pol::SAME_SUIT; + sr.build_pol = pol::SAME_SUIT; + sr.move_built_group = true; + sr.face_up = fu::TOP_CARDS; + + initializer_list piles = { + {"3S"}, + {"2s","AS"}, // from + {} // to + }; + + game_state gs(sr, piles); + move m = move(mt::regular, 1, 2); + gs.make_move(m); + gs.undo_move(m); + + ASSERT_FACE_UP(gs.get_data()[0][0]); + ASSERT_FACE_UP(gs.get_data()[1][0]); + ASSERT_FACE_DOWN(gs.get_data()[1][1]); +} + +TEST(FaceUpCards, UndoBuiltGroupTurnsBackFaceDown) { + sol_rules sr; + sr.tableau_pile_count = 3; + sr.built_group_pol = pol::SAME_SUIT; + sr.build_pol = pol::SAME_SUIT; + sr.move_built_group = true; + sr.face_up = fu::TOP_CARDS; + + initializer_list piles = { + {"4S"}, + {"3s","2S","AS"}, // from + {} // to + }; + + game_state gs(sr, piles); + move m = move(mt::built_group, 1, 2, 2); + gs.make_move(m); + gs.undo_move(m); + + ASSERT_FACE_UP(gs.get_data()[0][0]); + ASSERT_FACE_UP(gs.get_data()[1][0]); + ASSERT_FACE_UP(gs.get_data()[1][1]); + ASSERT_FACE_DOWN(gs.get_data()[1][2]); +} -- cgit v1.2.1 From 92d5705cb81e4fa4d971c8965b4cae7bc93f3eca Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Mon, 25 Jun 2018 11:54:07 +0100 Subject: Update rules schema to allow face up cards option --- src/main/input-output/input/json-parsing/rules_parser.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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..e55c313 100644 --- a/src/main/input-output/input/json-parsing/rules_parser.cpp +++ b/src/main/input-output/input/json-parsing/rules_parser.cpp @@ -318,7 +318,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}, -- cgit v1.2.1 From dbfd7469b1d62d3cd32325af6aeb01e975db0111 Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Mon, 25 Jun 2018 11:57:56 +0100 Subject: Add face up card rules parser --- .../input-output/input/json-parsing/rules_parser.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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 e55c313..91f6549 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,22 @@ 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(); + } else { + json_helper::json_parse_err("[tableau piles][face up cards] must be a string"); + } + } + if (face_up_str == "all") { + sr.face_up = fu::ALL; + } else if (face_up_str == "top") { + sr.face_up = fu::TOP_CARDS; + } else { + json_helper::json_parse_err("[tableau piles][face up cards] is invalid"); + } + } else { json_helper::json_parse_err("[tableau piles] must be an object"); } -- 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 ++++--- src/main/input-output/input/json-parsing/deal_parser.cpp | 4 +++- 3 files changed, 12 insertions(+), 8 deletions(-) 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&); 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)); } } } -- 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(-) 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(+) 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 From b9822b9fe08f423a32d5218ec8ce8bbcbf4c3a98 Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Mon, 25 Jun 2018 12:38:18 +0100 Subject: Correct face up rules parsing bug --- .../input-output/input/json-parsing/rules_parser.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) 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 91f6549..29e755b 100644 --- a/src/main/input-output/input/json-parsing/rules_parser.cpp +++ b/src/main/input-output/input/json-parsing/rules_parser.cpp @@ -166,17 +166,20 @@ void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) { 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"); } } - if (face_up_str == "all") { - sr.face_up = fu::ALL; - } else if (face_up_str == "top") { - sr.face_up = fu::TOP_CARDS; - } else { - json_helper::json_parse_err("[tableau piles][face up cards] is invalid"); - } } else { json_helper::json_parse_err("[tableau piles] must be an object"); -- cgit v1.2.1