diff options
| author | Charlie Blake | 2018-07-03 14:51:07 +0100 |
|---|---|---|
| committer | GitHub | 2018-07-03 14:51:07 +0100 |
| commit | b7953f5b0a5d155fc87e9ec5b17525d9ac42c6b7 (patch) | |
| tree | e220211c8313be2b25f1aebf537ffbf4a352f1db /src/test/unit_tests | |
| parent | Merge pull request #71 from thecharlesblake/correct-klondike (diff) | |
| parent | Tidy up stock rep and amend broken unit tests (diff) | |
| download | metasol-b7953f5b0a5d155fc87e9ec5b17525d9ac42c6b7.tar.gz metasol-b7953f5b0a5d155fc87e9ec5b17525d9ac42c6b7.zip | |
Merge pull request #72 from thecharlesblake/k-plus-stock
K plus stock
Diffstat (limited to 'src/test/unit_tests')
| -rw-r--r-- | src/test/unit_tests/built_group_move_gen_test.cpp | 80 | ||||
| -rw-r--r-- | src/test/unit_tests/k_plus_stock_test.cpp | 369 | ||||
| -rw-r--r-- | src/test/unit_tests/legal_move_gen_test.cpp | 24 |
3 files changed, 442 insertions, 31 deletions
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..7bc7f46 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; @@ -155,7 +156,8 @@ TEST(BuiltGroupMoveGen, CantMove) { TEST(BuiltGroupMoveGen, SameSuitOccupied) { sol_rules sr; - sr.tableau_pile_count = 5; + sr.tableau_pile_count = 6; + sr.build_pol = pol::SAME_SUIT; sr.built_group_pol = pol::SAME_SUIT; sr.move_built_group = true; @@ -166,7 +168,8 @@ TEST(BuiltGroupMoveGen, SameSuitOccupied) { {"3C", "2C", "AC"}, // Same suit {"3H", "2S", "AH"}, // Red black {"3D", "2D", "AS"}, // Any suit - {} + {}, + {"3C"} }, { // Regular moves @@ -174,18 +177,22 @@ TEST(BuiltGroupMoveGen, SameSuitOccupied) { move(move::mtype::regular, 2, 4, 1), move(move::mtype::regular, 3, 4, 1), move(move::mtype::regular, 0, 4, 1), + move(move::mtype::regular, 5, 4, 1), + move(move::mtype::regular, 5, 0, 1), // Built group moves 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, 1, 4, 3), + move(move::mtype::built_group, 1, 5, 2) } ); } TEST(BuiltGroupMoveGen, RedBlackOccupied) { sol_rules sr; - sr.tableau_pile_count = 5; + sr.tableau_pile_count = 6; + sr.build_pol = pol::RED_BLACK; sr.built_group_pol = pol::RED_BLACK; sr.move_built_group = true; @@ -196,7 +203,8 @@ TEST(BuiltGroupMoveGen, RedBlackOccupied) { {"3C", "2C", "AC"}, // Same suit {"3H", "2S", "AH"}, // Red black {"3D", "2D", "AS"}, // Any suit - {} + {}, + {"3C"} }, { // Regular moves @@ -204,19 +212,22 @@ TEST(BuiltGroupMoveGen, RedBlackOccupied) { move(move::mtype::regular, 2, 4, 1), move(move::mtype::regular, 3, 4, 1), move(move::mtype::regular, 0, 4, 1), + move(move::mtype::regular, 5, 4, 1), // Built group moves 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) + move(move::mtype::built_group, 3, 4, 2), + move(move::mtype::built_group, 3, 5, 2) } ); } TEST(BuiltGroupMoveGen, AnySuitOccupied) { sol_rules sr; - sr.tableau_pile_count = 5; + sr.tableau_pile_count = 6; + sr.build_pol = pol::ANY_SUIT; sr.built_group_pol = pol::ANY_SUIT; sr.move_built_group = true; @@ -227,7 +238,8 @@ TEST(BuiltGroupMoveGen, AnySuitOccupied) { {"3C", "2C", "AC"}, // Same suit {"3H", "2S", "AH"}, // Red black {"3D", "2D", "AS"}, // Any suit - {} + {}, + {"3C"} }, { // Regular moves @@ -235,6 +247,8 @@ TEST(BuiltGroupMoveGen, AnySuitOccupied) { move(move::mtype::regular, 2, 4, 1), move(move::mtype::regular, 3, 4, 1), move(move::mtype::regular, 0, 4, 1), + move(move::mtype::regular, 5, 4, 1), + move(move::mtype::regular, 5, 0, 1), // Built group moves move(move::mtype::built_group, 1, 0, 3), @@ -249,6 +263,56 @@ TEST(BuiltGroupMoveGen, AnySuitOccupied) { move(move::mtype::built_group, 3, 4, 2), move(move::mtype::built_group, 3, 4, 3), + + move(move::mtype::built_group, 1, 5, 2), + move(move::mtype::built_group, 2, 5, 2), + move(move::mtype::built_group, 3, 5, 2) + } + ); +} + +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 new file mode 100644 index 0000000..1507f1d --- /dev/null +++ b/src/test/unit_tests/k_plus_stock_test.cpp @@ -0,0 +1,369 @@ +// +// Created by thecharlesblake on 1/11/18. +// + +#include <gtest/gtest.h> + +#include "../test_helper.h" +#include "../../main/game/search-state/game_state.h" +#include "../../main/game/sol_rules.h" + +typedef sol_rules::build_policy pol; +typedef sol_rules::stock_deal_type sdt; + +using std::vector; +using std::ostream; +using std::initializer_list; + + +TEST(KPlusStock, NoRedealExact) { + sol_rules sr; + sr.tableau_pile_count = 3; + 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; + + test_helper::k_plus_stock_test( + sr, + { + {"2H","2D","3S","AD","2S","3C","AC","AH","AS"}, + {}, + {"3D"}, + {"3H"}, + {"2C"} + }, + { + move(move::mtype::stock_k_plus, 0, 4, 2), + move(move::mtype::stock_k_plus, 0, 3, 8), + }, + move(move::mtype::stock_k_plus, 0, 3, 8), + 0, 8, + card(), "2D" + ); +} + +TEST(KPlusStock, NoRedealOneExtra) { + sol_rules sr; + sr.tableau_pile_count = 3; + 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; + + test_helper::k_plus_stock_test( + sr, + { + {"2H","AD","2S","3C","AC","AH","AS"}, + {}, + {"3D"}, + {"3H"}, + {"2C"} + }, + { + move(move::mtype::stock_k_plus, 0, 4, 2), + move(move::mtype::stock_k_plus, 0, 3, 6), + }, + move(move::mtype::stock_k_plus, 0, 3, 6), + 0, 6, + card(), "AD" + ); +} + +TEST(KPlusStock, NoRedealTwoExtra) { + sol_rules sr; + sr.tableau_pile_count = 3; + 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; + + test_helper::k_plus_stock_test( + sr, + { + {"2S","2H","AD","2D","3C","AC","AH","AS"}, + {}, + {"3D"}, + {"3H"}, + {"2C"} + }, + { + move(move::mtype::stock_k_plus, 0, 4, 2) + }, + move(move::mtype::stock_k_plus, 0, 4, 2), + 5, 2, + "3C", "AH" + ); +} + +TEST(KPlusStock, RedealExact) { + sol_rules sr; + sr.tableau_pile_count = 3; + 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; + + test_helper::k_plus_stock_test( + sr, + { + {"2H","2D","3S","AD","2S","3C","AC","AH","AS"}, + {}, + {"3D"}, + {"3H"}, + {"2C"} + }, + { + move(move::mtype::stock_k_plus, 0, 4, 2), + move(move::mtype::stock_k_plus, 0, 3, 8), + }, + move(move::mtype::stock_k_plus, 0, 3, 8), + 8, 0, + "AS", card() + ); +} + +TEST(KPlusStock, RedealOneExtra) { + sol_rules sr; + sr.tableau_pile_count = 3; + 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; + + test_helper::k_plus_stock_test( + sr, + { + {"2H","AD","2S","3C","AC","AH","AS"}, + {}, + {"3D"}, + {"3H"}, + {"2C"} + }, + { + move(move::mtype::stock_k_plus, 0, 4, 2), + move(move::mtype::stock_k_plus, 0, 3, 6), + }, + move(move::mtype::stock_k_plus, 0, 3, 6), + 6, 0, + "AS", card() + ); +} + +TEST(KPlusStock, RedealTwoExtra) { + sol_rules sr; + sr.tableau_pile_count = 3; + 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; + + test_helper::k_plus_stock_test( + sr, + { + {"2S","2H","AD","2D","3C","AC","AH","AS"}, + {}, + {"3D"}, + {"3H"}, + {"2C"} + }, + { + move(move::mtype::stock_k_plus, 0, 4, 2) + }, + move(move::mtype::stock_k_plus, 0, 4, 2), + 5, 2, + "3C", "AH" + ); +} + +TEST(KPlusStock, RedealKPlus3Waste) { + sol_rules sr; + sr.tableau_pile_count = 3; + 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; + + test_helper::k_plus_stock_test( + sr, + { + {"2H","2D","3S","AD","2S","3C"}, + {"AS","AH","AC"}, + {"3D"}, + {"3H"}, + {"2C"} + }, + { + move(move::mtype::stock_k_plus, 0, 3, 5), + move(move::mtype::stock_k_plus, 0, 4, 8), + move(move::mtype::regular, 1, 4, 1) + }, + move(move::mtype::stock_k_plus, 0, 4, 8), + 6, 2, + "3C", "AH" + ); +} + +TEST(KPlusStock, RedealKPlus4Waste) { + sol_rules sr; + sr.tableau_pile_count = 3; + 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; + + test_helper::k_plus_stock_test( + sr, + { + {"2H","AD","3S","2D","2S"}, + {"AS","AH","AC","3C"}, + {"3D"}, + {"3H"}, + {"2C"} + }, + { + 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_k_plus, 0, 2, 1), + 3, 5, + "3S", "2S" + ); +} + +TEST(KPlusStock, RedealKPlus5Waste) { + sol_rules sr; + sr.tableau_pile_count = 3; + sr.build_pol = pol::SAME_SUIT; + sr.stock_size = 10; + sr.stock_deal_t = sdt::WASTE; + sr.stock_redeal = true; + sr.stock_deal_count = 3; + + test_helper::k_plus_stock_test( + sr, + { + {"2S","2D","2H","AD","2S"}, + {"AS","AH","AC","3C","4S"}, + {"3D"}, + {"3H"}, + {"2C"} + }, + { + 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_k_plus, 0, 3, 2), + 2, 7, + "2D", "AD" + ); +} + +TEST(KPlusStock, RedealKPlusEmptyStock) { + sol_rules sr; + sr.tableau_pile_count = 3; + 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; + + test_helper::k_plus_stock_test( + sr, + { + {"2H","2D","3S","AD","2S","3C"}, + {"AS","AH","AC"}, + {"3D"}, + {"3H"}, + {"2C"} + }, + { + move(move::mtype::stock_k_plus, 0, 3, 5), + move(move::mtype::stock_k_plus, 0, 4, 8), + move(move::mtype::regular, 1, 4, 1) + }, + 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" + ); +} diff --git a/src/test/unit_tests/legal_move_gen_test.cpp b/src/test/unit_tests/legal_move_gen_test.cpp index 6ea73d5..cbdeae0 100644 --- a/src/test/unit_tests/legal_move_gen_test.cpp +++ b/src/test/unit_tests/legal_move_gen_test.cpp @@ -262,28 +262,6 @@ TEST(LegalMoveGen, Cells) { ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; } -TEST(LegalMoveGen, StockDealToWaste) { - sol_rules sr; - sr.foundations = true; - sr.tableau_pile_count = 3; - sr.stock_size = 2; - sr.stock_deal_t = sdt::WASTE; - - game_state gs(sr, string_il{ - {}, {}, {}, {}, // The foundations - {"AC", "AD"}, // The stock - {}, // The waste - {}, {}, {} // The tableau piles - }); - vector<move> actual_moves = gs.get_legal_moves(); - - vector<move> exp_moves = { - move(move::mtype::stock_to_waste, 4, 5) - }; - - ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; -} - TEST(LegalMoveGen, StockDealToTableau) { sol_rules sr; sr.foundations = true; @@ -299,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; |
