Half-done fixing the conversion of moves to bit-shifted variants

master
Tait Hoyem 5 years ago
parent 0b84fcf8e0
commit 52ec82f7df

@ -188,15 +188,3 @@ std::array<PieceType, 120> dumb_move(int move, std::array<PieceType, 120> board)
board[from] = PieceType::NONE;
return board;
}
std::unordered_set<int> get_to_squares(std::unordered_set<int> moves){
std::unordered_set<int> to_squares;
for (int move : moves){
to_squares.insert(get_to_sq(move));
}
return to_squares;
}
std::unordered_set<int> get_from_squared(std::unordered_set<int> moves){
std::unordered_set<int> from_squares;
return from_squares;
}

@ -49,8 +49,3 @@ std::unordered_set<int> get_all_moves(int pos, std::array<PieceType, 120> board,
// Does not check if move is valid, just does it.
std::array<PieceType, 120> dumb_move(int move, std::array<PieceType, 120> board);
// Allow the developer to get only certain pieces of the part of a move in a list.
// This will return a vector (or unordered_set) of elements with only a certain part of the move revealed bit bit-switching.
std::unordered_set<int> get_from_squares(std::unordered_set<int> moves);
std::unordered_set<int> get_to_squares(std::unordered_set<int> moves);

@ -12,4 +12,4 @@ bitwise.out: catch_main.o
# TODO: Allw all.out to contain bitwise tests
all.out: catch_main.o custom_printing.o
g++ -std=c++11 -ggdb -w -I../src/ -o all.out ../src/functions.cpp catch_main.o custom_printing.o main.cpp
g++ -std=c++11 -ggdb -w -I../src/ -o all.out ../src/functions.cpp catch_main.o custom_printing.o test_functions.cpp main.cpp

@ -2,6 +2,7 @@
#include "test_boards.h"
#include "valid_moves.h"
#include "custom_printing.cpp"
#include "test_functions.h"
#include <sstream>
#include <functions.h>
@ -105,7 +106,10 @@ TEST_CASE("Test all moves for black in edge cases.", "[get_all_moves][black]"){
TEST_CASE("Test that moves that put king in check are not returned", "[get_all_moves]"){
CHECK(get_to_squares(get_all_moves(ROOK_CHECK_TEST_POS, ROOK_CHECK_TEST_BOARD)) == ROOK_CHECK_TEST_MOVES);
CHECK(get_to_squares(get_all_moves(PAWN_CHECK_TEST_POS, PAWN_CHECK_TEST_BOARD)) == PAWN_CHECK_TEST_MOVES);
CHECK(get_to_squares(get_all_moves(PAWN_DIAG_TEST1_POS, PAWN_DIAG_TEST1_BOARD)) == PAWN_DIAG_TEST1_MOVES);
auto pawn_diag_moves = get_all_moves(PAWN_DIAG_TEST1_POS, PAWN_DIAG_TEST1_BOARD);
std::unordered_set<int> pawn_start_flags = {0, 1, 0};
CHECK(get_to_squares(pawn_diag_moves) == PAWN_DIAG_TEST1_MOVES);
CHECK(get_pawn_start_flags(pawn_diag_moves) == pawn_start_flags);
}
TEST_CASE("Tests for en pessant squares.", "[get_all_moves]"){

@ -0,0 +1,56 @@
#include "test_functions.h"
#include <bitwise.h>
#include <unordered_set>
#include <algorithm>
std::unordered_set<int> get_to_squares(std::unordered_set<int> moves){
std::unordered_set<int> transformed;
for (int mv : moves){
transformed.insert(get_to_sq(mv));
}
return transformed;
}
std::unordered_set<int> get_from_squared(std::unordered_set<int> moves){
std::unordered_set<int> transformed;
for (int mv : moves){
transformed.insert(get_from_sq(mv));
}
return transformed;
}
std::unordered_set<int> get_captured_pieces(std::unordered_set<int> moves){
std::unordered_set<int> transformed;
for (int mv : moves){
transformed.insert(get_captured_pc(mv));
}
return transformed;
}
std::unordered_set<int> get_promoted_pieces(std::unordered_set<int> moves){
std::unordered_set<int> transformed;
for (int mv : moves){
transformed.insert(get_promoted_to_pc(mv));
}
return transformed;
}
std::unordered_set<int> get_en_passant_flags(std::unordered_set<int> moves){
std::unordered_set<int> transformed;
for (int mv : moves){
transformed.insert(get_en_pass_flag(mv));
}
return transformed;
}
std::unordered_set<int> get_pawn_start_flags(std::unordered_set<int> moves){
std::unordered_set<int> transformed;
for (int mv : moves){
std::cout << "MOVE: \n";
transformed.insert(get_pawn_st_flag(mv));
}
return transformed;
}
std::unordered_set<int> get_castle_flags(std::unordered_set<int> moves){
std::unordered_set<int> transformed;
for (int mv : moves){
transformed.insert(get_castle_flag(mv));
}
return transformed;
}

@ -0,0 +1,12 @@
#ifndef TEST_FUNCTIONS_H
#define TEST_FUNCTOPMS_H
#include <unordered_set>
std::unordered_set<int> get_from_squares(std::unordered_set<int> moves);
std::unordered_set<int> get_to_squares(std::unordered_set<int> moves);
std::unordered_set<int> get_captured_pieces(std::unordered_set<int> moves);
std::unordered_set<int> get_promoted_pieces(std::unordered_set<int> moves);
std::unordered_set<int> get_en_passant_flags(std::unordered_set<int> moves);
std::unordered_set<int> get_pawn_start_flags(std::unordered_set<int> moves);
std::unordered_set<int> get_castle_flags(std::unordered_set<int> moves);
#endif
Loading…
Cancel
Save