Revamp get_all_moves tests.

master
Tait Hoyem 5 years ago
parent f33d3125a0
commit 400599fc91

@ -0,0 +1,123 @@
#include <constants.h>
const Position B_QUEEN_POS = E4;
const std::array<PieceType, 64> B_QUEEN_BOARD = {
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, B_QUEEN, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE
};
const std::vector<Position> B_QUEEN_ALL_MOVES = {
A8, E8,
B7, E7, H7,
C6, E6, G6,
D5, E5, F5,
A4, B4, C4, D4, E4, F4, G4, H4,
D3, E3, F3,
C2, E2, G2,
B1, E1, H1
};
const Position B_BISHOP_POS = D4;
const std::array<PieceType, 64> B_BISHOP_BOARD = {
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, B_BISHOP, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE
};
const std::vector<Position> B_BISHOP_ALL_MOVES = {
H8,
A7, G7,
B6, F6,
C5, E5,
D4,
C3, E3,
B2, F2,
A1, G1
};
const Position B_KNIGHT_POS = D5;
const std::array<PieceType, 64> B_KNIGHT_BOARD = {
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, B_KNIGHT, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE
};
const std::vector<Position> B_KNIGHT_ALL_MOVES = {
C7, E7,
B6, F6,
D5,
B4, F4,
C3, E3
};
const Position B_ROOK_POS = E5;
const std::array<PieceType, 64> B_ROOK_BOARD = {
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, B_ROOK, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE
};
const std::vector<Position> B_ROOK_ALL_MOVES = {
E8, E7, E6,
A5, B5, C5, D5, E5, F5, G5, H5,
E4, E3, E2, E1
};
const Position B_KING_POS = C4;
const std::array<PieceType, 64> B_KING_BOARD = {
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, B_KING, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE
};
const std::vector<Position> B_KING_ALL_MOVES = {
B5, C5, D5,
B4, C4, D4,
B3, C3, D3
};
const Position B_PAWN_POS = F4;
const std::array<PieceType, 64> B_PAWN_BOARD = {
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, B_PAWN, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE
};
const std::vector<Position> B_PAWN_ALL_MOVES = {
F4,
E3, F3, G3,
F2
};

@ -0,0 +1,133 @@
#include <constants.h>
const Position W_QUEEN_POS = E4;
const std::array<PieceType, 64> W_QUEEN_BOARD = {
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, W_QUEEN, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE
};
const std::array<PieceType, 64> W_QUEEN_BOARD_BLOCKED = {
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, B_PAWN, W_PAWN, B_PAWN, NONE, NONE,
NONE, NONE, NONE, W_KNIGHT, W_QUEEN, B_PAWN, NONE, NONE,
NONE, NONE, NONE, B_QUEEN, B_KNIGHT, W_PAWN, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE
};
const std::vector<Position> W_QUEEN_ALL_MOVES = {
A8, E8,
B7, E7, H7,
C6, E6, G6,
D5, E5, F5,
A4, B4, C4, D4, E4, F4, G4, H4,
D3, E3, F3,
C2, E2, G2,
B1, E1, H1
};
const Position W_BISHOP_POS = D4;
const std::array<PieceType, 64> W_BISHOP_BOARD = {
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, W_BISHOP, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE
};
const std::vector<Position> W_BISHOP_ALL_MOVES = {
H8,
A7, G7,
B6, F6,
C5, E5,
D4,
C3, E3,
B2, F2,
A1, G1
};
const Position W_KNIGHT_POS = D5;
const std::array<PieceType, 64> W_KNIGHT_BOARD = {
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, W_KNIGHT, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE
};
const std::vector<Position> W_KNIGHT_ALL_MOVES = {
C7, E7,
B6, F6,
D5,
B4, F4,
C3, E3
};
const Position W_ROOK_POS = E5;
const std::array<PieceType, 64> W_ROOK_BOARD = {
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, W_ROOK, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE
};
const std::vector<Position> W_ROOK_ALL_MOVES = {
E8, E7, E6,
A5, B5, C5, D5, E5, F5, G5, H5,
E4, E3, E2, E1
};
const Position W_KING_POS = C4;
const std::array<PieceType, 64> W_KING_BOARD = {
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, W_KING, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE
};
const std::vector<Position> W_KING_ALL_MOVES = {
B5, C5, D5,
B4, C4, D4,
B3, C3, D3
};
const Position W_PAWN_POS = F4;
const std::array<PieceType, 64> W_PAWN_BOARD = {
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, W_PAWN, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE
};
const std::vector<Position> W_PAWN_ALL_MOVES = {
F6,
E5, F5, G5,
F4
};

@ -0,0 +1,4 @@
# This gets all new text from W_test_boards.h and converts all W_ to B_ then appends it to B_test_boards.h
# The new file may have to be edited if there are Pawns,
diff="$(git diff W_test_boards.h | grep -e '^\+[^\+]' | sed 's/^\+//g' | sed 's/W_/B_/g')"
echo -e "$diff" >> B_test_boards.h

@ -0,0 +1,2 @@
#include "W_test_boards.h"
#include "B_test_boards.h"

@ -1,5 +1,6 @@
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include "test_boards.h"
#include <sstream>
#include <functions.h>
@ -74,7 +75,7 @@ namespace Catch {
for (int pi = 0; pi < poss.size(); ++pi){
pi == poss.size()-1 ? ss << poss[pi] << "(" << POSITION_STRING[poss[pi]] << ")" : ss << poss[pi] << "(" << POSITION_STRING[poss[pi]] << "), ";
}
ss << " }" << std::endl;
ss << " } }" << std::endl;
return ss.str();
}
};
@ -129,38 +130,21 @@ TEST_CASE("Test where this piece may move to", "[get_possible_moves]"){
CHECK(get_possible_moves(Position::A7, DEFAULT_BOARD) == black_A_pawn_possible_moves);
}
TEST_CASE("Test all possible and impossible moves", "[get_all_moves]"){
std::vector<Position> white_right_knight_all_moves = {Position::F3, Position::H3, Position::E2, Position::G1};
TEST_CASE("Test all possible and impossible moves for black pieces", "[get_all_moves][black]"){
CHECK(get_all_moves(B_KING_POS, B_KING_BOARD) == B_KING_ALL_MOVES);
CHECK(get_all_moves(B_QUEEN_POS, B_QUEEN_BOARD) == B_QUEEN_ALL_MOVES);
CHECK(get_all_moves(B_ROOK_POS, B_ROOK_BOARD) == B_ROOK_ALL_MOVES);
CHECK(get_all_moves(B_BISHOP_POS, B_BISHOP_BOARD) == B_BISHOP_ALL_MOVES);
CHECK(get_all_moves(B_KNIGHT_POS, B_KNIGHT_BOARD) == B_KNIGHT_ALL_MOVES);
CHECK(get_all_moves(B_PAWN_POS, B_PAWN_BOARD) == B_PAWN_ALL_MOVES);
std::vector<Position> black_A_pawn_all_moves = {Position::A7, Position::A6, Position::B6, Position::A5};
std::vector<Position> black_F_bishop_all_moves = {Position:F8, Position::E7, Position::G7, Position::D6, Position::H6, Position::C5, Position::B4, Position::A3};
std::vector<Position> black_queen_all_moves = {Position::A8, Position::B8, Position::C8, Position::D8, Position::E8, Position::F8, Position::G8, Position::H8, Position::C7, Position::D7, Position::E7, Position::B6, Position::D6, Position::F6, Position::A5, Position::D5, Position::G5, Position::D4, Position::H4, Position::D3, Position::D2, Position::D1};
std::vector<Position> white_A_rook_all_moves = {Position::A8, Position::A7, Position::A6, Position::A5, Position::A4, Position::A3, Position::A2, Position::A1, Position::B1, Position::C1, Position::D1, Position::E1, Position::F1, Position::G1, Position::H1};
std::vector<Position> white_king_all_moves = {Position::D2, Position::E2, Position::F2, Position::D1, Position::E1, Position::F1};
std::vector<Position> black_king_all_moves = {Position::D8, Position::E8, Position::F8, Position::D7, Position::E7, Position::F7};
std::vector<Position> white_F_bishop_all_moves = {Position::A6, Position::B5, Position::C4, Position::D3, Position::H3, Position::E2, Position::G2, Position::F1};
std::vector<Position> white_queen_all_moves = {Position::D8, Position::D7, Position::D6, Position::D5, Position::H5, Position::A4, Position::D4, Position::G4, Position::B3, Position::D3, Position::F3, Position::C2, Position::D2, Position::E2, Position::A1, Position::B1, Position::C1, Position::D1, Position::E1, Position::F1, Position::G1, Position::H1};
std::vector<Position> left_black_knight_all_moves = {Position::B8, Position::D7, Position::A6, Position::C6};
std::vector<Position> black_H_rook_all_moves = {Position::A8, Position::B8, Position::C8, Position::D8, Position::E8, Position::F8, Position::G8, Position::H8, Position::H7, Position::H6, Position::H5, Position::H4, Position::H3, Position::H2, Position::H1};
CHECK(get_all_moves(Position::H8, DEFAULT_BOARD) == black_H_rook_all_moves);
CHECK(get_all_moves(Position::G1, DEFAULT_BOARD) == white_right_knight_all_moves);
CHECK(get_all_moves(Position::A7, DEFAULT_BOARD) == black_A_pawn_all_moves);
CHECK(get_all_moves(Position::F8, DEFAULT_BOARD) == black_F_bishop_all_moves);
CHECK(get_all_moves(Position::D8, DEFAULT_BOARD) == black_queen_all_moves);
CHECK(get_all_moves(Position::A1, DEFAULT_BOARD) == white_A_rook_all_moves);
CHECK(get_all_moves(Position::E1, DEFAULT_BOARD) == white_king_all_moves);
CHECK(get_all_moves(Position::D1, DEFAULT_BOARD) == white_queen_all_moves);
CHECK(get_all_moves(Position::B8, DEFAULT_BOARD) == left_black_knight_all_moves);
}
TEST_CASE("Test all possible and impossible moves for whtie pieces", "[get_all_moves][white]"){
CHECK(get_all_moves(W_KING_POS, W_KING_BOARD) == W_KING_ALL_MOVES);
CHECK(get_all_moves(W_QUEEN_POS, W_QUEEN_BOARD) == W_QUEEN_ALL_MOVES);
CHECK(get_all_moves(W_ROOK_POS, W_ROOK_BOARD) == W_ROOK_ALL_MOVES);
CHECK(get_all_moves(W_BISHOP_POS, W_BISHOP_BOARD) == W_BISHOP_ALL_MOVES);
CHECK(get_all_moves(W_KNIGHT_POS, W_KNIGHT_BOARD) == W_KNIGHT_ALL_MOVES);
CHECK(get_all_moves(W_PAWN_POS, W_PAWN_BOARD) == W_PAWN_ALL_MOVES);
}

Loading…
Cancel
Save