aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharlie Blake2018-07-18 16:04:56 +0100
committerGitHub2018-07-18 16:04:56 +0100
commit4ddf1752f3909eb1c87c06414597463208120058 (patch)
tree62bbba8f7dd114ccd39f0e935b1bc4fbd74250dd
parentMerge pull request #76 from thecharlesblake/add-gaps (diff)
parentAdd accordion move making (diff)
downloadmetasol-4ddf1752f3909eb1c87c06414597463208120058.tar.gz
metasol-4ddf1752f3909eb1c87c06414597463208120058.zip

Merge pull request #77 from thecharlesblake/add-accordion

Add accordion

-rw-r--r--CMakeLists.txt1
-rw-r--r--src/main/evaluation/solvability_calc.cpp2
-rw-r--r--src/main/game/global_cache.cpp4
-rw-r--r--src/main/game/move.h2
-rw-r--r--src/main/game/search-state/game_state.cpp45
-rw-r--r--src/main/game/search-state/game_state.h5
-rw-r--r--src/main/game/search-state/game_state.legal_moves.cpp44
-rw-r--r--src/main/game/sol_rules.cpp3
-rw-r--r--src/main/game/sol_rules.h10
-rw-r--r--src/main/input-output/input/json-parsing/deal_parser.cpp29
-rw-r--r--src/main/input-output/input/json-parsing/deal_parser.h1
-rw-r--r--src/main/input-output/input/json-parsing/rules_parser.cpp92
-rw-r--r--src/main/input-output/input/sol_preset_types.cpp65
-rw-r--r--src/main/input-output/output/state_printer.cpp18
-rw-r--r--src/main/input-output/output/state_printer.h2
-rw-r--r--src/main/solver/solver.cpp1
-rw-r--r--src/test/integration_tests/accordion_test.cpp28
-rw-r--r--src/test/resources/accordion/ComplexSolvable.json3
-rw-r--r--src/test/resources/accordion/ComplexUnsolvable.json3
-rw-r--r--src/test/resources/accordion/SimpleSolvable.json3
-rw-r--r--src/test/resources/accordion/SimpleUnsolvable.json3
21 files changed, 352 insertions, 12 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 508b6de..00fc75c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -67,6 +67,7 @@ set(sources_test
src/test/integration_tests/spider_test.cpp
src/test/integration_tests/klondike_test.cpp
src/test/integration_tests/gaps_test.cpp
+ src/test/integration_tests/accordion_test.cpp
src/test/unit_tests/global_cache_test.cpp
src/test/unit_tests/foundations_dominance_test.cpp
src/test/unit_tests/deal_parser_test.cpp
diff --git a/src/main/evaluation/solvability_calc.cpp b/src/main/evaluation/solvability_calc.cpp
index 1f1e76b..16c10c0 100644
--- a/src/main/evaluation/solvability_calc.cpp
+++ b/src/main/evaluation/solvability_calc.cpp
@@ -281,7 +281,7 @@ solvability_calc::sol_result solvability_calc::solve_seed(int seed, millisec tim
// SEED RESULTS CLASS //
////////////////////////
-solvability_calc::seed_results::seed_results(vector<int> v) : solvable(v[0]), unsolvable(v[1]), timed_out(v[2]) {
+solvability_calc::seed_results::seed_results(vector<int> v) : solvable(v[0]), unsolvable(v[1]), timed_out(v[2]), mem_limit(0) {
}
void solvability_calc::seed_results::add_result(sol_result::type t) {
diff --git a/src/main/game/global_cache.cpp b/src/main/game/global_cache.cpp
index e24cb4c..90d962d 100644
--- a/src/main/game/global_cache.cpp
+++ b/src/main/game/global_cache.cpp
@@ -73,6 +73,10 @@ cached_game_state::cached_game_state(const game_state& gs) : live(true) {
add_pile(pr, gs);
add_card_divider();
}
+
+ for (pile::ref pr : gs.accordion) {
+ add_card(gs.piles[pr].top_card(), gs);
+ }
}
diff --git a/src/main/game/move.h b/src/main/game/move.h
index 3e96733..8250609 100644
--- a/src/main/game/move.h
+++ b/src/main/game/move.h
@@ -8,7 +8,7 @@
#include "pile.h"
struct move {
- enum class mtype : uint8_t {regular, dominance, built_group, stock_k_plus, stock_to_all_tableau, sequence, null};
+ enum class mtype : uint8_t {regular, dominance, built_group, stock_k_plus, stock_to_all_tableau, sequence, accordion, null};
explicit move(mtype, pile::ref = 255 , pile::ref = 255, int8_t = 1, bool reveal_move_ = false, bool flip_waste_ = false);
friend bool operator==(const move&, const move&);
diff --git a/src/main/game/search-state/game_state.cpp b/src/main/game/search-state/game_state.cpp
index b61be3b..0388d9c 100644
--- a/src/main/game/search-state/game_state.cpp
+++ b/src/main/game/search-state/game_state.cpp
@@ -98,6 +98,15 @@ game_state::game_state(const sol_rules& s_rules, streamliner_options stream_opts
}
}
+ // If there is a reserve, creates piles
+ if (rules.accordion_size > 0) {
+ uint8_t pile_count = rules.accordion_size;
+ for (uint8_t i = 0; i < pile_count; i++) {
+ piles.emplace_back();
+ accordion.push_back(static_cast<pile::ref>(piles.size() - 1));
+ }
+ }
+
// Creates the tableau piles
for (uint8_t i = 0; i < rules.tableau_pile_count; i++) {
piles.emplace_back();
@@ -173,6 +182,14 @@ game_state::game_state(const sol_rules& s_rules, int seed, streamliner_options s
}
}
+ // Deals to the accordion
+ if (rules.accordion_size > 0) {
+ for (auto pr : accordion) {
+ place_card(pr, deck.back());
+ deck.pop_back();
+ }
+ }
+
// This only occurs during testing
if (rules.tableau_pile_count == 0) return;
@@ -288,6 +305,9 @@ void game_state::make_move(const move m) {
case move::mtype::sequence:
make_sequence_move(m);
break;
+ case move::mtype::accordion:
+ make_accordion_move(m);
+ break;
case move::mtype::null:
assert(false);
break;
@@ -316,6 +336,9 @@ void game_state::undo_move(const move m) {
case move::mtype::sequence:
undo_sequence_move(m);
break;
+ case move::mtype::accordion:
+ undo_accordion_move(m);
+ break;
case move::mtype::null:
assert(false);
break;
@@ -360,10 +383,8 @@ void game_state::undo_regular_move(const move m) {
}
void game_state::make_built_group_move(move m) {
- assert(rules.move_built_group);
assert(m.from < piles.size() );
assert(m.to < piles.size() );
- assert(m.count <= rules.max_rank);
// Adds the cards to the 'to' pile
for (auto pile_idx = m.count; pile_idx-- > 0;) {
@@ -383,9 +404,7 @@ void game_state::make_built_group_move(move m) {
}
void game_state::undo_built_group_move(move m) {
- assert(rules.move_built_group);
assert(m.to < piles.size());
- assert(m.count <= rules.max_rank);
if (m.reveal_move) {
assert(!piles[m.from].empty());
@@ -523,6 +542,16 @@ void game_state::undo_sequence_move(const move m) {
piles[from_seq_ref][from_card_idx] = to_card;
}
+void game_state::make_accordion_move(move m) {
+ make_built_group_move(m);
+ accordion.remove(m.from);
+}
+
+void game_state::undo_accordion_move(move m) {
+ accordion.insert(upper_bound(begin(accordion), end(accordion), m.from), m.from);
+ undo_built_group_move(m);
+}
+
// Places a card on a pile and if it is on a tableau, cell or reserve pile,
// reorders the pile refs so that the largest pile is first
void game_state::place_card(pile::ref pr, card c) {
@@ -578,9 +607,9 @@ bool game_state::is_solved() const {
} else if (rules.foundations_present) {
for (auto f : foundations) {
if (piles[f].size() != rules.max_rank) {
- solved = false;
- }
-}
+ solved = false;
+ }
+ }
} else if (rules.sequence_count > 0) {
for (pile::ref i = 0; i < sequences.size() && solved; i++) {
for (pile::ref j = piles[sequences[i]].size(); j-- > 2;) {
@@ -591,6 +620,8 @@ bool game_state::is_solved() const {
}
if (piles[sequences[i]].top_card() != "AS") solved = false;
}
+ } else if (rules.accordion_size > 0) {
+ return accordion.size() == 1;
} else {
assert(false);
}
diff --git a/src/main/game/search-state/game_state.h b/src/main/game/search-state/game_state.h
index 05f6974..cbd72b4 100644
--- a/src/main/game/search-state/game_state.h
+++ b/src/main/game/search-state/game_state.h
@@ -82,6 +82,8 @@ private:
void undo_stock_to_all_tableau_move(move move);
void make_sequence_move(move move);
void undo_sequence_move(move move);
+ void make_accordion_move(move move);
+ void undo_accordion_move(move move);
#ifndef NDEBUG
void check_face_down_consistent() const;
@@ -98,6 +100,7 @@ private:
void add_stock_to_hole_foundation_moves(std::vector<move>&) const;
card stock_card_from_count(int8_t) const;
void add_foundation_complete_piles_moves(std::vector<move> &) const;
+ void add_accordion_moves(std::vector<move>&) const;
bool is_valid_tableau_move(pile::ref, pile::ref) const;
bool is_valid_tableau_move(card, pile::ref) const;
@@ -117,6 +120,7 @@ private:
void add_sequence_moves(std::vector<move>&) const;
bool is_next_legal_card(sol_rules::build_policy, card, card) const;
+ bool is_next_legal_card(std::vector<sol_rules::accordion_policy>, card, card) const;
void turn_face_down_cards(std::vector<move>&) const;
/* Auto-foundation moves */
@@ -140,6 +144,7 @@ private:
std::list<pile::ref> reserve;
std::vector<pile::ref> foundations;
std::vector<pile::ref> sequences;
+ std::list<pile::ref> accordion;
pile::ref hole;
/* Pile references of starting/original layout */
diff --git a/src/main/game/search-state/game_state.legal_moves.cpp b/src/main/game/search-state/game_state.legal_moves.cpp
index 42d513a..e1cbc8e 100644
--- a/src/main/game/search-state/game_state.legal_moves.cpp
+++ b/src/main/game/search-state/game_state.legal_moves.cpp
@@ -18,6 +18,7 @@ using namespace rapidjson;
typedef sol_rules::build_policy pol;
typedef sol_rules::spaces_policy s_pol;
+typedef sol_rules::accordion_policy acc_pol;
typedef sol_rules::stock_deal_type sdt;
typedef sol_rules::face_up_policy fu;
typedef sol_rules::direction dir;
@@ -29,6 +30,7 @@ typedef sol_rules::direction dir;
// Note that the moves added last here, are tried first
vector<move> game_state::get_legal_moves(move parent_move) {
// Order:
+ // Accordion moves
// Foundations complete piles moves
// Tableau / cells / reserve / stock-waste to hole / foundation moves ---
// Cell to tableau moves
@@ -152,6 +154,9 @@ vector<move> game_state::get_legal_moves(move parent_move) {
if (rules.tableau_pile_count > 0 && rules.face_up != fu::ALL)
turn_face_down_cards(moves);
+ if (rules.accordion_size > 0)
+ add_accordion_moves(moves);
+
return moves;
}
@@ -466,6 +471,26 @@ void game_state::add_sequence_moves(std::vector<move>& moves) const {
}
}
+void game_state::add_accordion_moves(vector<move>& moves) const {
+ int idx = 0, idx_max = static_cast<int>(accordion.size());
+ for (auto from_it = begin(accordion); from_it != end(accordion); from_it++, idx++) {
+ for (pair<dir, uint8_t> move_rule : rules.accordion_moves) {
+ auto to_it = from_it;
+
+ if (move_rule.first == dir::LEFT && idx - move_rule.second >= 0) {
+ for (uint8_t i = 0; i < move_rule.second; i++) to_it--;
+ } else if (move_rule.first == dir::RIGHT && idx + move_rule.second < idx_max) {
+ for (uint8_t i = 0; i < move_rule.second; i++) to_it++;
+ } else {
+ continue;
+ }
+
+ if (is_next_legal_card(rules.accordion_pol, piles[*to_it].top_card(), piles[*from_it].top_card()))
+ moves.emplace_back(move::mtype::accordion, *from_it, *to_it, piles[*from_it].size());
+ }
+ }
+}
+
///////////////////////
@@ -484,6 +509,25 @@ bool game_state::is_next_legal_card(pol p, card a, card b) const {
return b.get_rank() + 1 == a.get_rank();
}
+bool game_state::is_next_legal_card(vector<acc_pol> vp, card a, card b) const {
+ for (auto p : vp) {
+ switch (p) {
+ case sol_rules::accordion_policy::SAME_RANK:
+ if (b.get_rank() == a.get_rank()) return true;
+ break;
+ case sol_rules::accordion_policy::SAME_SUIT:
+ if (b.get_suit() == a.get_suit()) return true;
+ break;
+ case sol_rules::accordion_policy::RED_BLACK:
+ if (b.get_colour() != a.get_colour()) return true;
+ break;
+ case sol_rules::accordion_policy::ANY_SUIT:
+ return true;
+ }
+ }
+ return false;
+}
+
void game_state::turn_face_down_cards(vector<move>& moves) const {
for (auto& m : moves) {
bool is_tableau_move = m.from >= original_tableau_piles.front() && m.from <= original_tableau_piles.back();
diff --git a/src/main/game/sol_rules.cpp b/src/main/game/sol_rules.cpp
index e9f4edf..0ea998e 100644
--- a/src/main/game/sol_rules.cpp
+++ b/src/main/game/sol_rules.cpp
@@ -34,5 +34,6 @@ sol_rules::sol_rules() :
face_up(fu::ALL),
sequence_count(0),
sequence_direction(dir::LEFT),
- sequence_build_pol(pol::SAME_SUIT) {
+ sequence_build_pol(pol::SAME_SUIT),
+ accordion_size(0) {
}
diff --git a/src/main/game/sol_rules.h b/src/main/game/sol_rules.h
index b03d854..0673771 100644
--- a/src/main/game/sol_rules.h
+++ b/src/main/game/sol_rules.h
@@ -6,6 +6,7 @@
#define SOLVITAIRE_SOL_RULES_H
#include <string>
+#include <vector>
#include "../../../lib/rapidjson/document.h"
@@ -24,6 +25,12 @@ struct sol_rules {
KINGS,
ANY
};
+ enum class accordion_policy {
+ SAME_RANK,
+ SAME_SUIT,
+ RED_BLACK,
+ ANY_SUIT
+ };
enum class stock_deal_type {
WASTE,
TABLEAU_PILES
@@ -62,6 +69,9 @@ struct sol_rules {
uint8_t sequence_count;
direction sequence_direction;
build_policy sequence_build_pol;
+ uint8_t accordion_size;
+ std::vector<std::pair<direction, uint8_t>> accordion_moves;
+ std::vector<accordion_policy> accordion_pol;
};
#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 998f337..7b8cf18 100644
--- a/src/main/input-output/input/json-parsing/deal_parser.cpp
+++ b/src/main/input-output/input/json-parsing/deal_parser.cpp
@@ -56,6 +56,11 @@ void deal_parser::parse(game_state &gs, const rapidjson::Document& doc) {
parse_sequences(gs, doc);
}
+ // Construct accordion
+ if (gs.rules.accordion_size > 0) {
+ parse_accordion(gs, doc);
+ }
+
// If the foundations begin with cards in them, fill them
if (gs.rules.foundations_present) {
bool supplied_foundations = parse_foundations(gs, doc);
@@ -109,7 +114,8 @@ string deal_parser::deal_schema_json() {
"hole": {"$ref": "#/definitions/card"},
"stock": {"$ref": "#/definitions/cardarray"},
"waste": {"$ref": "#/definitions/cardarray"},
- "reserve": {"$ref": "#/definitions/cardarray"}
+ "reserve": {"$ref": "#/definitions/cardarray"},
+ "accordion": {"$ref": "#/definitions/cardarray"}
}, "additionalProperties": false
}
@@ -236,6 +242,27 @@ void deal_parser::parse_sequences(game_state& gs, const rapidjson::Document& doc
}
}
+void deal_parser::parse_accordion(game_state &gs, const Document& doc) {
+ assert(doc.HasMember("accordion"));
+ const Value& json_accordion_piles = doc["accordion"];
+ assert(json_accordion_piles.IsArray());
+
+ const auto& json_card_arr = json_accordion_piles.GetArray();
+
+ // We treat a regular reserve like multiple single-card piles,
+ // but a stacked reserve as a single multiple-card pile
+ if (json_card_arr.Size() != gs.rules.accordion_size) {
+ json_helper::json_parse_err("Incorrect accordion size");
+ }
+
+ auto acc_it = begin(gs.accordion);
+ for (pile::ref i = 0; i < json_card_arr.Size(); i++, acc_it++) {
+ assert(json_card_arr[i].IsString());
+ pile::ref pr = *acc_it;
+ gs.place_card(pr, card(json_card_arr[i].GetString()));
+ }
+}
+
bool deal_parser::parse_foundations(game_state &gs, const rapidjson::Document& doc) {
if (!doc.HasMember("foundations")) return false;
diff --git a/src/main/input-output/input/json-parsing/deal_parser.h b/src/main/input-output/input/json-parsing/deal_parser.h
index bce4a29..36f58d5 100644
--- a/src/main/input-output/input/json-parsing/deal_parser.h
+++ b/src/main/input-output/input/json-parsing/deal_parser.h
@@ -24,6 +24,7 @@ public:
static void parse_waste(game_state&, const rapidjson::Document&);
static void parse_reserve(game_state&, const rapidjson::Document&);
static void parse_sequences(game_state&, const rapidjson::Document&);
+ static void parse_accordion(game_state&, const rapidjson::Document&);
static bool parse_foundations(game_state&, const rapidjson::Document&);
static void fill_foundations(game_state&);
static std::string deal_schema_json();
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 e3c4601..b70abdf 100644
--- a/src/main/input-output/input/json-parsing/rules_parser.cpp
+++ b/src/main/input-output/input/json-parsing/rules_parser.cpp
@@ -20,6 +20,7 @@ using namespace rapidjson;
typedef sol_rules::build_policy pol;
typedef sol_rules::spaces_policy s_pol;
+typedef sol_rules::accordion_policy acc_pol;
typedef sol_rules::stock_deal_type sdt;
typedef sol_rules::face_up_policy fu;
typedef sol_rules::direction dir;
@@ -306,6 +307,66 @@ void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) {
}
}
+ if (d.HasMember("accordion")) {
+ if (d["accordion"].IsObject()) {
+ if (d["accordion"].HasMember("size")) {
+ if (d["accordion"]["size"].IsInt()) {
+ sr.accordion_size = static_cast<uint8_t>(d["accordion"]["size"].GetInt());
+ } else {
+ json_helper::json_parse_err("[size] must be an integer");
+ }
+ }
+
+ if (d["accordion"].HasMember("moves")) {
+ if (d["accordion"]["moves"].IsArray()) {
+ for (auto& json_move : d["accordion"]["moves"].GetArray()) {
+ string move_str = json_move.GetString();
+
+ sol_rules::direction move_dir;
+ if (move_str[0] == 'L') {
+ move_dir = sol_rules::direction::LEFT;
+ } else if (move_str[0] == 'R') {
+ move_dir = sol_rules::direction::RIGHT;
+ } else {
+ json_helper::json_parse_err(R"([accordion][moves] must begin 'L' or 'R')");
+ }
+
+ auto count_str = move_str.substr(1, move_str.size() - 1);
+ auto count = static_cast<uint8_t>(stoi(count_str));
+
+ sr.accordion_moves.emplace_back(move_dir, count);
+ }
+ } else {
+ json_helper::json_parse_err("[accordion][moves] must be an array");
+ }
+ }
+
+ if (d["accordion"].HasMember("build policies")) {
+ if (d["accordion"]["build policies"].IsArray()) {
+ for (auto& json_policy : d["accordion"]["build policies"].GetArray()) {
+ string policy_str = json_policy.GetString();
+
+ if (policy_str == "any-suit") {
+ sr.accordion_pol.emplace_back(acc_pol::ANY_SUIT);
+ } else if (policy_str == "red-black") {
+ sr.accordion_pol.emplace_back(acc_pol::RED_BLACK);
+ } else if (policy_str == "same-suit") {
+ sr.accordion_pol.emplace_back(acc_pol::SAME_SUIT);
+ } else if (policy_str == "same-rank") {
+ sr.accordion_pol.emplace_back(acc_pol::SAME_RANK);
+ } else {
+ json_helper::json_parse_err("[accordion][build policies] is invalid");
+ }
+ }
+ } else {
+ json_helper::json_parse_err("[accordion][build policies] must be an array");
+ }
+ }
+ } else {
+ json_helper::json_parse_err("[accordion] must be an object");
+ }
+ }
+
if (d.HasMember("sequences")) {
if (d["sequences"].IsObject()) {
if (d["sequences"].HasMember("count")) {
@@ -379,8 +440,9 @@ void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) {
if (sr.hole) solution_types++;
if (sr.foundations_present) solution_types++;
if (sr.sequence_count > 0) solution_types++;
+ if (sr.accordion_size > 0) solution_types++;
if (solution_types != 1) {
- json_helper::json_parse_err("one and only one of [hole], [foundations] and [sequences][count] > 0 "
+ json_helper::json_parse_err("one and only one of [hole], [foundations], [accordion][size] > 0 and [sequences][count] > 0 "
"must be true");
}
@@ -514,6 +576,34 @@ string rules_parser::rules_schema_json() {
},
"additionalProperties": false
},
+ "accordion": {
+ "type": "object",
+ "properties": {
+ "size": {
+ "type": "integer",
+ "minimum": 0
+ },
+ "moves": {
+ "items": {
+ "type": "string",
+ "pattern": "^((L|R)([1-9]|[1-4][0-9]|5[0-2]))$"
+ }
+ },
+ "build policies": {
+ "type": "array",
+ "items": {
+ "type": "string",
+ "enum": [
+ "same-suit",
+ "red-black",
+ "any-suit",
+ "same-rank"
+ ]
+ }
+ }
+ },
+ "additionalProperties": false
+ },
"sequences": {
"type": "object",
"properties": {
diff --git a/src/main/input-output/input/sol_preset_types.cpp b/src/main/input-output/input/sol_preset_types.cpp
index 88ebb5f..0c96651 100644
--- a/src/main/input-output/input/sol_preset_types.cpp
+++ b/src/main/input-output/input/sol_preset_types.cpp
@@ -47,6 +47,11 @@ map<string, string> sol_preset_types::mp = {
"size": 0,
"stacked": false
},
+ "accordion": {
+ "size": 0,
+ "moves": [],
+ "build policies": []
+ },
"sequences": {
"count": 0,
"direction": "L",
@@ -1083,6 +1088,66 @@ map<string, string> sol_preset_types::mp = {
}
)"
+ },
+ {
+ "simple-accordion",
+
+ R"(
+{
+ "foundations": {
+ "present": false
+ },
+ "tableau piles": {
+ "count": 0
+ },
+ "accordion": {
+ "size": 10,
+ "moves": ["L1", "L3"],
+ "build policies": ["same-suit", "same-rank"]
+ }
+}
+)"
+
+ },
+ {
+ "accordion-knuth",
+
+ R"(
+{
+ "foundations": {
+ "present": false
+ },
+ "tableau piles": {
+ "count": 0
+ },
+ "accordion": {
+ "size": 18,
+ "moves": ["L1", "L3"],
+ "build policies": ["same-suit", "same-rank"]
+ }
+}
+)"
+
+ },
+ {
+ "accordion",
+
+ R"(
+{
+ "foundations": {
+ "present": false
+ },
+ "tableau piles": {
+ "count": 0
+ },
+ "accordion": {
+ "size": 52,
+ "moves": ["L1", "L3"],
+ "build policies": ["same-suit", "same-rank"]
+ }
+}
+)"
+
}
};
diff --git a/src/main/input-output/output/state_printer.cpp b/src/main/input-output/output/state_printer.cpp
index e48ed51..3f1978b 100644
--- a/src/main/input-output/output/state_printer.cpp
+++ b/src/main/input-output/output/state_printer.cpp
@@ -6,6 +6,7 @@
using std::ostream;
using std::vector;
+using std::list;
typedef sol_rules::stock_deal_type sdt;
@@ -47,6 +48,10 @@ ostream& state_printer::print(ostream& stream, const game_state& gs) {
state_printer::print_header(stream, "Sequences");
state_printer::print_sequences(stream, gs.sequences, gs);
}
+ if (gs.rules.accordion_size > 0) {
+ state_printer::print_header(stream, "Accordion");
+ state_printer::print_accordion(stream, gs.accordion, gs);
+ }
return stream << "===================================";
}
@@ -129,6 +134,16 @@ void state_printer::print_top_of_piles(ostream& stream,
stream << "\n";
}
+void state_printer::print_accordion(ostream& stream,
+ const list<pile::ref>& vp,
+ const game_state& gs) {
+ for (pile::ref p : vp) {
+ print_card(stream, gs.piles[p].top_card());
+ stream << "\t";
+ }
+ stream << "\n";
+}
+
void state_printer::print_top_of_pile(ostream& stream,
const pile::ref pile_r,
const game_state& gs) {
@@ -160,6 +175,9 @@ void state_printer::print_move(std::ostream& s, const move m) {
case move::mtype::sequence:
s << "sequence";
break;
+ case move::mtype::accordion:
+ s << "accordion";
+ break;
case move::mtype::null:
s << "null";
break;
diff --git a/src/main/input-output/output/state_printer.h b/src/main/input-output/output/state_printer.h
index 7e01aea..575b973 100644
--- a/src/main/input-output/output/state_printer.h
+++ b/src/main/input-output/output/state_printer.h
@@ -27,6 +27,8 @@ private:
const game_state&);
static void print_top_of_pile(std::ostream&, pile::ref,
const game_state&);
+ static void print_accordion(std::ostream&, const std::list<pile::ref>&,
+ const game_state&);
static void print_card(std::ostream&, card);
};
diff --git a/src/main/solver/solver.cpp b/src/main/solver/solver.cpp
index 3bfd6bd..4059b5b 100644
--- a/src/main/solver/solver.cpp
+++ b/src/main/solver/solver.cpp
@@ -136,6 +136,7 @@ bool solver::revert_to_last_node_with_children(optional<lru_cache::item_list::it
if (current_node->mv.type != move::mtype::dominance) {
if (cache.get_states_removed_from_cache() == 0) {
+ LOG_DEBUG(state); // TODO
assert(cache.contains(state));
}
LOG_DEBUG("(undo move)");
diff --git a/src/test/integration_tests/accordion_test.cpp b/src/test/integration_tests/accordion_test.cpp
new file mode 100644
index 0000000..bd27dec
--- /dev/null
+++ b/src/test/integration_tests/accordion_test.cpp
@@ -0,0 +1,28 @@
+//
+// Created by thecharlesblake on 10/4/17.
+//
+
+#include <gtest/gtest.h>
+
+#include "../test_helper.h"
+
+typedef test_helper th;
+
+const static std::string path = "resources/accordion/";
+const static std::string type = "simple-accordion";
+
+TEST(Accordion, SimpleSolvable) {
+ EXPECT_TRUE(th::is_solvable(path + "SimpleSolvable.json", type));
+}
+
+TEST(Accordion, ComplexSolvable) {
+ EXPECT_TRUE(th::is_solvable(path + "ComplexSolvable.json", type));
+}
+
+TEST(Accordion, SimpleUnsolvable) {
+ EXPECT_FALSE(th::is_solvable(path + "SimpleUnsolvable.json", type));
+}
+
+TEST(Accordion, ComplexUnsolvable) {
+ EXPECT_FALSE(th::is_solvable(path + "ComplexUnsolvable.json", type));
+}
diff --git a/src/test/resources/accordion/ComplexSolvable.json b/src/test/resources/accordion/ComplexSolvable.json
new file mode 100644
index 0000000..cdb2367
--- /dev/null
+++ b/src/test/resources/accordion/ComplexSolvable.json
@@ -0,0 +1,3 @@
+{
+ "accordion": ["AC","3H","AH","2S","AD","3S","3C","AS","2C","3D"]
+}
diff --git a/src/test/resources/accordion/ComplexUnsolvable.json b/src/test/resources/accordion/ComplexUnsolvable.json
new file mode 100644
index 0000000..09c7d32
--- /dev/null
+++ b/src/test/resources/accordion/ComplexUnsolvable.json
@@ -0,0 +1,3 @@
+{
+ "accordion": ["AD","AS","AH","2S","3C","3S","4C","3H","2C","4D"]
+} \ No newline at end of file
diff --git a/src/test/resources/accordion/SimpleSolvable.json b/src/test/resources/accordion/SimpleSolvable.json
new file mode 100644
index 0000000..00de391
--- /dev/null
+++ b/src/test/resources/accordion/SimpleSolvable.json
@@ -0,0 +1,3 @@
+{
+ "accordion": ["AC","AS","AH","2C","2S","2H","3C","3S","3H","4C"]
+} \ No newline at end of file
diff --git a/src/test/resources/accordion/SimpleUnsolvable.json b/src/test/resources/accordion/SimpleUnsolvable.json
new file mode 100644
index 0000000..2e1b9c3
--- /dev/null
+++ b/src/test/resources/accordion/SimpleUnsolvable.json
@@ -0,0 +1,3 @@
+{
+ "accordion": ["AC","4S","AH","2S","AD","3S","4C","3H","2C","3D"]
+}