From c7743d9f217c78b453a7676a88d61b4b937955ee Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Thu, 8 Mar 2018 23:05:02 +0000 Subject: Update JSON options for new spider rules --- resources/rules-presets/simple-spider.json | 4 +++- resources/rules-presets/spider.json | 6 ++++-- src/main/input-output/input/sol_preset_types.cpp | 11 ++++++++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/resources/rules-presets/simple-spider.json b/resources/rules-presets/simple-spider.json index b931efb..77c283a 100644 --- a/resources/rules-presets/simple-spider.json +++ b/resources/rules-presets/simple-spider.json @@ -1,7 +1,9 @@ { "tableau piles": { - "count": 4 + "count": 4, + "move built group": false }, + "ordered-tableau-sol": true, "two decks": true, "max rank": 3, "stock size": 12, diff --git a/resources/rules-presets/spider.json b/resources/rules-presets/spider.json index 4d93a47..442a8a3 100644 --- a/resources/rules-presets/spider.json +++ b/resources/rules-presets/spider.json @@ -1,8 +1,10 @@ { "tableau piles": { - "count": 10 + "count": 10, + "move built group": false }, + "ordered-tableau-sol": true, "two decks": true, - "stock size": 60, + "stock size": 50, "stock deal type": "tableau piles" } \ No newline at end of file diff --git a/src/main/input-output/input/sol_preset_types.cpp b/src/main/input-output/input/sol_preset_types.cpp index de0fd41..2eea9df 100644 --- a/src/main/input-output/input/sol_preset_types.cpp +++ b/src/main/input-output/input/sol_preset_types.cpp @@ -33,6 +33,7 @@ std::map sol_preset_types::mp = { "foundations": true, "foundations initial card": false, "foundations removable": false, + "ordered-tableau-sol": false, "cells": 0, "stock size": 0, "stock deal type": "waste", @@ -318,10 +319,12 @@ std::map sol_preset_types::mp = { R"( { "tableau piles": { - "count": 10 + "count": 10, + "move built group": false }, + "ordered-tableau-sol": true, "two decks": true, - "stock size": 60, + "stock size": 50, "stock deal type": "tableau piles" } )" @@ -333,8 +336,10 @@ std::map sol_preset_types::mp = { R"( { "tableau piles": { - "count": 4 + "count": 4, + "move built group": false }, + "ordered-tableau-sol": true, "two decks": true, "max rank": 3, "stock size": 12, -- cgit v1.2.1 From 5c3c87911b8149fedbc934fc2c98e6a331eeb4c3 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Thu, 8 Mar 2018 23:10:13 +0000 Subject: Add stock deal when no empty tableau piles logic --- src/main/game/game_state.legal_moves.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/game/game_state.legal_moves.cpp b/src/main/game/game_state.legal_moves.cpp index 99431e3..1d9b94f 100644 --- a/src/main/game/game_state.legal_moves.cpp +++ b/src/main/game/game_state.legal_moves.cpp @@ -21,9 +21,19 @@ vector game_state::get_legal_moves( // The next legal moves vector moves; - // If we have a stock that can deal to the tableau piles, add this move + // If we have a stock that can deal to the tableau piles, adds this move if (rules.stock_deal_t == sdt::TABLEAU_PILES && !piles[stock].empty()) { - moves.emplace_back(get_stock_tableau_move()); + // Only does this if all the tableau piles are empty + bool no_tableau_empty = true; + for (auto tab_ref : tableau_piles) { + if (piles[tab_ref].empty()) { + no_tableau_empty = false; + break; + } + } + if (no_tableau_empty) { + moves.emplace_back(get_stock_tableau_move()); + } } // Cycles through each pile which we may be able to remove a card from -- cgit v1.2.1 From 2cc12c2cc24701dbe89281c3b71031649a748879 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Thu, 8 Mar 2018 23:29:30 +0000 Subject: Add solve by ordered tableau json parsing --- resources/rules-presets/default.json | 1 + resources/rules-presets/simple-spider.json | 2 +- resources/rules-presets/spider.json | 2 +- src/main/game/sol_rules.cpp | 1 + src/main/game/sol_rules.h | 1 + .../input/json-parsing/rules_parser.cpp | 21 +++++++++++++++++---- src/main/input-output/input/sol_preset_types.cpp | 6 +++--- 7 files changed, 25 insertions(+), 9 deletions(-) diff --git a/resources/rules-presets/default.json b/resources/rules-presets/default.json index 9b28865..94a725f 100644 --- a/resources/rules-presets/default.json +++ b/resources/rules-presets/default.json @@ -13,6 +13,7 @@ "foundations": true, "foundations initial card": false, "foundations removable": false, + "solve by ordered tableau": false, "cells": 0, "stock size": 0, "stock deal type": "waste", diff --git a/resources/rules-presets/simple-spider.json b/resources/rules-presets/simple-spider.json index 77c283a..6c41a45 100644 --- a/resources/rules-presets/simple-spider.json +++ b/resources/rules-presets/simple-spider.json @@ -3,7 +3,7 @@ "count": 4, "move built group": false }, - "ordered-tableau-sol": true, + "solve by ordered tableau": true, "two decks": true, "max rank": 3, "stock size": 12, diff --git a/resources/rules-presets/spider.json b/resources/rules-presets/spider.json index 442a8a3..691b1de 100644 --- a/resources/rules-presets/spider.json +++ b/resources/rules-presets/spider.json @@ -3,7 +3,7 @@ "count": 10, "move built group": false }, - "ordered-tableau-sol": true, + "solve by ordered tableau": true, "two decks": true, "stock size": 50, "stock deal type": "tableau piles" diff --git a/src/main/game/sol_rules.cpp b/src/main/game/sol_rules.cpp index 7311e06..40a88a3 100644 --- a/src/main/game/sol_rules.cpp +++ b/src/main/game/sol_rules.cpp @@ -20,6 +20,7 @@ sol_rules::sol_rules() : hole(false), foundations(false), foundations_init_card(false), + solve_ord_tab(false), diagonal_deal(false), cells(0), stock_size(0), diff --git a/src/main/game/sol_rules.h b/src/main/game/sol_rules.h index 8ebb73d..d5d1e64 100644 --- a/src/main/game/sol_rules.h +++ b/src/main/game/sol_rules.h @@ -38,6 +38,7 @@ struct sol_rules { bool foundations; bool foundations_init_card; bool foundations_removable; + bool solve_ord_tab; bool diagonal_deal; uint8_t cells; uint8_t stock_size; 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 395f2e7..cf01b2d 100644 --- a/src/main/input-output/input/json-parsing/rules_parser.cpp +++ b/src/main/input-output/input/json-parsing/rules_parser.cpp @@ -56,6 +56,7 @@ sol_rules rules_parser::get_default() { } void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) { + int solution_types = 0; if (!d.IsObject()) { json_helper::json_parse_err("JSON doc must be object"); @@ -156,6 +157,7 @@ void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) { if (d.HasMember("hole")) { if (d["hole"].IsBool()) { sr.hole = d["hole"].GetBool(); + solution_types++; } else { json_helper::json_parse_err("[hole] must be a boolean"); } @@ -164,15 +166,12 @@ void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) { if (d.HasMember("foundations")) { if (d["foundations"].IsBool()) { sr.foundations = d["foundations"].GetBool(); + solution_types++; } else { json_helper::json_parse_err("[foundations] must be a boolean"); } } - if (!sr.hole && !sr.foundations) { - json_helper::json_parse_err("one of [hole] and [foundations] must be true"); - } - if (d.HasMember("foundations initial card")) { if (d["foundations initial card"].IsBool()) { sr.foundations_init_card = d["foundations initial card"].GetBool(); @@ -189,6 +188,15 @@ void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) { } } + if (d.HasMember("solve by ordered tableau")) { + if (d["solve by ordered tableau"].IsBool()) { + sr.solve_ord_tab = d["solve by ordered tableau"].GetBool(); + solution_types++; + } else { + json_helper::json_parse_err("[solve by ordered tableau] must be a boolean"); + } + } + if (d.HasMember("cells")) { if (d["cells"].IsInt()) { sr.cells = static_cast(d["cells"].GetInt()); @@ -232,4 +240,9 @@ void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) { json_helper::json_parse_err("[reserve stacked] must be a boolean"); } } + + if (solution_types != 1) + json_helper::json_parse_err("one and only one of [hole], [foundations] " + "and [solve by ordered tableau] must be true"); + } } diff --git a/src/main/input-output/input/sol_preset_types.cpp b/src/main/input-output/input/sol_preset_types.cpp index 2eea9df..75a0b01 100644 --- a/src/main/input-output/input/sol_preset_types.cpp +++ b/src/main/input-output/input/sol_preset_types.cpp @@ -33,7 +33,7 @@ std::map sol_preset_types::mp = { "foundations": true, "foundations initial card": false, "foundations removable": false, - "ordered-tableau-sol": false, + "solve by ordered tableau": false, "cells": 0, "stock size": 0, "stock deal type": "waste", @@ -322,7 +322,7 @@ std::map sol_preset_types::mp = { "count": 10, "move built group": false }, - "ordered-tableau-sol": true, + "solve by ordered tableau": true, "two decks": true, "stock size": 50, "stock deal type": "tableau piles" @@ -339,7 +339,7 @@ std::map sol_preset_types::mp = { "count": 4, "move built group": false }, - "ordered-tableau-sol": true, + "solve by ordered tableau": true, "two decks": true, "max rank": 3, "stock size": 12, -- cgit v1.2.1 From 1b56ea2cc3ca6ab1058391d8205fefbdeb202c12 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Fri, 9 Mar 2018 00:36:07 +0000 Subject: Add new solution type logic --- src/main/game/game_state.cpp | 20 +++++++++++++++++++- src/main/game/game_state.h | 1 + 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/game/game_state.cpp b/src/main/game/game_state.cpp index 6067c15..52f35f8 100644 --- a/src/main/game/game_state.cpp +++ b/src/main/game/game_state.cpp @@ -440,10 +440,18 @@ bool game_state::is_valid_auto_foundation_move(pile_ref target_pile) const { bool game_state::is_solved() const { bool solved = true; - if (rules.hole) { + if (rules.solve_ord_tab) { + for (pile_ref tab_pr : tableau_piles) { + if (is_ordered_pile(tab_pr)) { + solved = false; + break; + } + } + } else if (rules.hole) { solved = piles[hole].size() == rules.max_rank * 4 * (rules.two_decks ? 2 : 1); } else { + assert(rules.foundations); for (auto f : foundations) { if (piles[f].size() != rules.max_rank) { solved = false; @@ -480,6 +488,16 @@ bool game_state::is_solved() const { return solved; } +bool game_state::is_ordered_pile(pile_ref pr) const { + if (piles[pr].size() != rules.max_rank) return false; + + card::suit_t s = piles[pr][0].get_suit(); + for (card::rank_t r = rules.max_rank; r >= 1; r--) { + if (piles[pr][r] != card(s, r)) return false; + } + return true; +} + const std::vector& game_state::get_data() const { return piles; } diff --git a/src/main/game/game_state.h b/src/main/game/game_state.h index aeabc10..409fee9 100644 --- a/src/main/game/game_state.h +++ b/src/main/game/game_state.h @@ -84,6 +84,7 @@ private: void add_empty_built_group_moves(std::vector&, pile_ref, pile_ref, card) const; bool dominance_blocks_foundation_move(pile_ref); + bool is_ordered_pile(pile_ref) const; void update_auto_foundation_moves(pile_ref); bool is_valid_auto_foundation_move(pile_ref) const; -- cgit v1.2.1 From 1d44121d780e6d6c146792d7a992f1ddc1bf9cde Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Wed, 21 Mar 2018 10:57:15 +0000 Subject: Update python version to 3.6 --- .idea/Solvitaire.iml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.idea/Solvitaire.iml b/.idea/Solvitaire.iml index f0cb1fe..a198f4d 100644 --- a/.idea/Solvitaire.iml +++ b/.idea/Solvitaire.iml @@ -2,7 +2,7 @@ - + \ No newline at end of file -- cgit v1.2.1 From 00953c5edb79ed7c2551e6dcf9fb9e3040a3b42d Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Wed, 21 Mar 2018 10:57:59 +0000 Subject: Update spider with correct rules --- resources/rules-presets/default.json | 5 +++-- resources/rules-presets/simple-spider.json | 6 ++++-- resources/rules-presets/spider.json | 6 ++++-- src/main/input-output/input/sol_preset_types.cpp | 17 +++++++++++------ 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/resources/rules-presets/default.json b/resources/rules-presets/default.json index 94a725f..47032d8 100644 --- a/resources/rules-presets/default.json +++ b/resources/rules-presets/default.json @@ -5,7 +5,8 @@ "build policy": "any-suit", "spaces policy": "any", "diagonal deal": false, - "move built group": false + "move built group": false, + "move built group policy": "same-as-build" }, "max rank": 13, "two decks": false, @@ -13,7 +14,7 @@ "foundations": true, "foundations initial card": false, "foundations removable": false, - "solve by ordered tableau": false, + "foundations complete piles": false, "cells": 0, "stock size": 0, "stock deal type": "waste", diff --git a/resources/rules-presets/simple-spider.json b/resources/rules-presets/simple-spider.json index 6c41a45..5982441 100644 --- a/resources/rules-presets/simple-spider.json +++ b/resources/rules-presets/simple-spider.json @@ -1,9 +1,11 @@ { "tableau piles": { "count": 4, - "move built group": false + "build policy": "any-suit", + "move built group": true, + "move built group policy": "same-suit" }, - "solve by ordered tableau": true, + "foundations complete piles": true, "two decks": true, "max rank": 3, "stock size": 12, diff --git a/resources/rules-presets/spider.json b/resources/rules-presets/spider.json index 691b1de..6d08fba 100644 --- a/resources/rules-presets/spider.json +++ b/resources/rules-presets/spider.json @@ -1,9 +1,11 @@ { "tableau piles": { "count": 10, - "move built group": false + "build policy": "any-suit", + "move built group": true, + "move built group policy": "same-suit" }, - "solve by ordered tableau": true, + "foundations complete piles": true, "two decks": true, "stock size": 50, "stock deal type": "tableau piles" diff --git a/src/main/input-output/input/sol_preset_types.cpp b/src/main/input-output/input/sol_preset_types.cpp index 75a0b01..1fa6009 100644 --- a/src/main/input-output/input/sol_preset_types.cpp +++ b/src/main/input-output/input/sol_preset_types.cpp @@ -25,7 +25,8 @@ std::map sol_preset_types::mp = { "build policy": "any-suit", "spaces policy": "any", "diagonal deal": false, - "move built group": false + "move built group": false, + "move built group policy": "same-as-build" }, "max rank": 13, "two decks": false, @@ -33,7 +34,7 @@ std::map sol_preset_types::mp = { "foundations": true, "foundations initial card": false, "foundations removable": false, - "solve by ordered tableau": false, + "foundations complete piles": false, "cells": 0, "stock size": 0, "stock deal type": "waste", @@ -320,9 +321,11 @@ std::map sol_preset_types::mp = { { "tableau piles": { "count": 10, - "move built group": false + "build policy": "any-suit", + "move built group": true, + "move built group policy": "same-suit" }, - "solve by ordered tableau": true, + "foundations complete piles": true, "two decks": true, "stock size": 50, "stock deal type": "tableau piles" @@ -337,9 +340,11 @@ std::map sol_preset_types::mp = { { "tableau piles": { "count": 4, - "move built group": false + "build policy": "any-suit", + "move built group": true, + "move built group policy": "same-suit" }, - "solve by ordered tableau": true, + "foundations complete piles": true, "two decks": true, "max rank": 3, "stock size": 12, -- cgit v1.2.1 From 57cb29f245ebe7802014841d70f6f0289ce11113 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Wed, 21 Mar 2018 10:58:17 +0000 Subject: Update rules parse with built group pol --- .../input/json-parsing/rules_parser.cpp | 46 ++++++++++++++++------ 1 file changed, 33 insertions(+), 13 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 cf01b2d..6fa89bc 100644 --- a/src/main/input-output/input/json-parsing/rules_parser.cpp +++ b/src/main/input-output/input/json-parsing/rules_parser.cpp @@ -56,8 +56,6 @@ sol_rules rules_parser::get_default() { } void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) { - int solution_types = 0; - if (!d.IsObject()) { json_helper::json_parse_err("JSON doc must be object"); } @@ -110,7 +108,7 @@ void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) { } } else { - json_helper::json_parse_err("[tableau piles][spaces policy] must be an string"); + json_helper::json_parse_err("[tableau piles][spaces policy] must be a string"); } } @@ -122,6 +120,28 @@ void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) { } } + if (d["tableau piles"].HasMember("move built group policy")) { + if (d["tableau piles"]["move built group policy"].IsString()) { + string mbgp_str = d["tableau piles"]["move built group policy"].GetString(); + + if (mbgp_str == "same-as-build") { + sr.built_group_pol = sr.build_pol; + } else if (mbgp_str == "any-suit") { + sr.built_group_pol = pol::ANY_SUIT; + } else if (mbgp_str == "red-black") { + sr.built_group_pol = pol::RED_BLACK; + } else if (mbgp_str == "same-suit") { + sr.built_group_pol = pol::SAME_SUIT; + } else if (mbgp_str == "no-build") { + sr.built_group_pol = pol::NO_BUILD; + } else { + json_helper::json_parse_err("[tableau piles][move built group policy] is invalid"); + } + } else { + json_helper::json_parse_err("[tableau piles][move built group policy] must be a string"); + } + } + if (d["tableau piles"].HasMember("diagonal deal")) { if (d["tableau piles"]["diagonal deal"].IsBool()) { sr.diagonal_deal = d["tableau piles"]["diagonal deal"].GetBool(); @@ -157,7 +177,6 @@ void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) { if (d.HasMember("hole")) { if (d["hole"].IsBool()) { sr.hole = d["hole"].GetBool(); - solution_types++; } else { json_helper::json_parse_err("[hole] must be a boolean"); } @@ -166,7 +185,6 @@ void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) { if (d.HasMember("foundations")) { if (d["foundations"].IsBool()) { sr.foundations = d["foundations"].GetBool(); - solution_types++; } else { json_helper::json_parse_err("[foundations] must be a boolean"); } @@ -188,12 +206,11 @@ void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) { } } - if (d.HasMember("solve by ordered tableau")) { - if (d["solve by ordered tableau"].IsBool()) { - sr.solve_ord_tab = d["solve by ordered tableau"].GetBool(); - solution_types++; + if (d.HasMember("foundations complete piles")) { + if (d["foundations complete piles"].IsBool()) { + sr.foundations_comp_piles = d["foundations complete piles"].GetBool(); } else { - json_helper::json_parse_err("[solve by ordered tableau] must be a boolean"); + json_helper::json_parse_err("[foundations complete piles] must be a boolean"); } } @@ -241,8 +258,11 @@ void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) { } } - if (solution_types != 1) - json_helper::json_parse_err("one and only one of [hole], [foundations] " - "and [solve by ordered tableau] must be true"); + int solution_types = 0; + if (sr.hole) solution_types++; + if (sr.foundations) solution_types++; + if (solution_types != 1) { + json_helper::json_parse_err("one and only one of [hole] and [foundations] " + "must be true"); } } -- cgit v1.2.1 From 5cac604a3da9fd1eeb58c8cfab789f81ded34054 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Wed, 21 Mar 2018 10:59:09 +0000 Subject: Update sol rules with built group pol --- src/main/game/sol_rules.cpp | 3 ++- src/main/game/sol_rules.h | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/game/sol_rules.cpp b/src/main/game/sol_rules.cpp index 40a88a3..592437d 100644 --- a/src/main/game/sol_rules.cpp +++ b/src/main/game/sol_rules.cpp @@ -15,12 +15,13 @@ sol_rules::sol_rules() : build_pol(pol::ANY_SUIT), spaces_pol(s_pol::ANY), move_built_group(false), + built_group_pol(pol::ANY_SUIT), two_decks(false), max_rank(13), hole(false), foundations(false), foundations_init_card(false), - solve_ord_tab(false), + foundations_comp_piles(false), diagonal_deal(false), cells(0), stock_size(0), diff --git a/src/main/game/sol_rules.h b/src/main/game/sol_rules.h index d5d1e64..98474fc 100644 --- a/src/main/game/sol_rules.h +++ b/src/main/game/sol_rules.h @@ -32,13 +32,14 @@ struct sol_rules { build_policy build_pol; spaces_policy spaces_pol; bool move_built_group; + build_policy built_group_pol; bool two_decks; uint8_t max_rank; bool hole; bool foundations; bool foundations_init_card; bool foundations_removable; - bool solve_ord_tab; + bool foundations_comp_piles; bool diagonal_deal; uint8_t cells; uint8_t stock_size; -- cgit v1.2.1 From b44289751adb8c87fec50a0a8fd9b71d7c6bdaf8 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Wed, 21 Mar 2018 10:59:27 +0000 Subject: Update game logic for correct spider impl --- src/main/game/game_state.cpp | 34 ++++++++++----------------- src/main/game/game_state.legal_moves.cpp | 40 ++++++++++++++++++++++++++------ 2 files changed, 45 insertions(+), 29 deletions(-) diff --git a/src/main/game/game_state.cpp b/src/main/game/game_state.cpp index 52f35f8..8a62939 100644 --- a/src/main/game/game_state.cpp +++ b/src/main/game/game_state.cpp @@ -231,7 +231,7 @@ void game_state::make_move(const move m) { // Handles special stock-to-tableau-piles move if (rules.stock_deal_t == sdt::TABLEAU_PILES && m.from == stock) { assert(m.from == stock); - assert(m.count == 255 ); + assert(m.to == 255 ); for (pile_ref tab_pr = original_tableau_piles.front(); tab_pr < pile_ref(original_tableau_piles.front() + m.count); @@ -269,7 +269,6 @@ void game_state::make_move(const move m) { void game_state::undo_move(const move m) { assert(m.from < piles.size()); - assert(m.to < piles.size()); // Handles special stock-to-tableau-piles move if (rules.stock_deal_t == sdt::TABLEAU_PILES && m.from == stock) { @@ -281,11 +280,13 @@ void game_state::undo_move(const move m) { } // If this is not a built-pile move else if (m.count == 1 || m.is_dominance()) { + assert(m.to < piles.size()); place_card(m.from, take_card(m.to)); #ifndef NO_AUTO_FOUNDATIONS update_auto_foundation_moves(m.from); #endif } else { + assert(m.to < piles.size()); assert(m.count <= rules.max_rank); // Adds the cards to the 'from' pile for (auto pile_idx = m.count; pile_idx-- > 0;) { @@ -304,7 +305,10 @@ void game_state::undo_move(const move m) { void game_state::place_card(pile_ref pr, card c) { piles[pr].place(c); #ifndef NO_PILE_SYMMETRY - eval_pile_order(pr, true); + // If the stock deals to the tableau piles, there is no pile symmetry + if (rules.stock_size == 0 || rules.stock_deal_t != sdt::TABLEAU_PILES) { + eval_pile_order(pr, true); + } #endif } @@ -312,7 +316,10 @@ void game_state::place_card(pile_ref pr, card c) { card game_state::take_card(pile_ref pr) { card c = piles[pr].take(); #ifndef NO_PILE_SYMMETRY - eval_pile_order(pr, false); + // If the stock deals to the tableau piles, there is no pile symmetry + if (rules.stock_size == 0 || rules.stock_deal_t != sdt::TABLEAU_PILES) { + eval_pile_order(pr, false); + } #endif return c; } @@ -440,14 +447,7 @@ bool game_state::is_valid_auto_foundation_move(pile_ref target_pile) const { bool game_state::is_solved() const { bool solved = true; - if (rules.solve_ord_tab) { - for (pile_ref tab_pr : tableau_piles) { - if (is_ordered_pile(tab_pr)) { - solved = false; - break; - } - } - } else if (rules.hole) { + if (rules.hole) { solved = piles[hole].size() == rules.max_rank * 4 * (rules.two_decks ? 2 : 1); } else { @@ -488,16 +488,6 @@ bool game_state::is_solved() const { return solved; } -bool game_state::is_ordered_pile(pile_ref pr) const { - if (piles[pr].size() != rules.max_rank) return false; - - card::suit_t s = piles[pr][0].get_suit(); - for (card::rank_t r = rules.max_rank; r >= 1; r--) { - if (piles[pr][r] != card(s, r)) return false; - } - return true; -} - const std::vector& game_state::get_data() const { return piles; } diff --git a/src/main/game/game_state.legal_moves.cpp b/src/main/game/game_state.legal_moves.cpp index 1d9b94f..f0502d1 100644 --- a/src/main/game/game_state.legal_moves.cpp +++ b/src/main/game/game_state.legal_moves.cpp @@ -109,6 +109,22 @@ vector game_state::get_legal_moves( get_built_group_moves(moves); } + // If only complete built piles can be moved to the foundations, + if (rules.foundations_comp_piles) { + for (pile_ref tab_pr : tableau_piles) { + if (is_ordered_pile(tab_pr)) { + + for (pile_ref found_pr : foundations) { + if (piles[found_pr].empty()) { + moves.emplace_back(tab_pr, found_pr, rules.max_rank); + break; + } + } + } + } + } + + return moves; } @@ -163,7 +179,7 @@ bool game_state::is_valid_tableau_move(const pile_ref rem_ref, bool game_state::is_valid_foundations_move(const pile_ref rem_ref, const pile_ref add_ref) const { - if (rem_ref == add_ref) return false; + if (rules.foundations_comp_piles || rem_ref == add_ref) return false; card rem_c = piles[rem_ref].top_card(); @@ -198,7 +214,7 @@ bool game_state::is_valid_hole_move(const pile_ref rem_ref) const { /////////////////////// void game_state::get_built_group_moves(vector& moves) const { - assert(rules.build_pol != pol::NO_BUILD); + assert(rules.built_group_pol != pol::NO_BUILD); // Cycles through each pile to see if it contains a built group of size > 1 for (auto rem_ref : tableau_piles) { @@ -247,13 +263,13 @@ pile::size_type game_state::get_built_group_height(pile_ref ref) const { card c = piles[ref][group_card_idx]; // If the build policy is same suit, makes sure group has same suit - if (rules.build_pol == sol_rules::build_policy::SAME_SUIT + if (rules.built_group_pol == pol::SAME_SUIT && c.get_suit() != prev_c.get_suit()) { built_group = false; } // If the build policy is red black, makes sure group alternates // in correct phase - else if (rules.build_pol == sol_rules::build_policy::RED_BLACK + else if (rules.built_group_pol == pol::RED_BLACK && c.get_colour() == prev_c.get_colour()) { built_group = false; } @@ -281,11 +297,11 @@ const { } // Checks to see if the suits are correct - switch (rules.build_pol) { - case sol_rules::build_policy::SAME_SUIT: + switch (rules.built_group_pol) { + case pol::SAME_SUIT: return bg_low.get_suit() == add_card.get_suit(); - case sol_rules::build_policy::RED_BLACK: { + case pol::RED_BLACK: { bool same_suit = bg_low.get_suit() == add_card.get_suit(); bool even_diff = (add_card.get_rank() - bg_low.get_rank()) % 2 == 0; return (same_suit && even_diff) || (!same_suit && !even_diff); @@ -354,6 +370,16 @@ optional game_state::get_dominance_move() const { return none; } +bool game_state::is_ordered_pile(pile_ref pr) const { + if (piles[pr].size() != rules.max_rank) return false; + + card::suit_t s = piles[pr][0].get_suit(); + for (card::rank_t r = 0; r < rules.max_rank; r++) { + if (piles[pr][r] != card(s, card::rank_t(r + 1))) return false; + } + return true; +} + // For games where the foundations can be removed from, this dominance blocks // the foundations being removed from if the card that were to be removed would // go 'automatically' up -- cgit v1.2.1 From 40ba758cba9d7f491da2d2b08b93dacc2b20fd04 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Wed, 21 Mar 2018 10:59:46 +0000 Subject: Update spider tests --- src/test/resources/spider/ComplexSolvable.json | 8 ++++---- src/test/resources/spider/ComplexUnsolvable.json | 14 +++++++------- src/test/test_helper.cpp | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/test/resources/spider/ComplexSolvable.json b/src/test/resources/spider/ComplexSolvable.json index 3591805..c7d96e2 100644 --- a/src/test/resources/spider/ComplexSolvable.json +++ b/src/test/resources/spider/ComplexSolvable.json @@ -3,11 +3,11 @@ ["2D","AD","3D"], ["AC","2C","3C"], ["AS","2S","3S"], - ["AH","2H","3H"] + ["3H","2H","AH"] ], "stock": [ - "2C","2D","2H","2S", + "2C","3D","3H","3S", "AC","AD","AH","AS", - "3C","3D","3H","3S" + "3C","2D","2H","2S" ] -} +} \ No newline at end of file diff --git a/src/test/resources/spider/ComplexUnsolvable.json b/src/test/resources/spider/ComplexUnsolvable.json index 8fce03d..2379c9a 100644 --- a/src/test/resources/spider/ComplexUnsolvable.json +++ b/src/test/resources/spider/ComplexUnsolvable.json @@ -1,13 +1,13 @@ { "tableau piles": [ ["2D","AD","3D"], - ["AC","AC","3C"], - ["AS","AS","3S"], - ["AH","AH","3H"] + ["AC","2C","3C"], + ["AS","2S","3S"], + ["3H","2H","AH"] ], "stock": [ - "2C","2D","2H","2S", - "AC","2D","2H","2S", - "3C","3D","3H","3S" + "3C","3D","3H","3S", + "2C","2D","AH","AS", + "AC","AD","2H","2S" ] -} +} \ No newline at end of file diff --git a/src/test/test_helper.cpp b/src/test/test_helper.cpp index da618d8..5dadeb3 100644 --- a/src/test/test_helper.cpp +++ b/src/test/test_helper.cpp @@ -23,7 +23,7 @@ bool test_helper::is_solvable(const std::string& input_file, const std::string& game_state gs(rules, in_doc); solver sol(gs); - return sol.run(); + return sol.run() == solver::sol_state::solved; } void test_helper::run_foundations_dominance_test(sol_rules::build_policy policy, -- cgit v1.2.1 From 20e366d5f8c08111b0c1e185611a27af767ea678 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Wed, 21 Mar 2018 10:59:55 +0000 Subject: Update benchmark spider scaling for correct rules --- benchmark.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmark.py b/benchmark.py index efdddac..d790718 100644 --- a/benchmark.py +++ b/benchmark.py @@ -159,7 +159,7 @@ class SpiderRulesGen(SolitaireRulesGen): def alterFieldsToChange(self, level): self.baseJson["max rank"] = level self.baseJson["tableau piles"]["count"] = math.ceil(10*level/13) - self.baseJson["stock size"] = math.ceil(60*level/13) + self.baseJson["stock size"] = math.ceil(50*level/13) def cleanup(): os.remove(tempRulesFilename) -- cgit v1.2.1