bigger refactor in several files

This commit is contained in:
rektdie committed 2025-03-20 20:39:12 +01:00
1 parent 8d5024a4a4
commit 0ffc2c77de
7 files changed
+111 -112

No files matched your search

+16 -16
View File
@@ -29,8 +29,8 @@ void Board::SetByFen(std::string_view fen) {
// Starting from top left
int currSquare = a8;
std::vector<std::string> tokens = split(fen, ' ');
std::vector<std::string> pieceTokens = split(tokens[0], '/');
std::vector<std::string> tokens = UTILS::split(fen, ' ');
std::vector<std::string> pieceTokens = UTILS::split(tokens[0], '/');
constexpr std::string_view pieceTypes = "pnbrqk";
@@ -61,10 +61,10 @@ void Board::SetByFen(std::string_view fen) {
else if (piece == 'q') castlingRights |= blackQueenRight;
}
if (tokens[3] != "-") enPassantTarget = parseSquare(tokens[3]);
if (tokens[3] != "-") enPassantTarget = UTILS::parseSquare(tokens[3]);
occupied = colors[White] | colors[Black];
hashKey = GetHashKey(*this);
hashKey = UTILS::GetHashKey(*this);
MOVEGEN::GenerateMoves(*this);
MOVEGEN::GenAttackMaps(*this);
}
@@ -169,7 +169,7 @@ void Board::SetPiece(int piece, int square, bool color) {
colors[color].SetBit(square);
occupied.SetBit(square);
hashKey ^= zKeys[color][piece][square];
hashKey ^= UTILS::zKeys[color][piece][square];
}
void Board::RemovePiece(int piece, int square, bool color) {
@@ -177,14 +177,14 @@ void Board::RemovePiece(int piece, int square, bool color) {
colors[color].PopBit(square);
occupied.PopBit(square);
hashKey ^= zKeys[color][piece][square];
hashKey ^= UTILS::zKeys[color][piece][square];
}
// Updates castling rights
static void UpdateCastlingRights(Board &board, int square, int type, int color) {
if (type == Rook) {
// Removing old rights
board.hashKey ^= zCastle[board.castlingRights];
board.hashKey ^= UTILS::zCastle[board.castlingRights];
int queenSideRook = color ? a8 : a1;
int kingSideRook = color ? h8 : h1;
@@ -194,15 +194,15 @@ static void UpdateCastlingRights(Board &board, int square, int type, int color)
board.castlingRights &= color ? ~blackKingRight : ~whiteKingRight;
}
board.hashKey ^= zCastle[board.castlingRights];
board.hashKey ^= UTILS::zCastle[board.castlingRights];
} else if (type == King) {
// Removing old rights
board.hashKey ^= zCastle[board.castlingRights];
board.hashKey ^= UTILS::zCastle[board.castlingRights];
board.castlingRights &= color ? ~blackKingRight : ~whiteKingRight;
board.castlingRights &= color ? ~blackQueenRight : ~whiteQueenRight;
board.hashKey ^= zCastle[board.castlingRights];
board.hashKey ^= UTILS::zCastle[board.castlingRights];
}
}
@@ -224,14 +224,14 @@ void Board::MakeMove(Move move) {
int newEpTarget = noEPTarget;
sideToMove = !sideToMove;
hashKey ^= zSide;
hashKey ^= UTILS::zSide;
if (enPassantTarget != noEPTarget) {
hashKey ^= zEnPassant[enPassantTarget % 8];
hashKey ^= UTILS::zEnPassant[enPassantTarget % 8];
}
if (newEpTarget != noEPTarget) {
hashKey ^= zEnPassant[newEpTarget % 8];
hashKey ^= UTILS::zEnPassant[newEpTarget % 8];
}
enPassantTarget = newEpTarget;
@@ -328,14 +328,14 @@ void Board::MakeMove(Move move) {
UpdateCastlingRights(*this, move.MoveFrom(), attackerPiece, attackerColor);
sideToMove = !attackerColor;
hashKey ^= zSide;
hashKey ^= UTILS::zSide;
if (enPassantTarget != noEPTarget) {
hashKey ^= zEnPassant[enPassantTarget % 8];
hashKey ^= UTILS::zEnPassant[enPassantTarget % 8];
}
if (newEpTarget != noEPTarget) {
hashKey ^= zEnPassant[newEpTarget % 8];
hashKey ^= UTILS::zEnPassant[newEpTarget % 8];
}
enPassantTarget = newEpTarget;