diff options
| author | Charlie Blake | 2018-06-08 21:54:48 +0100 |
|---|---|---|
| committer | Charlie Blake | 2018-06-08 21:54:48 +0100 |
| commit | a7396c5497601855fad019cfd145ca6c93e1c40f (patch) | |
| tree | 99bdf08b2eb8f15c38a4ddb74c68d45bacd0fae1 /src | |
| parent | Fix built move bug and add unit tests (diff) | |
| download | metasol-a7396c5497601855fad019cfd145ca6c93e1c40f.tar.gz metasol-a7396c5497601855fad019cfd145ca6c93e1c40f.zip | |
Refactor moves logic
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/game/move.cpp | 21 | ||||
| -rw-r--r-- | src/main/game/move.h | 11 | ||||
| -rw-r--r-- | src/main/game/search-state/game_state.cpp | 223 | ||||
| -rw-r--r-- | src/main/game/search-state/game_state.h | 15 | ||||
| -rw-r--r-- | src/main/game/search-state/game_state.legal_moves.cpp | 26 | ||||
| -rw-r--r-- | src/main/solver/solver.cpp | 8 | ||||
| -rw-r--r-- | src/test/test_helper.cpp | 2 | ||||
| -rw-r--r-- | src/test/unit_tests/built_group_move_gen_test.cpp | 152 | ||||
| -rw-r--r-- | src/test/unit_tests/legal_move_gen_test.cpp | 45 |
9 files changed, 280 insertions, 223 deletions
diff --git a/src/main/game/move.cpp b/src/main/game/move.cpp index 053b3ba..ff8269c 100644 --- a/src/main/game/move.cpp +++ b/src/main/game/move.cpp @@ -4,19 +4,16 @@ #include "move.h" -const pile::size_type move::dominance_flag = pile::max_size_type; - -move::move(pile::ref f, pile::ref t, pile::size_type i) : from(f), to(t), count(i) { - assert(i >= 1); -} - -// Returns true is the move has been flagged as a special 'dominance' move -bool move::is_dominance() const { - return count == dominance_flag; +move::move(mtype ty, pile::ref f, pile::ref t, pile::size_type i) : type(ty), from(f), to(t), count(i) { +#ifndef NDEBUG + if (ty == mtype::regular) assert(i == 1); + else assert(i >= 1); +#endif } bool operator==(const move& a, const move& b) { - return (a.from == b.from ) + return (a.from == b.from ) && (a.to == b.to ) - && (a.count == b.count); -}
\ No newline at end of file + && (a.count == b.count) + && (a.type == b.type ); +} diff --git a/src/main/game/move.h b/src/main/game/move.h index 81a6116..b852811 100644 --- a/src/main/game/move.h +++ b/src/main/game/move.h @@ -8,12 +8,15 @@ #include "pile.h" struct move { - move(pile::ref , pile::ref, pile::size_type = 1); - bool is_dominance() const; + enum class mtype {regular, dominance, built_group, stock_to_waste, stock_to_tableau, redeal, null}; + + explicit move(mtype, pile::ref = 255 , pile::ref = 255, pile::size_type = 1); friend bool operator==(const move&, const move&); - const static pile::size_type dominance_flag; - pile::ref from; pile::ref to; pile::size_type count; + mtype type; + pile::ref from; + pile::ref to; + pile::size_type count; }; diff --git a/src/main/game/search-state/game_state.cpp b/src/main/game/search-state/game_state.cpp index 42f9b40..ac57142 100644 --- a/src/main/game/search-state/game_state.cpp +++ b/src/main/game/search-state/game_state.cpp @@ -227,114 +227,157 @@ vector<card> game_state::gen_shuffled_deck(int seed, card::rank_t max_rank, //////////////////// void game_state::make_move(const move m) { - // Handles stock moves - if (m.from == stock) { - // Handles special stock-to-tableau-piles move - if (rules.stock_deal_t == sdt::TABLEAU_PILES) { - assert(m.from == stock); - assert(m.to == 255); - - for (pile::ref tab_pr = original_tableau_piles.front(); - tab_pr < pile::ref(original_tableau_piles.front() + m.count); - tab_pr++) { - place_card(tab_pr, take_card(stock)); - } - } - // Handles stock-to-waste moves - else { - if (piles[stock].empty()) { - // Re-deal waste back to stock - while (!piles[waste].empty()) { - place_card(stock, take_card(waste)); - } - } else { - assert(m.to == waste); - for (int i = 0; i < m.count; i++) { - place_card(waste, take_card(stock)); - } - } - } + switch (m.type) { + case move::mtype::regular: + case move::mtype::dominance: + make_regular_move(m); + break; + case move::mtype::built_group: + make_built_pile_move(m); + break; + case move::mtype::stock_to_waste: + make_stock_to_waste_move(m); + break; + case move::mtype::stock_to_tableau: + make_stock_to_tableau_move(m); + break; + case move::mtype::redeal: + make_redeal_move(); + break; + case move::mtype::null: + assert(false); + break; + } +} + +void game_state::undo_move(const move m) { + switch (m.type) { + case move::mtype::regular: + case move::mtype::dominance: + undo_regular_move(m); + break; + case move::mtype::built_group: + undo_built_pile_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); + break; + case move::mtype::redeal: + undo_redeal_move(); + break; + case move::mtype::null: + assert(false); + break; } +} - // If this is not a built-pile move - else if (m.count == 1 || m.is_dominance()) { - assert(m.from < piles.size()); - assert(m.to < piles.size()); +void game_state::make_regular_move(const move m) { + assert(m.from < piles.size()); + assert(m.to < piles.size()); + + place_card(m.to, take_card(m.from)); - place_card(m.to, take_card(m.from)); #ifndef NO_AUTO_FOUNDATIONS - update_auto_foundation_moves(m.to); + update_auto_foundation_moves(m.to); #endif +} + +void game_state::undo_regular_move(const move m) { + assert(m.to < piles.size()); + + place_card(m.from, take_card(m.to)); + +#ifndef NO_AUTO_FOUNDATIONS + update_auto_foundation_moves(m.from); +#endif +} + +void game_state::make_built_pile_move(const 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;) { + place_card(m.to, piles[m.from][pile_idx]); } - // If this is a built-pile move - else { - assert(m.from < piles.size() ); - assert(m.to < piles.size() ); - assert(m.count <= rules.max_rank); + // Removes the cards from the 'from' pile + for (uint8_t rem_count = 0; rem_count < m.count; rem_count++) { + take_card(m.from); + } +} - // Adds the cards to the 'to' pile - for (auto pile_idx = m.count; pile_idx-- > 0;) { - place_card(m.to, piles[m.from][pile_idx]); - } +void game_state::undo_built_pile_move(const move m) { + assert(rules.move_built_group); + assert(m.to < piles.size()); + assert(m.count <= rules.max_rank); - // Removes the cards from the 'from' pile - for (uint8_t rem_count = 0; rem_count < m.count; rem_count++) { - take_card(m.from); - } + // Adds the cards to the 'from' pile + for (auto pile_idx = m.count; pile_idx-- > 0;) { + place_card(m.from, piles[m.to][pile_idx]); + } + + // Removes the cards from the 'to' pile + for (uint8_t rem_count = 0; rem_count < m.count; rem_count++) { + take_card(m.to); } } -void game_state::undo_move(const move m) { - assert(m.from < piles.size()); +void game_state::make_stock_to_waste_move(const move m) { + assert(rules.stock_deal_t == sdt::WASTE); - // Handles stock moves - if (m.from == stock) { - // Handles special stock-to-tableau-piles move - if (rules.stock_deal_t == sdt::TABLEAU_PILES) { - for (pile::ref tab_pr = original_tableau_piles.front() + m.count; - tab_pr-- > original_tableau_piles.front(); - ) { - place_card(stock, take_card(tab_pr)); - } - } - // Handles stock-to-waste moves - else { - if (piles[waste].empty()) { - // Re-deal waste back to stock - while (!piles[stock].empty()) { - place_card(waste, take_card(stock)); - } - } else { - for (int i = 0; i < m.count; i++) { - place_card(stock, take_card(waste)); - } - } - } + for (int i = 0; i < m.count; i++) { + place_card(waste, take_card(stock)); } +} - // 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 +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)); } +} - // If this is a built-pile move - 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;) { - place_card(m.from, piles[m.to][pile_idx]); - } +void game_state::make_stock_to_tableau_move(const move m) { + assert(rules.stock_deal_t == sdt::TABLEAU_PILES); - // Removes the cards from the 'to' pile - for (uint8_t rem_count = 0; rem_count < m.count; rem_count++) { - take_card(m.to); - } + for (pile::ref tab_pr = original_tableau_piles.front(); + tab_pr < pile::ref(original_tableau_piles.front() + m.count); + tab_pr++) { + place_card(tab_pr, take_card(stock)); + } +} + +void game_state::undo_stock_to_tableau_move(const move m) { + assert(rules.stock_deal_t == sdt::TABLEAU_PILES); + + for (pile::ref tab_pr = original_tableau_piles.front() + m.count; + tab_pr-- > original_tableau_piles.front(); + ) { + place_card(stock, take_card(tab_pr)); + } +} + +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)); } } diff --git a/src/main/game/search-state/game_state.h b/src/main/game/search-state/game_state.h index 3c6b192..be8b79c 100644 --- a/src/main/game/search-state/game_state.h +++ b/src/main/game/search-state/game_state.h @@ -43,7 +43,7 @@ public: /* Legal move generation */ - std::vector<move> get_legal_moves(move = move(255, 255, 255)); + std::vector<move> get_legal_moves(move = move(move::mtype::regular)); boost::optional<move> get_dominance_move() const; /* State inspection */ @@ -66,6 +66,19 @@ private: void eval_pile_order(pile::ref, bool); void eval_pile_order(std::list<pile::ref>&, pile::ref, bool); + /* Altering state */ + + void make_regular_move(move move); + void undo_regular_move(move move); + void make_built_pile_move(move move); + void undo_built_pile_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(); + /* Legal move generation */ move get_stock_tableau_move() 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 b6e110d..3fb0156 100644 --- a/src/main/game/search-state/game_state.legal_moves.cpp +++ b/src/main/game/search-state/game_state.legal_moves.cpp @@ -34,7 +34,7 @@ vector<move> game_state::get_legal_moves(move parent_move) { && rules.stock_deal_t == sdt::WASTE && piles[stock].empty() && !piles[waste].empty()) { - moves.emplace_back(stock, waste); + moves.emplace_back(move::mtype::redeal); } // Cycles through each pile which we may be able to remove a card from @@ -44,7 +44,7 @@ vector<move> game_state::get_legal_moves(move parent_move) { if ((rules.hole && rem_ref == hole) || piles[rem_ref].empty() || (rem_ref == parent_move.to - && parent_move.count <= 1 + && parent_move.count == 1 && parent_move.from != stock) ) continue; @@ -69,7 +69,7 @@ vector<move> game_state::get_legal_moves(move parent_move) { if (rules.stock_deal_t == sdt::WASTE) { uint8_t cards_to_move = min(rules.stock_deal_count, piles[stock].size()); - moves.emplace_back(stock, waste, cards_to_move); + moves.emplace_back(move::mtype::stock_to_waste, stock, waste, cards_to_move); } continue; } @@ -78,14 +78,14 @@ vector<move> game_state::get_legal_moves(move parent_move) { // tableau move according to the rules for (auto add_ref : tableau_piles) { if (is_valid_tableau_move(rem_ref, add_ref)) { - moves.emplace_back(rem_ref, add_ref); + moves.emplace_back(move::mtype::regular, rem_ref, add_ref); } } // Any card can be moved to a cell, so long as the cell isn't full for (auto add_ref : cells) { if (add_ref != rem_ref && piles[add_ref].empty()) { - moves.emplace_back(rem_ref, add_ref); + moves.emplace_back(move::mtype::regular, rem_ref, add_ref); } } @@ -93,13 +93,13 @@ vector<move> game_state::get_legal_moves(move parent_move) { // move according to the rules for (auto add_ref : foundations) { if (is_valid_foundations_move(rem_ref, add_ref)) { - moves.emplace_back(rem_ref, add_ref); + moves.emplace_back(move::mtype::regular, rem_ref, add_ref); } } // Does the same for the hole if (rules.hole && is_valid_hole_move(rem_ref)) { - moves.emplace_back(rem_ref, hole); + moves.emplace_back(move::mtype::regular, rem_ref, hole); } // Note that the stock and the reserve aren't mentioned here, as @@ -117,7 +117,7 @@ vector<move> game_state::get_legal_moves(move parent_move) { for (pile::ref found_pr : foundations) { if (piles[found_pr].empty()) { - moves.emplace_back(tab_pr, found_pr, rules.max_rank); + moves.emplace_back(move::mtype::built_group, tab_pr, found_pr, rules.max_rank); break; } } @@ -130,7 +130,7 @@ vector<move> game_state::get_legal_moves(move parent_move) { } // This is a special kind of move which the solver handles differently. Hence -// the arbitrary second param. We must supply the number of stock cards +// the arbitrary middle params. 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 { pile::size_type stock_moves = @@ -139,7 +139,7 @@ move game_state::get_stock_tableau_move() const { : piles[stock].size(); assert(stock_moves > 0 && stock_moves <= piles[stock].size()); - return {stock, 255, stock_moves}; + return move(move::mtype::stock_to_tableau, 0, 0, stock_moves); } // If a tableau pile is empty and the space policy is @@ -250,7 +250,7 @@ void game_state::get_built_group_moves(vector<move>& moves) const { // Adds the move to the list of moves, as a special built group move if (valid_built_group_move(bg_low, bg_high, add_card)) { - moves.emplace_back(rem_ref, add_ref, built_group_height); + moves.emplace_back(move::mtype::built_group, rem_ref, add_ref, built_group_height); } } } @@ -317,7 +317,7 @@ void game_state::add_empty_built_group_moves(vector<move>& moves, pile::size_type card_idx = 1; do { moves.emplace_back( - rem_ref, add_ref, static_cast<pile::size_type>(card_idx + 1) + move::mtype::built_group, rem_ref, add_ref, static_cast<pile::size_type>(card_idx + 1) ); } while (piles[rem_ref][card_idx++] != bg_high); } @@ -355,7 +355,7 @@ boost::optional<move> game_state::get_dominance_move() const { + card::rank_t(1); if (target_rank == c.get_rank() && auto_foundation_moves[c.get_suit()]) { - return move(pr, target_foundation, move::dominance_flag); + return move(move::mtype::dominance, pr, target_foundation); } } #endif diff --git a/src/main/solver/solver.cpp b/src/main/solver/solver.cpp index b104da3..7d490be 100644 --- a/src/main/solver/solver.cpp +++ b/src/main/solver/solver.cpp @@ -26,7 +26,7 @@ solver::solver(const game_state& gs) , backtracks(0) , dominance_moves(0) , depth(0) - , root(nullptr, move(255, 255, 255)) + , root(nullptr, move(move::mtype::null)) , current_node(&root) { } @@ -53,7 +53,7 @@ solver::sol_state solver::run(boost::optional<atomic<bool> &> terminate_solver) } #ifndef NDEBUG - if (current_node->mv.is_dominance()) { + if (current_node->mv.type == move::mtype::dominance) { LOG_DEBUG("(dominance move)"); } LOG_DEBUG(state); @@ -92,7 +92,7 @@ solver::sol_state solver::run(boost::optional<atomic<bool> &> terminate_solver) current_node = ¤t_node->children.back(); state.make_move(current_node->mv); depth++; - if (current_node->mv.is_dominance()) dominance_moves++; + if (current_node->mv.type == move::mtype::dominance) dominance_moves++; } states_searched++; @@ -137,7 +137,7 @@ bool solver::revert_to_last_node_with_children() { // Checks that the state after the undo is in the cache // (as long as the move wasn't a dominance move) - if (!current_node->mv.is_dominance()) { + if (current_node->mv.type != move::mtype::dominance) { assert(cache.contains(state)); LOG_DEBUG("(undo move)"); } else { diff --git a/src/test/test_helper.cpp b/src/test/test_helper.cpp index 18b36eb..dbc6f0d 100644 --- a/src/test/test_helper.cpp +++ b/src/test/test_helper.cpp @@ -52,7 +52,7 @@ void test_helper::run_foundations_dominance_test(sol_rules::build_policy policy, solver::node const *n = &sol.get_search_tree(); for (card c : cards) { n = &n->children.back(); - ASSERT_TRUE(n->mv.is_dominance()); + ASSERT_TRUE(n->mv.type == move::mtype::dominance); ASSERT_TRUE(gs.get_data()[n->mv.from].top_card() == c); ASSERT_TRUE(n->mv.to >= 0 && n->mv.to <= 4); gs.make_move(n->mv); diff --git a/src/test/unit_tests/built_group_move_gen_test.cpp b/src/test/unit_tests/built_group_move_gen_test.cpp index 0bdff4d..6ea40bf 100644 --- a/src/test/unit_tests/built_group_move_gen_test.cpp +++ b/src/test/unit_tests/built_group_move_gen_test.cpp @@ -31,18 +31,18 @@ TEST(BuiltGroupMoveGen, SameSuitEmpty) { }, { // Regular moves - move(1, 0, 1), - move(2, 0, 1), - move(3, 0, 1), - move(1, 4, 1), - move(2, 4, 1), - move(3, 4, 1), + move(move::mtype::regular, 1, 0, 1), + move(move::mtype::regular, 2, 0, 1), + move(move::mtype::regular, 3, 0, 1), + move(move::mtype::regular, 1, 4, 1), + move(move::mtype::regular, 2, 4, 1), + move(move::mtype::regular, 3, 4, 1), // Built pile moves - move(1, 0, 2), - move(1, 0, 3), - move(1, 4, 2), - move(1, 4, 3) + move(move::mtype::built_group, 1, 0, 2), + move(move::mtype::built_group, 1, 0, 3), + move(move::mtype::built_group, 1, 4, 2), + move(move::mtype::built_group, 1, 4, 3) } ); } @@ -64,21 +64,21 @@ TEST(BuiltGroupMoveGen, RedBlackEmpty) { }, { // Regular moves - move(1, 0, 1), - move(2, 0, 1), - move(3, 0, 1), - move(1, 4, 1), - move(2, 4, 1), - move(3, 4, 1), + move(move::mtype::regular, 1, 0, 1), + move(move::mtype::regular, 2, 0, 1), + move(move::mtype::regular, 3, 0, 1), + move(move::mtype::regular, 1, 4, 1), + move(move::mtype::regular, 2, 4, 1), + move(move::mtype::regular, 3, 4, 1), // Built pile moves - move(2, 0, 2), - move(2, 0, 3), - move(2, 4, 2), - move(2, 4, 3), + move(move::mtype::built_group, 2, 0, 2), + move(move::mtype::built_group, 2, 0, 3), + move(move::mtype::built_group, 2, 4, 2), + move(move::mtype::built_group, 2, 4, 3), - move(3, 0, 2), - move(3, 4, 2) + move(move::mtype::built_group, 3, 0, 2), + move(move::mtype::built_group, 3, 4, 2) } ); } @@ -100,28 +100,28 @@ TEST(BuiltGroupMoveGen, AnySuitEmpty) { }, { // Regular moves - move(1, 0, 1), - move(2, 0, 1), - move(3, 0, 1), - move(1, 4, 1), - move(2, 4, 1), - move(3, 4, 1), + move(move::mtype::regular, 1, 0, 1), + move(move::mtype::regular, 2, 0, 1), + move(move::mtype::regular, 3, 0, 1), + move(move::mtype::regular, 1, 4, 1), + move(move::mtype::regular, 2, 4, 1), + move(move::mtype::regular, 3, 4, 1), // Built pile moves - move(1, 0, 2), - move(1, 0, 3), - move(1, 4, 2), - move(1, 4, 3), - - move(2, 0, 2), - move(2, 0, 3), - move(2, 4, 2), - move(2, 4, 3), - - move(3, 0, 2), - move(3, 0, 3), - move(3, 4, 2), - move(3, 4, 3), + move(move::mtype::built_group, 1, 0, 2), + move(move::mtype::built_group, 1, 0, 3), + move(move::mtype::built_group, 1, 4, 2), + move(move::mtype::built_group, 1, 4, 3), + + move(move::mtype::built_group, 2, 0, 2), + move(move::mtype::built_group, 2, 0, 3), + move(move::mtype::built_group, 2, 4, 2), + move(move::mtype::built_group, 2, 4, 3), + + move(move::mtype::built_group, 3, 0, 2), + move(move::mtype::built_group, 3, 0, 3), + move(move::mtype::built_group, 3, 4, 2), + move(move::mtype::built_group, 3, 4, 3), } ); } @@ -143,12 +143,12 @@ TEST(BuiltGroupMoveGen, CantMove) { }, { // Regular moves - move(1, 0, 1), - move(2, 0, 1), - move(3, 0, 1), - move(1, 4, 1), - move(2, 4, 1), - move(3, 4, 1) + move(move::mtype::regular, 1, 0, 1), + move(move::mtype::regular, 2, 0, 1), + move(move::mtype::regular, 3, 0, 1), + move(move::mtype::regular, 1, 4, 1), + move(move::mtype::regular, 2, 4, 1), + move(move::mtype::regular, 3, 4, 1) } ); } @@ -170,15 +170,15 @@ TEST(BuiltGroupMoveGen, SameSuitOccupied) { }, { // Regular moves - move(1, 4, 1), - move(2, 4, 1), - move(3, 4, 1), - move(0, 4, 1), + move(move::mtype::regular, 1, 4, 1), + move(move::mtype::regular, 2, 4, 1), + move(move::mtype::regular, 3, 4, 1), + move(move::mtype::regular, 0, 4, 1), // Built pile moves - move(1, 0, 3), - move(1, 4, 2), - move(1, 4, 3) + move(move::mtype::built_group, 1, 0, 3), + move(move::mtype::built_group, 1, 4, 2), + move(move::mtype::built_group, 1, 4, 3) } ); } @@ -200,16 +200,16 @@ TEST(BuiltGroupMoveGen, RedBlackOccupied) { }, { // Regular moves - move(1, 4, 1), - move(2, 4, 1), - move(3, 4, 1), - move(0, 4, 1), + move(move::mtype::regular, 1, 4, 1), + move(move::mtype::regular, 2, 4, 1), + move(move::mtype::regular, 3, 4, 1), + move(move::mtype::regular, 0, 4, 1), // Built pile moves - move(2, 0, 3), - move(2, 4, 2), - move(2, 4, 3), - move(3, 4, 2) + move(move::mtype::built_group, 2, 0, 3), + move(move::mtype::built_group, 2, 4, 2), + move(move::mtype::built_group, 2, 4, 3), + move(move::mtype::built_group, 3, 4, 2) } ); } @@ -231,24 +231,24 @@ TEST(BuiltGroupMoveGen, AnySuitOccupied) { }, { // Regular moves - move(1, 4, 1), - move(2, 4, 1), - move(3, 4, 1), - move(0, 4, 1), + move(move::mtype::regular, 1, 4, 1), + move(move::mtype::regular, 2, 4, 1), + move(move::mtype::regular, 3, 4, 1), + move(move::mtype::regular, 0, 4, 1), // Built pile moves - move(1, 0, 3), - move(2, 0, 3), - move(3, 0, 3), + move(move::mtype::built_group, 1, 0, 3), + move(move::mtype::built_group, 2, 0, 3), + move(move::mtype::built_group, 3, 0, 3), - move(1, 4, 2), - move(1, 4, 3), + move(move::mtype::built_group, 1, 4, 2), + move(move::mtype::built_group, 1, 4, 3), - move(2, 4, 2), - move(2, 4, 3), + move(move::mtype::built_group, 2, 4, 2), + move(move::mtype::built_group, 2, 4, 3), - move(3, 4, 2), - move(3, 4, 3), + move(move::mtype::built_group, 3, 4, 2), + move(move::mtype::built_group, 3, 4, 3), } ); } diff --git a/src/test/unit_tests/legal_move_gen_test.cpp b/src/test/unit_tests/legal_move_gen_test.cpp index f8c9a63..f9ff52e 100644 --- a/src/test/unit_tests/legal_move_gen_test.cpp +++ b/src/test/unit_tests/legal_move_gen_test.cpp @@ -7,6 +7,7 @@ #include "../test_helper.h" #include "../../main/game/search-state/game_state.h" #include "../../main/game/sol_rules.h" +#include "../../main/game/move.h" typedef sol_rules::build_policy pol; typedef sol_rules::spaces_policy s_pol; @@ -31,10 +32,10 @@ TEST(LegalMoveGen, BuildPolAnySuit) { vector<move> actual_moves = gs.get_legal_moves(); vector<move> exp_moves = { - move(4,0), - move(4,1), - move(4,2), - move(4,3) + move(move::mtype::regular, 4,0), + move(move::mtype::regular, 4,1), + move(move::mtype::regular, 4,2), + move(move::mtype::regular, 4,3) }; ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; @@ -55,8 +56,8 @@ TEST(LegalMoveGen, BuildPolRedBlack) { vector<move> actual_moves = gs.get_legal_moves(); vector<move> exp_moves = { - move(4,1), - move(4,3) + move(move::mtype::regular, 4,1), + move(move::mtype::regular, 4,3) }; ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; @@ -77,7 +78,7 @@ TEST(LegalMoveGen, BuildPolSameSuit) { vector<move> actual_moves = gs.get_legal_moves(); vector<move> exp_moves = { - move(4,0) + move(move::mtype::regular, 4,0) }; ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; @@ -115,7 +116,7 @@ TEST(LegalMoveGen, SpacesPolAny) { vector<move> actual_moves = gs.get_legal_moves(); vector<move> exp_moves = { - move(1, 0) + move(move::mtype::regular, 1, 0) }; ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; @@ -134,7 +135,7 @@ TEST(LegalMoveGen, SpacesPolKings) { vector<move> actual_moves = gs.get_legal_moves(); vector<move> exp_moves = { - move(2, 0) + move(move::mtype::regular, 2, 0) }; ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; @@ -169,8 +170,8 @@ TEST(LegalMoveGen, MoveBuiltGroupTrue) { vector<move> actual_moves = gs.get_legal_moves(); vector<move> exp_moves = { - move(1, 0, 1), - move(1, 0, 2) + move(move::mtype::regular, 1, 0, 1), + move(move::mtype::built_group, 1, 0, 2) }; ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; @@ -188,7 +189,7 @@ TEST(LegalMoveGen, MoveBuiltGroupFalse) { vector<move> actual_moves = gs.get_legal_moves(); vector<move> exp_moves = { - move(1, 0, 1) + move(move::mtype::regular, 1, 0, 1) }; ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; @@ -209,10 +210,10 @@ TEST(LegalMoveGen, Foundations) { vector<move> actual_moves = gs.get_legal_moves(); vector<move> exp_moves = { - move(4, 0), - move(5, 1), - move(6, 2), - move(7, 3) + move(move::mtype::regular, 4, 0), + move(move::mtype::regular, 5, 1), + move(move::mtype::regular, 6, 2), + move(move::mtype::regular, 7, 3) }; ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; @@ -234,7 +235,7 @@ TEST(LegalMoveGen, FoundationsRemovable) { vector<move> actual_moves = gs.get_legal_moves(); vector<move> exp_moves = { - move(0, 4) + move(move::mtype::regular, 0, 4) }; ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; @@ -252,9 +253,9 @@ TEST(LegalMoveGen, Cells) { vector<move> actual_moves = gs.get_legal_moves(); vector<move> exp_moves = { - move(0, 1), - move(0, 2), - move(2, 1) + move(move::mtype::regular, 0, 1), + move(move::mtype::regular, 0, 2), + move(move::mtype::regular, 2, 1) }; ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; @@ -276,7 +277,7 @@ TEST(LegalMoveGen, StockDealToWaste) { vector<move> actual_moves = gs.get_legal_moves(); vector<move> exp_moves = { - move(4, 5) + move(move::mtype::stock_to_waste, 4, 5) }; ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; @@ -297,7 +298,7 @@ TEST(LegalMoveGen, StockDealToTableau) { vector<move> actual_moves = gs.get_legal_moves(); vector<move> exp_moves = { - move(4, 255, 2) // Special stock-to-tableau syntax + move(move::mtype::stock_to_tableau, 0, 0, 2) // Special stock-to-tableau syntax }; ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; |
