Implement Search

This commit is contained in:
2022-12-23 18:34:34 +01:00
parent bcf4d66c49
commit 87adca7e66
15 changed files with 337 additions and 66 deletions

View File

@@ -25,6 +25,22 @@ static void testGameEnd(const char* fen, bool isMate) {
REQUIRE(pv.length() == 0);
}
static void testMove(const char *fen, const std::vector<std::string> &expectedMoves) {
auto engine = createEngine();
REQUIRE(engine != nullptr);
auto board = Fen::createBoard(fen);
REQUIRE(board.has_value());
for (const auto &moveName : expectedMoves) {
auto pv = engine->pv(board.value());
Move move = *pv.begin();
REQUIRE(move == Move::fromUci(moveName));
board->makeMove(move);
}
}
TEST_CASE("Engine detects checkmate", "[Engine][Checkmate]") {
auto fen = GENERATE(
// https://lichess.org/editor/4R2k/6pp/8/8/8/8/8/K7_b_-_-_0_1
@@ -46,3 +62,11 @@ TEST_CASE("Engine detects stalemate", "[Engine][Stalemate]") {
testGameEnd(fen, false);
}
TEST_CASE("Puzzles mateIn1_simple", "[Engine][Puzzle]") {
auto [fen, moves] = GENERATE(table<const char*, std::vector<std::string>>({
{"2bQ1k1r/1p3p2/p4b1p/4pNp1/2q5/8/PPP2PPP/1K1RR3 b - - 3 23",{"f6d8", "d1d8"}}, // https://lichess.org/gQa01loO/black#46
{"5rk1/ppp5/2n4p/3b2p1/6R1/P1B1P2P/1Pq5/R2Q2K1 b - - 3 29",{"c2f2"}}, // https://lichess.org/haKJxadR#57
}));
testMove(fen, moves);
}