Improve preformace. Add tests.

master
Tait Hoyem 5 years ago
parent 6269bc0311
commit 695c8f5b8e

@ -181,7 +181,7 @@ void filter_checked_moves(PieceType pt, const std::array<PieceType, 120>& board,
}
// Make move
std::array<PieceType, 120> moved_board;
dumb_move(*p_pn, board, moved_board);
dumb_move(*p_pn, board, moved_board);
// This is for when the king is the same piece that is moving.
// If this is the case, reset to king position to the new position given by the get_to_sq() of the move.
if (pt == my_king){

@ -308,3 +308,8 @@ TEST_CASE("Test for add_checked_flags is working correctly.", "[get_all_moves][a
CHECK(get_checked_flags(rook_checked_flags) == ROOK_CHECK_FLAGS);
}
TEST_CASE("Test that kings cannot move backwards into check", "[get_all_moves]"){
auto king_back_checked = get_all_moves(BACK_CHECK_POS, BACK_CHECK_BOARD);
CHECK(get_to_squares(king_back_checked) == BACK_CHECK_KING_MOVES);
}

@ -917,3 +917,24 @@ const std::vector<int> ROOK_CHECK_FLAGS = {
0, 1
};
// This tests that kings cannot move backward into check from check
const int BACK_CHECK_POS = E6;
const std::array<PieceType, 120> BACK_CHECK_BOARD = {
INV, INV, INV, INV, INV, INV, INV, INV, INV, INV,
INV, INV, INV, INV, INV, INV, INV, INV, INV, INV,
INV, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, INV,
INV, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, INV,
INV, NONE, NONE, NONE, NONE, B_KING, NONE, NONE, NONE, INV,
INV, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, INV,
INV, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, INV,
INV, NONE, NONE, NONE, NONE, W_ROOK, NONE, NONE, NONE, INV,
INV, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, INV,
INV, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, INV,
INV, INV, INV, INV, INV, INV, INV, INV, INV, INV,
INV, INV, INV, INV, INV, INV, INV, INV, INV, INV
};
const std::vector<int> BACK_CHECK_KING_MOVES = {
D7, F7,
D5, F5,
F6, D6
};

Loading…
Cancel
Save