From 83891829f32dcc94db7c73894c04e88ffcd657c3 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Mon, 6 Nov 2017 15:13:05 +0000 Subject: Add FC (reg & simple) to cmdln parsing & sol_rules --- src/main/sol_rules.cpp | 29 ++++++++++++++++++++--------- src/main/sol_rules.h | 5 ++++- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/main/sol_rules.cpp b/src/main/sol_rules.cpp index eded5eb..de56254 100644 --- a/src/main/sol_rules.cpp +++ b/src/main/sol_rules.cpp @@ -19,7 +19,9 @@ vector sol_rules::valid_sol_strs = { "black-hole", "simple-black-hole", "spanish-patience", - "simple-spanish-patience" + "simple-spanish-patience", + "free-cell", + "simple-free-cell" }; bool sol_rules::is_suit(pol bp) { @@ -40,14 +42,21 @@ int sol_rules::suit_val(pol bp) { sol_rules::sol_rules(std::string sol_type) { valid_sol vs = valid_sol_enum(sol_type); + // Default game values + build_ord = build_order::DESCENDING; + max_rank = 13; + hole = false; + foundations = true; + cells = 0; + // Game-specific values switch(vs) { case valid_sol::BLACK_HOLE: tableau_pile_count = 17; build_ord = build_order::NO_BUILD; - max_rank = 13; hole = true; foundations = false; + cells = 0; break; case valid_sol::SIMPLE_BLACK_HOLE: tableau_pile_count = 9; @@ -58,17 +67,19 @@ sol_rules::sol_rules(std::string sol_type) { break; case valid_sol::SPANISH_PATIENCE: tableau_pile_count = 13; - build_ord = build_order::DESCENDING; - max_rank = 13; - hole = false; - foundations = true; break; case valid_sol::SIMPLE_SPANISH_PATIENCE: tableau_pile_count = 5; - build_ord = build_order::DESCENDING; max_rank = 5; - hole = false; - foundations = true; + break; + case valid_sol::FREE_CELL: + tableau_pile_count = 8; + cells = 4; + break; + case valid_sol::SIMPLE_FREE_CELL: + tableau_pile_count = 4; + max_rank = 4; + cells = 1; break; default: assert(false); diff --git a/src/main/sol_rules.h b/src/main/sol_rules.h index 671e8b7..aabb57c 100644 --- a/src/main/sol_rules.h +++ b/src/main/sol_rules.h @@ -14,7 +14,9 @@ public: BLACK_HOLE, SIMPLE_BLACK_HOLE, SPANISH_PATIENCE, - SIMPLE_SPANISH_PATIENCE + SIMPLE_SPANISH_PATIENCE, + FREE_CELL, + SIMPLE_FREE_CELL }; enum class build_order { NO_BUILD, @@ -42,6 +44,7 @@ public: int max_rank; bool hole; bool foundations; + int cells; private: static valid_sol valid_sol_enum(const std::string&); -- cgit v1.2.1 From f91cd251fd40d927254246e9276924af3e046dd1 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Mon, 6 Nov 2017 15:35:10 +0000 Subject: Add cells to game state and next state generation --- src/main/game_state.cpp | 14 +++++++++++++- src/main/game_state.h | 1 + src/main/pile.cpp | 2 ++ src/main/sol_rules.h | 3 ++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/game_state.cpp b/src/main/game_state.cpp index 29ccdc3..2dd1ca8 100644 --- a/src/main/game_state.cpp +++ b/src/main/game_state.cpp @@ -55,7 +55,7 @@ game_state::game_state(int seed, const sol_rules& s_rules) hole(false, ord::BOTH, pol::ANY_SUIT, true, rules.max_rank) { vector deck = shuffled_deck(seed, rules.max_rank); - // If there is a hole, move the ace to spades to it + // If there is a hole, move the ace of spades to it if (rules.hole) { deck.erase(find(begin(deck), end(deck), card("AS"))); hole.place("AS"); @@ -82,6 +82,14 @@ game_state::game_state(int seed, const sol_rules& s_rules) foundations.push_back(p); } } + + // If there are cell piles, create the relevant cell vectors + if (rules.cells > 0) { + for (int i = 0; i < rules.cells; i++) { + pile p(true, ord::SINGLE_CARD, pol::ANY_SUIT, false); + foundations.push_back(p); + } + } } // Generate a randomly ordered vector of cards @@ -129,6 +137,10 @@ vector game_state::get_next_legal_states() { can_add.push_back(&foundations[i]); } } + for (vector::size_type i = 0; i < cells.size(); i++) { + can_remove.push_back(&cells[i]); + can_add.push_back(&cells[i]); + } if (rules.hole) { can_add.push_back(&hole); } diff --git a/src/main/game_state.h b/src/main/game_state.h index 311c97f..bb98ee3 100644 --- a/src/main/game_state.h +++ b/src/main/game_state.h @@ -40,6 +40,7 @@ private: void print_hole(std::ostream&) const; std::vector tableau_piles; + std::vector cells; std::vector foundations; sol_rules rules; pile hole; diff --git a/src/main/pile.cpp b/src/main/pile.cpp index cceda50..344e56c 100644 --- a/src/main/pile.cpp +++ b/src/main/pile.cpp @@ -34,6 +34,8 @@ bool pile::can_place(const card& c) const { if (build_order == ord::NO_BUILD) { return false; + } else if (build_order == ord::SINGLE_CARD) { + return empty(); } if (empty()) { diff --git a/src/main/sol_rules.h b/src/main/sol_rules.h index aabb57c..5699ef1 100644 --- a/src/main/sol_rules.h +++ b/src/main/sol_rules.h @@ -22,7 +22,8 @@ public: NO_BUILD, DESCENDING, ASCENDING, - BOTH + BOTH, + SINGLE_CARD }; enum class build_policy { CLUBS, -- cgit v1.2.1 From cbea9f4b5f83f1745ab7ff01b94eb96412f8e035 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Mon, 6 Nov 2017 15:40:39 +0000 Subject: Add cell printing --- src/main/game_state.cpp | 11 +++++++++++ src/main/game_state.h | 1 + 2 files changed, 12 insertions(+) diff --git a/src/main/game_state.cpp b/src/main/game_state.cpp index 2dd1ca8..90a7381 100644 --- a/src/main/game_state.cpp +++ b/src/main/game_state.cpp @@ -181,6 +181,10 @@ ostream& game_state::print(ostream& stream) const { print_header(stream, "Foundations"); print_foundations(stream); } + if (rules.cells) { + print_header(stream, "Cells"); + print_cells(stream); + } if (rules.tableau_pile_count > 0) { print_header(stream, "Tableau Piles"); print_tableau_piles(stream); @@ -208,6 +212,13 @@ void game_state::print_foundations(ostream& stream) const { << foundations[3] << "\n"; } +void game_state::print_cells(ostream& stream) const { + for (pile cell : cells) { + if (!cell.empty()) stream << cells[0] << "\t"; + } + stream << "\n"; +} + void game_state::print_tableau_piles(ostream& stream) const { bool empty_row = false; vector::size_type row_idx = 0; diff --git a/src/main/game_state.h b/src/main/game_state.h index bb98ee3..97a1bec 100644 --- a/src/main/game_state.h +++ b/src/main/game_state.h @@ -36,6 +36,7 @@ private: void print_header(std::ostream&, const char*) const; void print_foundations(std::ostream&) const; + void print_cells(std::ostream&) const; void print_tableau_piles(std::ostream&) const; void print_hole(std::ostream&) const; -- cgit v1.2.1 From dfa640b05e1f6bc0c8dcc74ea857159703c10b20 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Mon, 6 Nov 2017 16:06:45 +0000 Subject: Fixup cell/foundation mixup and printing errs --- src/main/game_state.cpp | 13 +++++++++++-- src/main/sol_rules.cpp | 4 ++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/game_state.cpp b/src/main/game_state.cpp index 90a7381..05bfb4f 100644 --- a/src/main/game_state.cpp +++ b/src/main/game_state.cpp @@ -87,7 +87,7 @@ game_state::game_state(int seed, const sol_rules& s_rules) if (rules.cells > 0) { for (int i = 0; i < rules.cells; i++) { pile p(true, ord::SINGLE_CARD, pol::ANY_SUIT, false); - foundations.push_back(p); + cells.push_back(p); } } } @@ -173,6 +173,11 @@ bool game_state::is_solved() const { return false; } } + for (auto p : cells) { + if (!p.empty()) { + return false; + } + } return true; } @@ -214,7 +219,11 @@ void game_state::print_foundations(ostream& stream) const { void game_state::print_cells(ostream& stream) const { for (pile cell : cells) { - if (!cell.empty()) stream << cells[0] << "\t"; + if (cells.empty()) { + stream << "[]" << "\t"; + } else { + stream << cells[0] << "\t"; + } } stream << "\n"; } diff --git a/src/main/sol_rules.cpp b/src/main/sol_rules.cpp index de56254..b98e96d 100644 --- a/src/main/sol_rules.cpp +++ b/src/main/sol_rules.cpp @@ -77,8 +77,8 @@ sol_rules::sol_rules(std::string sol_type) { cells = 4; break; case valid_sol::SIMPLE_FREE_CELL: - tableau_pile_count = 4; - max_rank = 4; + tableau_pile_count = 3; + max_rank = 3; cells = 1; break; default: -- cgit v1.2.1