Cleared previous method of movegen

This commit is contained in:
rektdie committed 2024-04-04 22:49:56 +02:00
1 parent cc4409ef3d
commit 09dfeb7198
6 files changed
+50 -467

No files matched your search

+2 -138
View File
@@ -243,9 +243,7 @@ void Board::ResetMoves() {
void Board::ListMoves() {
int count = 1;
for (Move move : moveList) {
std::cout << count << ". ";
move.PrintMove();
count++;
}
}
@@ -299,139 +297,5 @@ void Board::Promote(int square, int pieceType, int color, bool isCapture) {
}
void Board::MakeMove(Move move) {
int oldEPTarget = enPassantTarget;
enPassantTarget = a1; // resetting (a1 is impossible)
std::array<bool, 4> oldCastlingRights = castlingRights;
uint16_t moveType = move.moveFlags;
int attackerType = GetPieceType(move.moveFrom);
bool attackerColor = GetPieceColor(move.moveFrom);
int targetType = GetPieceType(move.moveTo);
int direction = attackerColor ? south : north;
// Removing attacker from old square
RemovePiece(attackerType, move.moveFrom, attackerColor);
if (moveType == doublePawnPush) {
enPassantTarget = move.moveFrom + direction;
} else if (moveType == capture) {
RemovePiece(targetType, move.moveTo, !attackerColor);
} else if (moveType == epCapture) {
targetType = Pawn;
RemovePiece(targetType, move.moveTo - direction, !attackerColor);
} else if (moveType == queenCastle) {
int rookSquare = attackerColor ? a8 : a1;
// Removing rook from old position
RemovePiece(Rook, rookSquare, attackerColor);
// Setting rook on new position
SetPiece(Rook, rookSquare + 3, attackerColor);
} else if (moveType == kingCastle) {
int rookSquare = attackerColor ? h8 : h1;
// Removing rook from old position
RemovePiece(Rook, rookSquare, attackerColor);
// Setting rook on new position
SetPiece(Rook, rookSquare - 2, attackerColor);
} else if (moveType == knightPromotion) {
Promote(move.moveTo, Knight, attackerColor, false);
} else if (moveType == bishopPromotion) {
Promote(move.moveTo, Bishop, attackerColor, false);
} else if (moveType == rookPromotion) {
Promote(move.moveTo, Rook, attackerColor, false);
} else if (moveType == queenPromotion) {
Promote(move.moveTo, Queen, attackerColor, false);
} else if (moveType == knightPromoCapture) {
Promote(move.moveTo, Knight, attackerColor, true);
} else if (moveType == bishopPromoCapture) {
Promote(move.moveTo, Bishop, attackerColor, true);
} else if (moveType == rookPromoCapture) {
Promote(move.moveTo, Rook, attackerColor, true);
} else if (moveType == queenPromoCapture) {
Promote(move.moveTo, Queen, attackerColor, true);
}
// Setting attacker on the target square if its not a promotion
if (moveType < knightPromotion) {
SetPiece(attackerType, move.moveTo, attackerColor);
}
// Removing the right to castle on king movement
if (attackerType == King) {
castlingRights[attackerColor * 2] = false;
castlingRights[attackerColor * 2 + 1] = false;
}
// Removing the right to castle on rook movement
if (attackerType == Rook) {
if ((Bitboard::GetSquare(move.moveFrom) & files[A] & (ranks[r_1] | ranks[r_8])).GetBoard()) {
castlingRights[attackerColor * 2 + 1] = false;
} else if ((Bitboard::GetSquare(move.moveFrom) & files[H] & (ranks[r_1] | ranks[r_8])).GetBoard()) {
castlingRights[attackerColor * 2] = false;
}
}
GenAttackMaps(*this);
halfMoves++;
if (halfMoves & 2 == 0) fullMoves++;
sideToMove = !attackerColor;
lastMove = LastMove(move, targetType, !attackerColor, oldEPTarget, oldCastlingRights, attackerType);
}
void Board::UnmakeMove() {
enPassantTarget = lastMove.enPassantTarget;
uint16_t moveType = lastMove.moveFlags;
int direction = lastMove.capturedColor ? south : north;
// Removing attacker piece from new square
RemovePiece(lastMove.attackerPiece, lastMove.moveTo, !lastMove.capturedColor);
// Setting back the attacker
SetPiece(lastMove.attackerPiece, lastMove.moveFrom, !lastMove.capturedColor);
// Setting back the target
if (moveType == quiet || moveType == doublePawnPush) {
RemovePiece(lastMove.attackerPiece, lastMove.moveTo, !lastMove.capturedColor);
} else if (moveType == capture) {
SetPiece(lastMove.capturedPiece, lastMove.moveTo, lastMove.capturedColor);
} else if (moveType == epCapture) {
SetPiece(lastMove.capturedPiece, lastMove.moveTo + direction, lastMove.capturedColor);
} else if (moveType == queenCastle) {
int rookSquare = !lastMove.capturedColor ? a8 : a1;
// Removing rook from new position
RemovePiece(Rook, rookSquare + 3, !lastMove.capturedColor);
// Setting rook back on old position
SetPiece(Rook, rookSquare, !lastMove.capturedColor);
} else if (moveType == kingCastle) {
int rookSquare = !lastMove.capturedColor ? h8 : h1;
// Removing rook from new position
RemovePiece(Rook, rookSquare - 2, !lastMove.capturedColor);
// Setting rook back to old position
SetPiece(Rook, rookSquare, !lastMove.capturedColor);
} else if (moveType >= knightPromotion && moveType <= queenPromotion) {
for (int piece = Pawn; piece <= King; piece++) {
RemovePiece(piece, lastMove.moveTo, !lastMove.capturedColor);
}
} else if (moveType >= knightPromoCapture) {
for (int piece = Pawn; piece <= King; piece++) {
RemovePiece(piece, lastMove.moveTo, !lastMove.capturedColor);
}
SetPiece(lastMove.capturedPiece, lastMove.moveTo, lastMove.capturedColor);
}
GenAttackMaps(*this);
castlingRights = lastMove.castlingRights;
if (halfMoves & 2 == 0) fullMoves--;
halfMoves--;
sideToMove = !lastMove.capturedColor;
}