From 1e06a9a1998b22c1c6faae44c7badfee4c72e75a Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Tue, 26 Jun 2018 12:16:18 +0100 Subject: Add klondike unit tests --- src/main/input-output/input/sol_preset_types.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/main') diff --git a/src/main/input-output/input/sol_preset_types.cpp b/src/main/input-output/input/sol_preset_types.cpp index a10df54..9564bcc 100644 --- a/src/main/input-output/input/sol_preset_types.cpp +++ b/src/main/input-output/input/sol_preset_types.cpp @@ -359,6 +359,25 @@ map sol_preset_types::mp = { }, + { + "simple-klondike", + + R"( +{ + "tableau piles": { + "count": 4, + "build policy": "red-black", + "move built group": true, + "diagonal deal": true, + "face up cards": "top" + }, + "max rank": 4, + "stock size": 6, + "stock deal count": 3, + "stock redeal": true +} +)" + }, // --- END OF 'CANONICAL' GAMES --- { -- cgit v1.2.1 From c84d8ccf133bc49c44c185dac7b49a46b8878ec1 Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Thu, 28 Jun 2018 14:19:31 +0100 Subject: Implement to pass unit tests --- src/main/game/move.cpp | 2 +- src/main/game/search-state/game_state.cpp | 31 ++++++++++-- .../game/search-state/game_state.legal_moves.cpp | 56 ++++++++++++++++++++-- 3 files changed, 81 insertions(+), 8 deletions(-) (limited to 'src/main') diff --git a/src/main/game/move.cpp b/src/main/game/move.cpp index 9e45c66..c51a120 100644 --- a/src/main/game/move.cpp +++ b/src/main/game/move.cpp @@ -8,7 +8,7 @@ move::move(mtype ty, pile::ref f, pile::ref t, pile::size_type i, bool reveal_mo type(ty), from(f), to(t), count(i), reveal_move(reveal_move_) { #ifndef NDEBUG if (ty == mtype::regular) assert(i == 1); - else assert(i >= 1); + else if (ty != mtype::stock_to_waste) assert(i >= 1); #endif } diff --git a/src/main/game/search-state/game_state.cpp b/src/main/game/search-state/game_state.cpp index 7870b1b..d974c26 100644 --- a/src/main/game/search-state/game_state.cpp +++ b/src/main/game/search-state/game_state.cpp @@ -385,16 +385,39 @@ void game_state::undo_built_group_move(move m) { void game_state::make_stock_to_waste_move(const move m) { assert(rules.stock_deal_t == sdt::WASTE); - for (int i = 0; i < m.count; i++) { - place_card(waste, take_card(stock)); + // Index of the card to be moved + auto count = m.count % (piles[stock].size() + piles[waste].size()); + + for (int i = 0; i <= count; i++) { + if (i < count) place_card(waste, take_card(stock)); + else place_card(m.to, take_card(stock)); + + if (rules.stock_redeal) { + // If the stock is empty, flips it + // (invariant: no search state has an empty stock if rules.stock_size > 0 && rules.stock_redeal) + if (piles[stock].empty()) + while (!piles[waste].empty()) + place_card(stock, take_card(waste)); + } } } void game_state::undo_stock_to_waste_move(const move m) { assert(rules.stock_deal_t == sdt::WASTE); - for (int i = 0; i < m.count; i++) { - place_card(stock, take_card(waste)); + auto count = m.count % (piles[stock].size() + piles[waste].size() + 1); + + for (int i = count; i >= 0; i--) { + if (rules.stock_redeal) { + // If the waste is empty, flips it + // (invariant: no search state has an empty stock if rules.stock_size > 0 && rules.stock_redeal) + if (piles[waste].empty()) + while (!piles[stock].empty()) + place_card(waste, take_card(stock)); + } + + if (i < count) place_card(stock, take_card(waste)); + else place_card(stock, take_card(m.to )); } } 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 9ad8b1d..fd71e5c 100644 --- a/src/main/game/search-state/game_state.legal_moves.cpp +++ b/src/main/game/search-state/game_state.legal_moves.cpp @@ -4,12 +4,15 @@ #include "game_state.h" #include "../sol_rules.h" +#include "../move.h" #include using std::vector; using std::min; using std::list; +using std::pair; +using std::set; using namespace rapidjson; typedef sol_rules::build_policy pol; @@ -88,7 +91,10 @@ vector game_state::get_legal_moves(move parent_move) { } // Waste to tableau moves - if (rules.stock_size > 0 && rules.stock_deal_t == sdt::WASTE && !piles[waste].empty()) { + if (rules.stock_size > 0 + && rules.stock_deal_t == sdt::WASTE + && !rules.stock_redeal + && !piles[waste].empty()) { for (auto t : tableau_piles) { if (is_valid_tableau_move(waste, t)) { moves.emplace_back(move::mtype::regular, waste, t); @@ -234,8 +240,52 @@ bool game_state::is_foundation(pile::ref ref) const { } void game_state::add_stock_to_waste_move(std::vector& moves) const { - uint8_t cards_to_move = min(rules.stock_deal_count, piles[stock].size()); - moves.emplace_back(move::mtype::stock_to_waste, stock, waste, cards_to_move); + set stock_moves_to_check; + + // Adds multiples of deal count (excluding last card) + for (auto i = static_cast(rules.stock_deal_count - 1); + i < piles[stock].size() - 1; + i += rules.stock_deal_count) { + stock_moves_to_check.insert(i); + } + + // Adds last card + stock_moves_to_check.insert(static_cast(piles[stock].size() - 1)); + + // If the stock can be redealt, searches through the waste then the stock again + if (rules.stock_redeal) { + auto stock_waste_sz = piles[waste].size() + piles[stock].size(); + for (auto i = piles[stock].size() - 1 + rules.stock_deal_count; + i < piles[stock].size() + stock_waste_sz - 1; + i += rules.stock_deal_count) { + stock_moves_to_check.insert(static_cast(i % stock_waste_sz)); + } + } + + // TODO: invariant -> no waste moves if redeal + // TODO: invariant -> count always < stock+waste + + // For each stock move to check, if it can be moved legally to one of the tableau + // piles, adds this as a move + for (auto i : stock_moves_to_check) { + card from; + // If we are moving from the waste in a readeal (by looping), finds the correct card + if (i < piles[stock].size()) { + from = piles[stock][i]; + } else { + auto _i = static_cast(piles[stock].size() + piles[waste].size() - 1 - i); + from = piles[waste][_i]; + } + + for (auto t : tableau_piles) { + bool valid_move = piles[t].empty() + ? true + : is_next_tableau_card(piles[t].top_card(), from); + + if (valid_move) + moves.emplace_back(move::mtype::stock_to_waste, stock, t, i); + } + } } void game_state::add_tableau_moves(std::vector& moves, pile::ref rem_ref) const { -- cgit v1.2.1 From 5fde1f9563c98e2d661ac495e448d35eeb97e68c Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Fri, 29 Jun 2018 11:34:09 +0100 Subject: Fix bugs + correct built pile kings. Cell + founds --- src/main/game/move.cpp | 2 +- src/main/game/move.h | 2 +- src/main/game/search-state/game_state.cpp | 72 +++---- src/main/game/search-state/game_state.h | 30 +-- .../game/search-state/game_state.legal_moves.cpp | 231 +++++++++------------ 5 files changed, 148 insertions(+), 189 deletions(-) (limited to 'src/main') diff --git a/src/main/game/move.cpp b/src/main/game/move.cpp index c51a120..915bac6 100644 --- a/src/main/game/move.cpp +++ b/src/main/game/move.cpp @@ -8,7 +8,7 @@ move::move(mtype ty, pile::ref f, pile::ref t, pile::size_type i, bool reveal_mo type(ty), from(f), to(t), count(i), reveal_move(reveal_move_) { #ifndef NDEBUG if (ty == mtype::regular) assert(i == 1); - else if (ty != mtype::stock_to_waste) assert(i >= 1); + else if (ty != mtype::stock_k_plus) assert(i >= 1); #endif } diff --git a/src/main/game/move.h b/src/main/game/move.h index 8651d1e..5e6892f 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_to_waste, stock_to_tableau, redeal, null}; + enum class mtype : uint8_t {regular, dominance, built_group, stock_k_plus, stock_to_all_tableau, null}; explicit move(mtype, pile::ref = 255 , pile::ref = 255, pile::size_type = 1, bool reveal_move_ = 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 d974c26..276d582 100644 --- a/src/main/game/search-state/game_state.cpp +++ b/src/main/game/search-state/game_state.cpp @@ -257,14 +257,11 @@ void game_state::make_move(const move m) { case move::mtype::built_group: make_built_group_move(m); break; - case move::mtype::stock_to_waste: - make_stock_to_waste_move(m); + case move::mtype::stock_k_plus: + make_stock_k_plus_move(m); break; - case move::mtype::stock_to_tableau: - make_stock_to_tableau_move(m); - break; - case move::mtype::redeal: - make_redeal_move(); + case move::mtype::stock_to_all_tableau: + make_stock_to_all_tableau_move(m); break; case move::mtype::null: assert(false); @@ -285,14 +282,11 @@ void game_state::undo_move(const move m) { case move::mtype::built_group: undo_built_group_move(m); break; - case move::mtype::stock_to_waste: - undo_stock_to_waste_move(m); - break; - case move::mtype::stock_to_tableau: - undo_stock_to_tableau_move(m); + case move::mtype::stock_k_plus: + undo_stock_k_plus_move(m); break; - case move::mtype::redeal: - undo_redeal_move(); + case move::mtype::stock_to_all_tableau: + undo_stock_to_all_tableau_move(m); break; case move::mtype::null: assert(false); @@ -382,8 +376,14 @@ void game_state::undo_built_group_move(move m) { } } -void game_state::make_stock_to_waste_move(const move m) { +void game_state::make_stock_k_plus_move(const move m) { assert(rules.stock_deal_t == sdt::WASTE); + assert(m.count < piles[stock].size() + piles[waste].size()); + assert(!rules.stock_redeal || m.to != waste); +#ifndef NDEBUG + auto sz_before = piles[stock].size() + piles[waste].size(); +#endif + // if redeal -> stock tableau move implies s+w-=1 // Index of the card to be moved auto count = m.count % (piles[stock].size() + piles[waste].size()); @@ -400,10 +400,22 @@ void game_state::make_stock_to_waste_move(const move m) { place_card(stock, take_card(waste)); } } + +#ifndef NDEBUG + auto sz_after = piles[stock].size() + piles[waste].size(); + assert(sz_before == sz_after + 1); +#endif + assert(!(rules.stock_size > 0 && rules.stock_redeal && piles[stock].empty() && !piles[waste].empty())); + assert(piles[stock].size() <= rules.stock_size); } -void game_state::undo_stock_to_waste_move(const move m) { +void game_state::undo_stock_k_plus_move(move m) { assert(rules.stock_deal_t == sdt::WASTE); + assert(m.count < piles[stock].size() + piles[waste].size() + 1); + assert(!rules.stock_redeal || m.to != waste); +#ifndef NDEBUG + auto sz_after = piles[stock].size() + piles[waste].size(); +#endif auto count = m.count % (piles[stock].size() + piles[waste].size() + 1); @@ -419,9 +431,16 @@ void game_state::undo_stock_to_waste_move(const move m) { if (i < count) place_card(stock, take_card(waste)); else place_card(stock, take_card(m.to )); } + +#ifndef NDEBUG + auto sz_before = piles[stock].size() + piles[waste].size(); + assert(sz_before == sz_after + 1); +#endif + assert(!(rules.stock_size > 0 && rules.stock_redeal && piles[stock].empty() && !piles[waste].empty())); + assert(piles[stock].size() <= rules.stock_size); } -void game_state::make_stock_to_tableau_move(const move m) { +void game_state::make_stock_to_all_tableau_move(move m) { assert(rules.stock_deal_t == sdt::TABLEAU_PILES); for (pile::ref tab_pr = original_tableau_piles.front(); @@ -431,7 +450,7 @@ void game_state::make_stock_to_tableau_move(const move m) { } } -void game_state::undo_stock_to_tableau_move(const move m) { +void game_state::undo_stock_to_all_tableau_move(move m) { assert(rules.stock_deal_t == sdt::TABLEAU_PILES); for (pile::ref tab_pr = original_tableau_piles.front() + m.count; @@ -441,23 +460,6 @@ void game_state::undo_stock_to_tableau_move(const move m) { } } -void game_state::make_redeal_move() { - assert(piles[stock].empty()); - - // Re-deal waste back to stock - while (!piles[waste].empty()) { - place_card(stock, take_card(waste)); - } -} - -void game_state::undo_redeal_move() { - assert(piles[waste].empty()); - - while (!piles[stock].empty()) { - place_card(waste, take_card(stock)); - } -} - // 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) { diff --git a/src/main/game/search-state/game_state.h b/src/main/game/search-state/game_state.h index b8b0d03..f6f41d9 100644 --- a/src/main/game/search-state/game_state.h +++ b/src/main/game/search-state/game_state.h @@ -24,6 +24,7 @@ class game_state { friend class cached_game_state; friend class deal_parser; friend class state_printer; + friend class test_helper; public: /* Constructors */ @@ -73,12 +74,10 @@ private: void undo_regular_move(move move); void make_built_group_move(move move); void undo_built_group_move(move move); - void make_stock_to_waste_move(move move); - void undo_stock_to_waste_move(move move); - void make_stock_to_tableau_move(move move); - void undo_stock_to_tableau_move(move move); - void make_redeal_move(); - void undo_redeal_move(); + void make_stock_k_plus_move(move move); + void undo_stock_k_plus_move(move move); + void make_stock_to_all_tableau_move(move move); + void undo_stock_to_all_tableau_move(move move); #ifndef NDEBUG void check_face_down_consistent() const; @@ -86,23 +85,24 @@ private: /* Legal move generation */ - bool stock_can_deal_tableau() const; - move get_stock_tableau_move() const; - bool stock_can_redeal() const; - bool undoes_prev_move(pile::ref, move) const; - bool is_foundation(pile::ref) const; + bool stock_can_deal_all_tableau() const; + move get_stock_to_all_tableau_move() const; - void add_stock_to_waste_move(std::vector&) const; - void add_tableau_moves(std::vector&, pile::ref) const; - void add_cell_moves(std::vector&, pile::ref) const; - void add_foundation_moves(std::vector&, pile::ref) const; + std::set generate_stock_moves_to_check() const; + void add_stock_to_cell_move(std::vector&, pile::ref) const; + void add_stock_to_tableau_moves(std::vector&) const; + void add_stock_to_hole_foundation_moves(std::vector&) const; + card stock_card_from_index(pile::size_type) const; void add_built_group_moves(std::vector &) const; void add_foundation_complete_piles_moves(std::vector &) const; bool is_valid_tableau_move(pile::ref, pile::ref) const; + bool is_valid_tableau_move(card, pile::ref) const; bool is_next_tableau_card(card, card) const; bool is_valid_foundations_move(pile::ref, pile::ref) const; + bool is_valid_foundations_move(card, pile::ref) const; bool is_valid_hole_move(pile::ref) const; + bool is_valid_hole_move(card) const; pile::size_type get_built_group_height(pile::ref) const; void add_empty_built_group_moves(std::vector&, pile::ref, pile::ref, 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 fd71e5c..cadeca9 100644 --- a/src/main/game/search-state/game_state.legal_moves.cpp +++ b/src/main/game/search-state/game_state.legal_moves.cpp @@ -29,32 +29,23 @@ typedef sol_rules::face_up_policy fu; vector game_state::get_legal_moves(move parent_move) { // Order: // Foundations complete piles moves - // Tableau built group moves - // Tableau / cells / reserve to hole / foundation moves + // Tableau / cells / reserve / stock-waste to hole / foundation moves --- // Cell to tableau moves // Tableau to tableau moves - // Waste to tableau moves + // Tableau built group moves + // Stock-waste to tableau moves // Reserve to tableau moves // Foundation to tableau moves - // Tableau to cell moves - // Stock to waste moves - // Stock to tableau / redeal moves + // Tableau / stock-waste to cell moves + // Stock to all tableau moves vector moves; // Stock to tableau / redeal moves - if (rules.stock_size > 0) { - if (stock_can_deal_tableau()) - moves.emplace_back(get_stock_tableau_move()); - else if (stock_can_redeal()) - moves.emplace_back(move::mtype::redeal); - } + if (rules.stock_size > 0 && stock_can_deal_all_tableau()) + moves.emplace_back(get_stock_to_all_tableau_move()); - // Stock to waste moves - if (rules.stock_size > 0 && rules.stock_deal_t == sdt::WASTE && !piles[stock].empty()) - add_stock_to_waste_move(moves); - - // Tableau to cell moves + // Tableau / waste to cell moves pile::ref empty_cell = 255; for (auto c : cells) { if (piles[c].empty()) empty_cell = c; @@ -64,6 +55,9 @@ vector game_state::get_legal_moves(move parent_move) { if (piles[t].empty() || parent_move.to == t || !is_valid_tableau_move(t, empty_cell)) continue; else moves.emplace_back(move::mtype::regular, t, empty_cell); } + + if (rules.stock_size > 0 && rules.stock_deal_t == sdt::WASTE && !piles[stock].empty()) + add_stock_to_cell_move(moves, empty_cell); } // Foundation to tableau moves @@ -90,17 +84,12 @@ vector game_state::get_legal_moves(move parent_move) { } } - // Waste to tableau moves - if (rules.stock_size > 0 - && rules.stock_deal_t == sdt::WASTE - && !rules.stock_redeal - && !piles[waste].empty()) { - for (auto t : tableau_piles) { - if (is_valid_tableau_move(waste, t)) { - moves.emplace_back(move::mtype::regular, waste, t); - } - } - } + // Stock to tableau moves + if (rules.stock_size > 0 && rules.stock_deal_t == sdt::WASTE && !piles[stock].empty()) + add_stock_to_tableau_moves(moves); + + if (rules.move_built_group) + add_built_group_moves(moves); // Tableau to tableau moves for (auto t_from : tableau_piles) { @@ -124,8 +113,12 @@ vector game_state::get_legal_moves(move parent_move) { } } - // Tableau / cells to hole / foundation moves + // Tableau / cells / reserve / stock-waste to hole / foundation moves if (rules.hole || (rules.foundations && !rules.foundations_comp_piles)) { + // Stock + if (rules.stock_size > 0 && rules.stock_deal_t == sdt::WASTE && !piles[stock].empty()) + add_stock_to_hole_foundation_moves(moves); + list from_piles = tableau_piles; if (rules.cells > 0) from_piles.insert(from_piles.end(), cells.begin(), cells.end()); if (rules.reserve_size > 0) from_piles.insert(from_piles.end(), reserve.begin(), reserve.end()); @@ -141,60 +134,11 @@ vector game_state::get_legal_moves(move parent_move) { } } - if (rules.move_built_group) - add_built_group_moves(moves); - if (rules.foundations_comp_piles) // i.e. Spider-type winning condition add_foundation_complete_piles_moves(moves); - if (rules.face_up != fu::ALL) + if (rules.tableau_pile_count > 0 && rules.face_up != fu::ALL) turn_face_down_cards(moves); - /* - - vector moves; - - // Attempts stock tableau deal and redeal - if (rules.stock_size > 0) { - if (stock_can_deal_tableau()) - moves.emplace_back(get_stock_tableau_move()); - else if (stock_can_redeal()) - moves.emplace_back(move::mtype::redeal); - } - - // Cycles through all of the piles from which we want to remove cards - for (pile::ref rem_ref = 0; rem_ref < piles.size(); rem_ref++) { - if ((rules.hole && rem_ref == hole) || piles[rem_ref].empty()) - continue; - if (undoes_prev_move(rem_ref, parent_move)) - continue; - - if (rules.foundations && is_foundation(rem_ref)) { - if (!rules.foundations_removable) continue; - else if (dominance_blocks_foundation_move(rem_ref)) continue; - } - - if (rules.stock_size > 0 && rem_ref == stock) { - if (rules.stock_deal_t == sdt::WASTE) - add_stock_to_waste_move(moves); - continue; - } - - if (rules.cells > 0) - add_cell_moves(moves, rem_ref); - if (rules.tableau_pile_count > 0) - add_tableau_moves(moves, rem_ref); - if (rules.foundations) - add_foundation_moves(moves, rem_ref); - if (rules.hole && is_valid_hole_move(rem_ref)) - moves.emplace_back(move::mtype::regular, rem_ref, hole); - } - - if (rules.move_built_group) - add_built_group_moves(moves); - - if (rules.foundations_comp_piles) // I.E. Spider-type winning condition - add_foundation_complete_piles_moves(moves); -*/ return moves; } @@ -204,7 +148,7 @@ vector game_state::get_legal_moves(move parent_move) { // REGULAR MOVE GEN FUNCTIONS // //////////////////////////////// -bool game_state::stock_can_deal_tableau() const { +bool game_state::stock_can_deal_all_tableau() const { return rules.stock_deal_t == sdt::TABLEAU_PILES && !piles[stock].empty(); } @@ -212,34 +156,17 @@ bool game_state::stock_can_deal_tableau() const { // This is a special kind of move which the solver handles differently. // We must supply the number of stock cards // that we will deal, so that the move can be undone in backtracking. -move game_state::get_stock_tableau_move() const { +move game_state::get_stock_to_all_tableau_move() const { pile::size_type stock_moves = piles[stock].size() >= tableau_piles.size() ? pile::size_type(tableau_piles.size()) : piles[stock].size(); assert(stock_moves > 0 && stock_moves <= piles[stock].size()); - return move(move::mtype::stock_to_tableau, 0, 0, stock_moves); -} - -bool game_state::stock_can_redeal() const { - return rules.stock_redeal - && rules.stock_deal_t == sdt::WASTE - && piles[stock].empty() - && !piles[waste].empty(); -} - -bool game_state::undoes_prev_move(pile::ref rem_ref, move parent_move) const { - return rem_ref == parent_move.to - && parent_move.count == 1 - && parent_move.from != stock; -} - -bool game_state::is_foundation(pile::ref ref) const { - return ref >= foundations.front() && ref <= foundations.back(); + return move(move::mtype::stock_to_all_tableau, 0, 0, stock_moves); } -void game_state::add_stock_to_waste_move(std::vector& moves) const { +set game_state::generate_stock_moves_to_check() const { set stock_moves_to_check; // Adds multiples of deal count (excluding last card) @@ -262,53 +189,71 @@ void game_state::add_stock_to_waste_move(std::vector& moves) const { } } - // TODO: invariant -> no waste moves if redeal - // TODO: invariant -> count always < stock+waste + return stock_moves_to_check; +} + +void game_state::add_stock_to_cell_move(std::vector& moves, pile::ref empty_cell) const { + for (auto i : generate_stock_moves_to_check()) + moves.emplace_back(move::mtype::stock_k_plus, stock, empty_cell, i); + + // If there is no redeal option and the k-plus representation is not in effect, + // adds a regular move from the waste + if (!rules.stock_redeal && !piles[waste].empty()) + moves.emplace_back(move::mtype::regular, waste, empty_cell); +} +void game_state::add_stock_to_tableau_moves(std::vector& moves) const { // For each stock move to check, if it can be moved legally to one of the tableau // piles, adds this as a move - for (auto i : stock_moves_to_check) { - card from; - // If we are moving from the waste in a readeal (by looping), finds the correct card - if (i < piles[stock].size()) { - from = piles[stock][i]; - } else { - auto _i = static_cast(piles[stock].size() + piles[waste].size() - 1 - i); - from = piles[waste][_i]; - } + for (auto i : generate_stock_moves_to_check()) { + card from = stock_card_from_index(i); for (auto t : tableau_piles) { - bool valid_move = piles[t].empty() - ? true - : is_next_tableau_card(piles[t].top_card(), from); - - if (valid_move) - moves.emplace_back(move::mtype::stock_to_waste, stock, t, i); + if (is_valid_tableau_move(from, t)) + moves.emplace_back(move::mtype::stock_k_plus, stock, t, i); } } -} -void game_state::add_tableau_moves(std::vector& moves, pile::ref rem_ref) const { - for (auto add_ref : tableau_piles) { - if (is_valid_tableau_move(rem_ref, add_ref)) { - moves.emplace_back(move::mtype::regular, rem_ref, add_ref); + // If there is no redeal option and the k-plus representation is not in effect, + // adds a regular move from the waste to valid tableau piles + if (!rules.stock_redeal && !piles[waste].empty()) { + for (auto t : tableau_piles) { + if (is_valid_tableau_move(waste, t)) + moves.emplace_back(move::mtype::regular, waste, t); } } } -void game_state::add_cell_moves(std::vector& moves, pile::ref rem_ref) const { - for (auto add_ref : cells) { - if (add_ref != rem_ref && piles[add_ref].empty()) { - moves.emplace_back(move::mtype::regular, rem_ref, add_ref); - } +void game_state::add_stock_to_hole_foundation_moves(std::vector& moves) const { + for (auto i : generate_stock_moves_to_check()) { + card from = stock_card_from_index(i); + + for (auto f : foundations) + if (is_valid_foundations_move(from, f)) + moves.emplace_back(move::mtype::stock_k_plus, stock, f, i); + if (rules.hole && is_valid_hole_move(from)) + moves.emplace_back(move::mtype::stock_k_plus, stock, hole, i); + } + + // If there is no redeal option and the k-plus representation is not in effect, + // adds a regular move from the waste to valid foundation piles + if (!rules.stock_redeal && !piles[waste].empty()) { + for (auto f : foundations) + if (is_valid_foundations_move(waste, f)) + moves.emplace_back(move::mtype::regular, waste, f); + + if (rules.hole && is_valid_hole_move(waste)) + moves.emplace_back(move::mtype::regular, waste, hole); } } -void game_state::add_foundation_moves(std::vector& moves, pile::ref rem_ref) const { - for (auto add_ref : foundations) { - if (is_valid_foundations_move(rem_ref, add_ref)) { - moves.emplace_back(move::mtype::regular, rem_ref, add_ref); - } +card game_state::stock_card_from_index(pile::size_type i) const { + if (i < piles[stock].size()) { + return piles[stock][i]; + } else { + // If we are moving from the waste in a readeal (by looping), finds the correct card + auto _i = static_cast(piles[stock].size() + piles[waste].size() - 1 - i); + return piles[waste][_i]; } } @@ -331,17 +276,21 @@ bool game_state::is_valid_tableau_move(const pile::ref rem_ref, if (rem_ref == add_ref || rules.build_pol == pol::NO_BUILD) return false; + return is_valid_tableau_move(piles[rem_ref].top_card(), add_ref); +} + +bool game_state::is_valid_tableau_move(const card rem_c, + const pile::ref add_ref) const { if (piles[add_ref].empty()) { switch(rules.spaces_pol) { case sol_rules::spaces_policy::NO_BUILD: return false; case sol_rules::spaces_policy::KINGS: - return piles[rem_ref].top_card().get_rank() == 13; + return rem_c.get_rank() == 13; default: return true; } } else { - card rem_c = piles[rem_ref].top_card(); card add_c = piles[add_ref].top_card(); return is_next_tableau_card(add_c, rem_c); @@ -356,8 +305,11 @@ bool game_state::is_valid_foundations_move(const pile::ref rem_ref, const pile::ref add_ref) const { if (rem_ref == add_ref || rules.foundations_comp_piles) return false; - card rem_c = piles[rem_ref].top_card(); + return is_valid_foundations_move(piles[rem_ref].top_card(), add_ref); +} +bool game_state::is_valid_foundations_move(const card rem_c, + const pile::ref add_ref) const { // Checks same suit policy uint8_t suit_idx = (add_ref - foundations.front()) % uint8_t(4); if (rem_c.get_suit() != suit_idx) @@ -372,8 +324,11 @@ bool game_state::is_valid_foundations_move(const pile::ref rem_ref, bool game_state::is_valid_hole_move(const pile::ref rem_ref) const { if (rem_ref == hole) return false; + return is_valid_hole_move(piles[rem_ref].top_card()); +} - card::rank_t rank = piles[rem_ref].top_card().get_rank(); +bool game_state::is_valid_hole_move(const card c) const { + card::rank_t rank = c.get_rank(); card::rank_t hole_rank = piles[hole].top_card().get_rank(); return rank + 1 == hole_rank @@ -404,8 +359,10 @@ void game_state::add_built_group_moves(vector &moves) const { card bg_high = piles[rem_ref][built_group_height - 1]; if (piles[add_ref].empty()) { - if (rules.spaces_pol == s_pol::ANY || (rules.spaces_pol == s_pol::KINGS && bg_high.get_rank() == 13)) + if (rules.spaces_pol == s_pol::ANY) add_empty_built_group_moves(moves, rem_ref, add_ref, bg_high); + else if (rules.spaces_pol == s_pol::KINGS && bg_high.get_rank() == 13) + moves.emplace_back(move::mtype::built_group, rem_ref, add_ref, built_group_height); } else { if (is_next_built_group_card(piles[add_ref].top_card(), bg_high)) { bool is_reveal_move = -- cgit v1.2.1 From ccc77aecea3bf4b629780ee6441fff8f92de251a Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Fri, 29 Jun 2018 11:57:15 +0100 Subject: Fix built group reveal bug --- src/main/game/search-state/game_state.h | 2 +- src/main/game/search-state/game_state.legal_moves.cpp | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'src/main') diff --git a/src/main/game/search-state/game_state.h b/src/main/game/search-state/game_state.h index f6f41d9..b63823d 100644 --- a/src/main/game/search-state/game_state.h +++ b/src/main/game/search-state/game_state.h @@ -106,7 +106,7 @@ private: pile::size_type get_built_group_height(pile::ref) const; void add_empty_built_group_moves(std::vector&, pile::ref, pile::ref, - card) const; + card, bool) const; bool is_next_built_group_card(card, card) const; bool is_next_legal_card(sol_rules::build_policy, card, card) const; 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 cadeca9..be1d717 100644 --- a/src/main/game/search-state/game_state.legal_moves.cpp +++ b/src/main/game/search-state/game_state.legal_moves.cpp @@ -358,16 +358,17 @@ void game_state::add_built_group_moves(vector &moves) const { card bg_high = piles[rem_ref][built_group_height - 1]; + bool is_reveal_move = + piles[rem_ref].size() > built_group_height + && piles[rem_ref][built_group_height].is_face_down(); + if (piles[add_ref].empty()) { if (rules.spaces_pol == s_pol::ANY) - add_empty_built_group_moves(moves, rem_ref, add_ref, bg_high); + add_empty_built_group_moves(moves, rem_ref, add_ref, bg_high, is_reveal_move); else if (rules.spaces_pol == s_pol::KINGS && bg_high.get_rank() == 13) - moves.emplace_back(move::mtype::built_group, rem_ref, add_ref, built_group_height); + moves.emplace_back(move::mtype::built_group, rem_ref, add_ref, built_group_height, is_reveal_move); } else { if (is_next_built_group_card(piles[add_ref].top_card(), bg_high)) { - bool is_reveal_move = - piles[rem_ref].size() > built_group_height - && piles[rem_ref][built_group_height].is_face_down(); moves.emplace_back(move::mtype::built_group, rem_ref, add_ref, built_group_height, is_reveal_move); } } @@ -387,10 +388,11 @@ pile::size_type game_state::get_built_group_height(pile::ref ref) const { // Loops through each possible built group move to an empty pile and adds it to the list void game_state::add_empty_built_group_moves(vector& moves, pile::ref rem_ref, pile::ref add_ref, - card bg_high) const { + card bg_high, bool is_reveal_move) const { pile::size_type card_idx = 1; do { - moves.emplace_back(move::mtype::built_group, rem_ref, add_ref, static_cast(card_idx + 1)); + moves.emplace_back(move::mtype::built_group, rem_ref, add_ref, static_cast(card_idx + 1), + is_reveal_move); } while (piles[rem_ref][card_idx++] != bg_high); if (card_idx < piles[rem_ref].size() && piles[rem_ref][card_idx].is_face_down()) -- cgit v1.2.1 From 889494a8771e289f22cf517d3c891913ea8c4c2a Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Mon, 2 Jul 2018 11:45:13 +0100 Subject: Fix small impl bugs --- src/main/game/global_cache.cpp | 4 ++-- src/main/game/search-state/game_state.legal_moves.cpp | 2 +- src/main/input-output/input/sol_preset_types.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/main') diff --git a/src/main/game/global_cache.cpp b/src/main/game/global_cache.cpp index f688c33..2cec338 100644 --- a/src/main/game/global_cache.cpp +++ b/src/main/game/global_cache.cpp @@ -89,10 +89,10 @@ void cached_game_state::add_card(card c, const game_state& gs) { target.emplace_back(c); break; case pol::RED_BLACK: - target.emplace_back(c.get_colour(), c.get_rank()); + target.emplace_back(c.get_colour(), c.get_rank(), c.is_face_down()); break; default: - target.emplace_back(0, c.get_rank()); + target.emplace_back(0, c.get_rank(), c.is_face_down()); break; } } else { 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 be1d717..7a1f124 100644 --- a/src/main/game/search-state/game_state.legal_moves.cpp +++ b/src/main/game/search-state/game_state.legal_moves.cpp @@ -52,7 +52,7 @@ vector game_state::get_legal_moves(move parent_move) { } if (empty_cell != 255) { for (auto t : tableau_piles) { - if (piles[t].empty() || parent_move.to == t || !is_valid_tableau_move(t, empty_cell)) continue; + if (piles[t].empty() || parent_move.to == t) continue; else moves.emplace_back(move::mtype::regular, t, empty_cell); } diff --git a/src/main/input-output/input/sol_preset_types.cpp b/src/main/input-output/input/sol_preset_types.cpp index 9564bcc..363a801 100644 --- a/src/main/input-output/input/sol_preset_types.cpp +++ b/src/main/input-output/input/sol_preset_types.cpp @@ -413,7 +413,7 @@ map sol_preset_types::mp = { }, "stock size": 24, "stock deal count": 1, - "stock redeal": false + "stock redeal": true } )" -- cgit v1.2.1 From 34003ef1d084a1798c1ef6f6b2dbc1021e2eb0b0 Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Tue, 3 Jul 2018 11:27:32 +0100 Subject: Fix klondike bugs --- src/main/game/search-state/game_state.h | 9 +- .../game/search-state/game_state.legal_moves.cpp | 128 ++++++++++++++++----- .../input/json-parsing/deal_parser.cpp | 55 ++++++++- .../input-output/input/json-parsing/deal_parser.h | 2 + src/main/input-output/input/sol_preset_types.cpp | 2 + 5 files changed, 155 insertions(+), 41 deletions(-) (limited to 'src/main') diff --git a/src/main/game/search-state/game_state.h b/src/main/game/search-state/game_state.h index b63823d..78f1fb9 100644 --- a/src/main/game/search-state/game_state.h +++ b/src/main/game/search-state/game_state.h @@ -93,7 +93,6 @@ private: void add_stock_to_tableau_moves(std::vector&) const; void add_stock_to_hole_foundation_moves(std::vector&) const; card stock_card_from_index(pile::size_type) const; - void add_built_group_moves(std::vector &) const; void add_foundation_complete_piles_moves(std::vector &) const; bool is_valid_tableau_move(pile::ref, pile::ref) const; @@ -104,13 +103,15 @@ private: bool is_valid_hole_move(pile::ref) const; bool is_valid_hole_move(card) const; + void add_built_group_moves(std::vector&) const; + void add_built_group_moves(std::vector&, pile::ref, pile::size_type) const; pile::size_type get_built_group_height(pile::ref) const; - void add_empty_built_group_moves(std::vector&, pile::ref, pile::ref, - card, bool) const; bool is_next_built_group_card(card, card) const; + void add_empty_built_group_moves(std::vector&, pile::ref, pile::ref, pile::size_type, bool) const; + void add_kings_only_built_group_move(std::vector&, pile::ref, pile::ref, pile::size_type, bool) const; + void add_non_empty_built_group_move(std::vector&, pile::ref, pile::ref, pile::size_type, bool) const; bool is_next_legal_card(sol_rules::build_policy, card, card) const; - void turn_face_down_cards(std::vector&) const; /* Auto-foundation moves */ 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 7a1f124..42ba578 100644 --- a/src/main/game/search-state/game_state.legal_moves.cpp +++ b/src/main/game/search-state/game_state.legal_moves.cpp @@ -7,6 +7,7 @@ #include "../move.h" #include +#include using std::vector; using std::min; @@ -20,6 +21,10 @@ typedef sol_rules::spaces_policy s_pol; typedef sol_rules::stock_deal_type sdt; typedef sol_rules::face_up_policy fu; +// TODO: delete +using std::ostream; +std::ostream& operator <<(std::ostream&, const move&); +std::ostream& operator <<(std::ostream&, const std::vector&); //////////////////////////////// // MAIN LEGAL MOVE GEN CYCLE /// @@ -140,9 +145,46 @@ vector game_state::get_legal_moves(move parent_move) { if (rules.tableau_pile_count > 0 && rules.face_up != fu::ALL) turn_face_down_cards(moves); + // TODO: delete +//#ifndef NDEBUG +// std::cerr << "Moves:\n" << moves; + /*vector::size_type i = 0; + std::cin >> i; + move m = moves[i]; + moves.erase(moves.begin() + i); + moves.push_back(m);*/ +//#endif + return moves; } +/*#ifndef NDEBUG +// TODO: delete +ostream& operator <<(ostream& os, const move& m) { + switch (m.type) { + case move::mtype::regular: os << "regular"; break; + case move::mtype::dominance: os << "dominance"; break; + case move::mtype::built_group: os << "built_group"; break; + case move::mtype::stock_k_plus: os << "stock_k_plus"; break; + case move::mtype::stock_to_all_tableau: os << "stock_to_all_tableau"; break; + case move::mtype::null: os << "null"; break; + } + os << " (" << int(m.from) + << "," << int(m.to) + << "," << int(m.count) + << "," << m.reveal_move + << ")"; + return os; +} +ostream& operator <<(ostream& os, const vector& moves) { + int i = 0; + for (const move m : moves) { + os << m << " "<< i++ << "\n"; + } + return os; +} +#endif*/ + //////////////////////////////// // REGULAR MOVE GEN FUNCTIONS // @@ -216,7 +258,7 @@ void game_state::add_stock_to_tableau_moves(std::vector& moves) const { // If there is no redeal option and the k-plus representation is not in effect, // adds a regular move from the waste to valid tableau piles - if (!rules.stock_redeal && !piles[waste].empty()) { + if (/*!rules.stock_redeal && */!piles[waste].empty()) { for (auto t : tableau_piles) { if (is_valid_tableau_move(waste, t)) moves.emplace_back(move::mtype::regular, waste, t); @@ -342,7 +384,7 @@ bool game_state::is_valid_hole_move(const card c) const { // BUILT-GROUP MOVE GEN FUNCTIONS // //////////////////////////////////// -void game_state::add_built_group_moves(vector &moves) const { +void game_state::add_built_group_moves(vector& moves) const { assert(rules.built_group_pol != pol::NO_BUILD); // Cycles through each pile to see if it contains a built group @@ -352,26 +394,28 @@ void game_state::add_built_group_moves(vector &moves) const { auto built_group_height = get_built_group_height(rem_ref); if (built_group_height == 1) continue; - // We have found a built group. Cycles through each pile to see if it can be added - for (auto add_ref : tableau_piles) { - if (add_ref == rem_ref) continue; - - card bg_high = piles[rem_ref][built_group_height - 1]; - - bool is_reveal_move = - piles[rem_ref].size() > built_group_height - && piles[rem_ref][built_group_height].is_face_down(); + add_built_group_moves(moves, rem_ref, built_group_height); + } +} - if (piles[add_ref].empty()) { - if (rules.spaces_pol == s_pol::ANY) - add_empty_built_group_moves(moves, rem_ref, add_ref, bg_high, is_reveal_move); - else if (rules.spaces_pol == s_pol::KINGS && bg_high.get_rank() == 13) - moves.emplace_back(move::mtype::built_group, rem_ref, add_ref, built_group_height, is_reveal_move); - } else { - if (is_next_built_group_card(piles[add_ref].top_card(), bg_high)) { - moves.emplace_back(move::mtype::built_group, rem_ref, add_ref, built_group_height, is_reveal_move); - } +void game_state::add_built_group_moves(vector& moves, pile::ref rem_ref, pile::size_type built_group_height) const { + // We have found a built group. Cycles through each pile to see if it can be added + for (auto add_ref : tableau_piles) { + if (add_ref == rem_ref) continue; + + card bg_high = piles[rem_ref][built_group_height - 1]; + bool base_face_down = + piles[rem_ref].size() > built_group_height + && piles[rem_ref][built_group_height].is_face_down(); + + if (piles[add_ref].empty()) { + if (rules.spaces_pol == s_pol::ANY) { + add_empty_built_group_moves(moves, rem_ref, add_ref, built_group_height, base_face_down); + } else if (rules.spaces_pol == s_pol::KINGS && bg_high.get_rank() == 13) { + add_kings_only_built_group_move(moves, rem_ref, add_ref, built_group_height, base_face_down); } + } else { + add_non_empty_built_group_move(moves, rem_ref, add_ref, built_group_height, base_face_down); } } } @@ -386,23 +430,45 @@ pile::size_type game_state::get_built_group_height(pile::ref ref) const { return i; } +bool game_state::is_next_built_group_card(card a, card b) const { + return is_next_legal_card(rules.built_group_pol, a, b); +} + // Loops through each possible built group move to an empty pile and adds it to the list void game_state::add_empty_built_group_moves(vector& moves, pile::ref rem_ref, pile::ref add_ref, - card bg_high, bool is_reveal_move) const { - pile::size_type card_idx = 1; - do { - moves.emplace_back(move::mtype::built_group, rem_ref, add_ref, static_cast(card_idx + 1), - is_reveal_move); - } while (piles[rem_ref][card_idx++] != bg_high); - - if (card_idx < piles[rem_ref].size() && piles[rem_ref][card_idx].is_face_down()) - moves.back().make_reveal_move(); + pile::size_type built_group_height, bool base_face_down) const { + + for (pile::size_type card_idx = 1; card_idx < built_group_height; card_idx++) { + bool is_reveal_move = card_idx + 1 == built_group_height && base_face_down; + moves.emplace_back(move::mtype::built_group, rem_ref, add_ref, card_idx + 1, is_reveal_move); + } } -bool game_state::is_next_built_group_card(card a, card b) const { - return is_next_legal_card(rules.built_group_pol, a, b); +void game_state::add_kings_only_built_group_move(vector& moves, pile::ref rem_ref, pile::ref add_ref, + pile::size_type built_group_height, bool base_face_down) const { + + moves.emplace_back(move::mtype::built_group, rem_ref, add_ref, built_group_height, base_face_down); } +// Loops through each possible built group move to an empty pile and adds it to the list +void game_state::add_non_empty_built_group_move(vector& moves, pile::ref rem_ref, pile::ref add_ref, + pile::size_type built_group_height, bool base_face_down) const { + + // Given rank of add pile, get card of that rank - 1 in rem pile and see if next bg card + // For each card going down from top card in rem pile, check if is next bg card + for (pile::ref r = 1; r < built_group_height; r++) { + if (is_next_built_group_card(piles[add_ref].top_card(), piles[rem_ref][r])) { + + bool is_reveal_move = r + 1 == built_group_height && base_face_down; + moves.emplace_back(move::mtype::built_group, rem_ref, add_ref, r + 1, is_reveal_move); + break; + } + } +} + + +/////////////////////// + bool game_state::is_next_legal_card(pol p, card a, card b) const { // Checks build pol violations switch(p) { 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 e776cbd..bc31cbc 100644 --- a/src/main/input-output/input/json-parsing/deal_parser.cpp +++ b/src/main/input-output/input/json-parsing/deal_parser.cpp @@ -11,6 +11,7 @@ using namespace std; using namespace rapidjson; typedef sol_rules::build_policy pol; +typedef sol_rules::stock_deal_type sdt; typedef sol_rules::face_up_policy fu; void deal_parser::parse(game_state &gs, const rapidjson::Document& doc) { @@ -39,6 +40,11 @@ void deal_parser::parse(game_state &gs, const rapidjson::Document& doc) { if (gs.rules.stock_size > 0) { parse_stock(gs, doc); } + + // Construct waste + if (gs.rules.stock_deal_t == sdt::WASTE) { + parse_waste(gs, doc); + } // Construct reserve if (gs.rules.reserve_size > 0) { @@ -46,8 +52,12 @@ void deal_parser::parse(game_state &gs, const rapidjson::Document& doc) { } // If the foundations begin with cards in them, fill them - if (gs.rules.foundations_init_card) { - fill_foundations(gs); + if (gs.rules.foundations) { + bool supplied_foundations = parse_foundations(gs, doc); + + if (!supplied_foundations && gs.rules.foundations_init_card) { + fill_foundations(gs); + } } Document d; @@ -76,6 +86,9 @@ string deal_parser::deal_schema_json() { "tableau piles": { "type": "array", "items": {"$ref": "#/definitions/cardarray"} }, + "foundations": { + "type": "array", "items": {"$ref": "#/definitions/cardarray"} + }, "hole": {"$ref": "#/definitions/card"}, "stock": {"$ref": "#/definitions/cardarray"}, "waste": {"$ref": "#/definitions/cardarray"}, @@ -144,10 +157,6 @@ void deal_parser::parse_stock(game_state &gs, const Document& doc) { const Value &json_stock = doc["stock"]; assert(json_stock.IsArray()); - if (json_stock.Size() != gs.rules.stock_size) { - json_helper::json_parse_err("Incorrect stock size"); - } - for (const Value& json_card : json_stock.GetArray()) { assert(json_card.IsString()); gs.place_card(gs.stock, card(json_card.GetString())); @@ -155,6 +164,18 @@ void deal_parser::parse_stock(game_state &gs, const Document& doc) { } } +void deal_parser::parse_waste(game_state &gs, const Document& doc) { + if (doc.HasMember("waste")) { + const Value &json_waste = doc["waste"]; + assert(json_waste.IsArray()); + + for (const Value& json_card : json_waste.GetArray()) { + assert(json_card.IsString()); + gs.place_card(gs.waste, card(json_card.GetString())); + } + } +} + void deal_parser::parse_reserve(game_state &gs, const Document& doc) { assert(doc.HasMember("reserve")); const Value& json_reserve_piles = doc["reserve"]; @@ -176,6 +197,28 @@ void deal_parser::parse_reserve(game_state &gs, const Document& doc) { } } +bool deal_parser::parse_foundations(game_state &gs, const rapidjson::Document& doc) { + if (!doc.HasMember("foundations")) return false; + + const Value& json_foundations = doc["foundations"]; + assert(json_foundations.IsArray()); + + if (json_foundations.Size() != 4 * (gs.rules.two_decks ? 2 : 1) ) { + json_helper::json_parse_err("Incorrect number of foundations"); + } + + for (auto j = begin(json_foundations.GetArray()); j != end(json_foundations.GetArray()); j++) { + + for (auto& json_card : j->GetArray()) { + assert(json_card.IsString()); + card c = card(json_card.GetString()); + gs.place_card(gs.foundations[c.get_suit()], c); + } + } + + return true; +} + void deal_parser::fill_foundations(game_state &gs) { auto foundations_count = uint8_t(4 * (gs.rules.two_decks ? 2:1)); assert(gs.foundations.size() == foundations_count); 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 dc67573..c34a93f 100644 --- a/src/main/input-output/input/json-parsing/deal_parser.h +++ b/src/main/input-output/input/json-parsing/deal_parser.h @@ -21,7 +21,9 @@ public: static void parse_hole(game_state&, const rapidjson::Document&); static void parse_cells(game_state&, const rapidjson::Document&); static void parse_stock(game_state&, const rapidjson::Document&); + static void parse_waste(game_state&, const rapidjson::Document&); static void parse_reserve(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/sol_preset_types.cpp b/src/main/input-output/input/sol_preset_types.cpp index 363a801..ee19b5c 100644 --- a/src/main/input-output/input/sol_preset_types.cpp +++ b/src/main/input-output/input/sol_preset_types.cpp @@ -411,6 +411,7 @@ map sol_preset_types::mp = { "diagonal deal": true, "face up cards": "top" }, + "foundations removable": true, "stock size": 24, "stock deal count": 1, "stock redeal": true @@ -432,6 +433,7 @@ map sol_preset_types::mp = { "diagonal deal": true, "face up cards": "top" }, + "foundations removable": true, "stock size": 24, "stock deal count": 3, "stock redeal": true -- cgit v1.2.1 From 9114b8032cadd17553a07daef49e2272aa4116e9 Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Tue, 3 Jul 2018 14:49:25 +0100 Subject: Tidy up stock rep and amend broken unit tests --- .../game/search-state/game_state.legal_moves.cpp | 42 ---------------------- src/main/input-output/input/sol_preset_types.cpp | 3 +- 2 files changed, 2 insertions(+), 43 deletions(-) (limited to 'src/main') 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 42ba578..5dfa00a 100644 --- a/src/main/game/search-state/game_state.legal_moves.cpp +++ b/src/main/game/search-state/game_state.legal_moves.cpp @@ -21,11 +21,6 @@ typedef sol_rules::spaces_policy s_pol; typedef sol_rules::stock_deal_type sdt; typedef sol_rules::face_up_policy fu; -// TODO: delete -using std::ostream; -std::ostream& operator <<(std::ostream&, const move&); -std::ostream& operator <<(std::ostream&, const std::vector&); - //////////////////////////////// // MAIN LEGAL MOVE GEN CYCLE /// //////////////////////////////// @@ -145,46 +140,9 @@ vector game_state::get_legal_moves(move parent_move) { if (rules.tableau_pile_count > 0 && rules.face_up != fu::ALL) turn_face_down_cards(moves); - // TODO: delete -//#ifndef NDEBUG -// std::cerr << "Moves:\n" << moves; - /*vector::size_type i = 0; - std::cin >> i; - move m = moves[i]; - moves.erase(moves.begin() + i); - moves.push_back(m);*/ -//#endif - return moves; } -/*#ifndef NDEBUG -// TODO: delete -ostream& operator <<(ostream& os, const move& m) { - switch (m.type) { - case move::mtype::regular: os << "regular"; break; - case move::mtype::dominance: os << "dominance"; break; - case move::mtype::built_group: os << "built_group"; break; - case move::mtype::stock_k_plus: os << "stock_k_plus"; break; - case move::mtype::stock_to_all_tableau: os << "stock_to_all_tableau"; break; - case move::mtype::null: os << "null"; break; - } - os << " (" << int(m.from) - << "," << int(m.to) - << "," << int(m.count) - << "," << m.reveal_move - << ")"; - return os; -} -ostream& operator <<(ostream& os, const vector& moves) { - int i = 0; - for (const move m : moves) { - os << m << " "<< i++ << "\n"; - } - return os; -} -#endif*/ - //////////////////////////////// // REGULAR MOVE GEN FUNCTIONS // diff --git a/src/main/input-output/input/sol_preset_types.cpp b/src/main/input-output/input/sol_preset_types.cpp index ee19b5c..e540a51 100644 --- a/src/main/input-output/input/sol_preset_types.cpp +++ b/src/main/input-output/input/sol_preset_types.cpp @@ -816,7 +816,8 @@ map sol_preset_types::mp = { "tableau piles": { "count": 7, "build policy": "red-black", - "move built group": true + "move built group": true, + "face up cards": "top" }, "foundations removable": true, "stock size": 31, -- cgit v1.2.1