diff options
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/test_helper.cpp | 12 | ||||
| -rw-r--r-- | src/test/unit_tests/built_group_move_gen_test.cpp | 47 | ||||
| -rw-r--r-- | src/test/unit_tests/k_plus_stock_test.cpp | 132 | ||||
| -rw-r--r-- | src/test/unit_tests/legal_move_gen_test.cpp | 2 |
4 files changed, 156 insertions, 37 deletions
diff --git a/src/test/test_helper.cpp b/src/test/test_helper.cpp index 333cc07..c85cf39 100644 --- a/src/test/test_helper.cpp +++ b/src/test/test_helper.cpp @@ -105,18 +105,18 @@ void test_helper::k_plus_stock_test gs.make_move(m); - ASSERT_EQ(gs.get_data()[0].size(), stock_size) << gs.get_data()[0].size(); - ASSERT_EQ(gs.get_data()[1].size(), waste_size) << gs.get_data()[1].size(); + ASSERT_EQ(gs.get_data()[gs.stock].size(), stock_size) << gs.get_data()[gs.stock].size(); + ASSERT_EQ(gs.get_data()[gs.waste].size(), waste_size) << gs.get_data()[gs.waste].size(); if (top_stock == card()) - ASSERT_TRUE(gs.get_data()[0].empty()); + ASSERT_TRUE(gs.get_data()[gs.stock].empty()); else - ASSERT_EQ(gs.get_data()[0].top_card(), top_stock ) << gs.get_data()[0].top_card().to_string(); + ASSERT_EQ(gs.get_data()[gs.stock].top_card(), top_stock ) << gs.get_data()[gs.stock].top_card().to_string(); if (top_waste == card()) - ASSERT_TRUE(gs.get_data()[1].empty()); + ASSERT_TRUE(gs.get_data()[gs.waste].empty()); else - ASSERT_EQ(gs.get_data()[1].top_card(), top_waste ) << gs.get_data()[1].top_card().to_string(); + ASSERT_EQ(gs.get_data()[gs.waste].top_card(), top_waste ) << gs.get_data()[gs.waste].top_card().to_string(); gs.undo_move(m); 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 37a2cf0..cba54d9 100644 --- a/src/test/unit_tests/built_group_move_gen_test.cpp +++ b/src/test/unit_tests/built_group_move_gen_test.cpp @@ -9,6 +9,7 @@ #include "../../main/game/sol_rules.h" typedef sol_rules::build_policy pol; +typedef sol_rules::spaces_policy s_pol; using std::vector; using std::ostream; @@ -252,3 +253,49 @@ TEST(BuiltGroupMoveGen, AnySuitOccupied) { } ); } + +TEST(BuiltGroupMoveGen, KingsOnly) { + sol_rules sr; + sr.tableau_pile_count = 5; + sr.build_pol = pol::SAME_SUIT; + sr.built_group_pol = pol::RED_BLACK; + sr.move_built_group = true; + sr.spaces_pol = s_pol::KINGS; + + test_helper::expected_moves_test( + sr, + { + {}, + {"KC", "QC", "JC"}, // Same suit + {"KH", "QS", "JH"}, // Red black + {"KD", "QD", "JS"}, // Any suit + {} + }, + { + // Built group moves + move(move::mtype::built_group, 2, 0, 3), + move(move::mtype::built_group, 2, 4, 3) + } + ); +} + +TEST(BuiltGroupMoveGen, NoBuild) { + sol_rules sr; + sr.tableau_pile_count = 5; + sr.build_pol = pol::SAME_SUIT; + sr.built_group_pol = pol::RED_BLACK; + sr.move_built_group = true; + sr.spaces_pol = s_pol::NO_BUILD; + + test_helper::expected_moves_test( + sr, + { + {}, + {"KC", "QC", "JC"}, // Same suit + {"KH", "QS", "JH"}, // Red black + {"KD", "QD", "JS"}, // Any suit + {} + }, + {} + ); +} diff --git a/src/test/unit_tests/k_plus_stock_test.cpp b/src/test/unit_tests/k_plus_stock_test.cpp index 5877330..f56373e 100644 --- a/src/test/unit_tests/k_plus_stock_test.cpp +++ b/src/test/unit_tests/k_plus_stock_test.cpp @@ -35,10 +35,10 @@ TEST(KPlusStock, NoRedealExact) { {"2C"} }, { - move(move::mtype::stock_to_waste, 0, 4, 2), - move(move::mtype::stock_to_waste, 0, 3, 8), + move(move::mtype::stock_k_plus, 0, 4, 2), + move(move::mtype::stock_k_plus, 0, 3, 8), }, - move(move::mtype::stock_to_waste, 0, 3, 8), + move(move::mtype::stock_k_plus, 0, 3, 8), 0, 8, card(), "2D" ); @@ -63,10 +63,10 @@ TEST(KPlusStock, NoRedealOneExtra) { {"2C"} }, { - move(move::mtype::stock_to_waste, 0, 4, 2), - move(move::mtype::stock_to_waste, 0, 3, 6), + move(move::mtype::stock_k_plus, 0, 4, 2), + move(move::mtype::stock_k_plus, 0, 3, 6), }, - move(move::mtype::stock_to_waste, 0, 3, 6), + move(move::mtype::stock_k_plus, 0, 3, 6), 0, 6, card(), "AD" ); @@ -91,9 +91,9 @@ TEST(KPlusStock, NoRedealTwoExtra) { {"2C"} }, { - move(move::mtype::stock_to_waste, 0, 4, 2) + move(move::mtype::stock_k_plus, 0, 4, 2) }, - move(move::mtype::stock_to_waste, 0, 4, 2), + move(move::mtype::stock_k_plus, 0, 4, 2), 5, 2, "3C", "AH" ); @@ -118,10 +118,10 @@ TEST(KPlusStock, RedealExact) { {"2C"} }, { - move(move::mtype::stock_to_waste, 0, 4, 2), - move(move::mtype::stock_to_waste, 0, 3, 8), + move(move::mtype::stock_k_plus, 0, 4, 2), + move(move::mtype::stock_k_plus, 0, 3, 8), }, - move(move::mtype::stock_to_waste, 0, 3, 8), + move(move::mtype::stock_k_plus, 0, 3, 8), 8, 0, "AS", card() ); @@ -146,10 +146,10 @@ TEST(KPlusStock, RedealOneExtra) { {"2C"} }, { - move(move::mtype::stock_to_waste, 0, 4, 2), - move(move::mtype::stock_to_waste, 0, 3, 6), + move(move::mtype::stock_k_plus, 0, 4, 2), + move(move::mtype::stock_k_plus, 0, 3, 6), }, - move(move::mtype::stock_to_waste, 0, 3, 6), + move(move::mtype::stock_k_plus, 0, 3, 6), 6, 0, "AS", card() ); @@ -174,9 +174,9 @@ TEST(KPlusStock, RedealTwoExtra) { {"2C"} }, { - move(move::mtype::stock_to_waste, 0, 4, 2) + move(move::mtype::stock_k_plus, 0, 4, 2) }, - move(move::mtype::stock_to_waste, 0, 4, 2), + move(move::mtype::stock_k_plus, 0, 4, 2), 5, 2, "3C", "AH" ); @@ -201,10 +201,10 @@ TEST(KPlusStock, RedealKPlus3Waste) { {"2C"} }, { - move(move::mtype::stock_to_waste, 0, 3, 5), - move(move::mtype::stock_to_waste, 0, 4, 8) + move(move::mtype::stock_k_plus, 0, 3, 5), + move(move::mtype::stock_k_plus, 0, 4, 8) }, - move(move::mtype::stock_to_waste, 0, 4, 8), + move(move::mtype::stock_k_plus, 0, 4, 8), 6, 2, "3C", "AH" ); @@ -229,11 +229,11 @@ TEST(KPlusStock, RedealKPlus4Waste) { {"2C"} }, { - move(move::mtype::stock_to_waste, 0, 3, 4), - move(move::mtype::stock_to_waste, 0, 4, 7), - move(move::mtype::stock_to_waste, 0, 2, 1) + move(move::mtype::stock_k_plus, 0, 3, 4), + move(move::mtype::stock_k_plus, 0, 4, 7), + move(move::mtype::stock_k_plus, 0, 2, 1) }, - move(move::mtype::stock_to_waste, 0, 2, 1), + move(move::mtype::stock_k_plus, 0, 2, 1), 3, 5, "3S", "2S" ); @@ -258,11 +258,11 @@ TEST(KPlusStock, RedealKPlus5Waste) { {"2C"} }, { - move(move::mtype::stock_to_waste, 0, 3, 2), - move(move::mtype::stock_to_waste, 0, 4, 7), - move(move::mtype::stock_to_waste, 0, 2, 3) + move(move::mtype::stock_k_plus, 0, 3, 2), + move(move::mtype::stock_k_plus, 0, 4, 7), + move(move::mtype::stock_k_plus, 0, 2, 3) }, - move(move::mtype::stock_to_waste, 0, 3, 2), + move(move::mtype::stock_k_plus, 0, 3, 2), 2, 7, "2D", "AD" ); @@ -287,11 +287,83 @@ TEST(KPlusStock, RedealKPlusEmptyStock) { {"2C"} }, { - move(move::mtype::stock_to_waste, 0, 3, 5), - move(move::mtype::stock_to_waste, 0, 4, 8) + move(move::mtype::stock_k_plus, 0, 3, 5), + move(move::mtype::stock_k_plus, 0, 4, 8) }, - move(move::mtype::stock_to_waste, 0, 3, 5), + move(move::mtype::stock_k_plus, 0, 3, 5), 8, 0, "AS", card() ); } + +TEST(KPlusStock, NoRedealCellFoundationMoves) { + sol_rules sr; + sr.build_pol = pol::SAME_SUIT; + sr.stock_size = 9; + sr.stock_deal_t = sdt::WASTE; + sr.stock_redeal = false; + sr.stock_deal_count = 3; + sr.cells = 2; + sr.foundations = true; + + test_helper::k_plus_stock_test( + sr, + { + {"AC"}, {}, {}, {}, + {"2D"}, {}, + {"2H","AS","2C","AH","2S","3C"}, + {"3S"} + }, + { + // Cell moves + move(move::mtype::stock_k_plus, 6, 5, 2), + move(move::mtype::stock_k_plus, 6, 5, 5), + + // Foundation moves + move(move::mtype::stock_k_plus, 6, 1, 2), + + // Regular waste move + move(move::mtype::regular, 7, 5, 1) + }, + move(move::mtype::stock_k_plus, 6, 1, 2), + 3, 3, + "2C", "2S" + ); +} + +TEST(KPlusStock, RedealCellFoundationMoves) { + sol_rules sr; + sr.build_pol = pol::SAME_SUIT; + sr.stock_size = 9; + sr.stock_deal_t = sdt::WASTE; + sr.stock_redeal = true; + sr.stock_deal_count = 3; + sr.cells = 2; + sr.foundations = true; + + test_helper::k_plus_stock_test( + sr, + { + {"AC"}, {}, {}, {}, + {"2D"}, {}, + {"2H","AS","2C","AH","2S","3C"}, + {"3S"} + }, + { + // Cell moves + move(move::mtype::stock_k_plus, 6, 5, 2), + move(move::mtype::stock_k_plus, 6, 5, 5), + move(move::mtype::stock_k_plus, 6, 5, 1), + move(move::mtype::stock_k_plus, 6, 5, 4), + + // Foundation moves + move(move::mtype::stock_k_plus, 6, 1, 2), + move(move::mtype::stock_k_plus, 6, 2, 4) + }, + move(move::mtype::stock_k_plus, 6, 2, 4), + 1, 5, + "2H", "2C" + ); +} + +// TODO: add to logic if !redeal && !piles[waste].empty(), consider top waste card too ===>>> FOR ALL 3 WASTE/STOCK MOVE TYPES diff --git a/src/test/unit_tests/legal_move_gen_test.cpp b/src/test/unit_tests/legal_move_gen_test.cpp index 5155138..cbdeae0 100644 --- a/src/test/unit_tests/legal_move_gen_test.cpp +++ b/src/test/unit_tests/legal_move_gen_test.cpp @@ -277,7 +277,7 @@ TEST(LegalMoveGen, StockDealToTableau) { vector<move> actual_moves = gs.get_legal_moves(); vector<move> exp_moves = { - move(move::mtype::stock_to_tableau, 0, 0, 2) // Special stock-to-tableau syntax + move(move::mtype::stock_to_all_tableau, 0, 0, 2) // Special stock-to-tableau syntax }; ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; |
