Pseudo legal #28

Merged
rektdie merged 14 commits from pseudoLegal into main 2025-03-25 14:16:56 +01:00
5 changed files with 24 additions and 27 deletions
Showing only changes of commit d4c7263b93 - Show all commits

No files matched your search

+9 -12
View File
@@ -159,20 +159,14 @@ int Board::GetPieceColor(int square) {
}
bool Board::InCheck() {
int kingSquare = (pieces[King] & colors[sideToMove]).getLS1BIndex();
Bitboard myKingSquare = colors[sideToMove] & pieces[King];
for (int type = Pawn; type <= Queen; type++) {
Bitboard moves = MOVEGEN::getPieceAttacks(kingSquare, type, sideToMove, occupied);
if (moves & colors[!sideToMove] & pieces[type]) return true;
}
return false;
return GetThreatMaps(!sideToMove) & myKingSquare;
}
bool Board::IsLegal(Move move) {
Board copy = *this;
copy.MakeMove(move);
copy.MakeMove(move, true);
copy.sideToMove = sideToMove;
positionIndex--;
@@ -231,9 +225,10 @@ void Board::Promote(int square, int pieceType, int color, bool isCapture) {
SetPiece(pieceType, square, color);
}
void Board::MakeMove(Move move) {
SEARCH::nodes++;
void Board::MakeMove(Move move, bool legalityCheck) {
if (!legalityCheck) {
SEARCH::nodes++;
}
// Null Move
if (!move) {
int newEpTarget = noEPTarget;
@@ -357,6 +352,8 @@ void Board::MakeMove(Move move) {
positionIndex++;
positionHistory[positionIndex] = hashKey;
MOVEGEN::GenThreatMaps(*this);
}
bool Board::InPossibleZug() {
+1 -1
View File
@@ -53,7 +53,7 @@ public:
void RemovePiece(int piece, int square, bool color);
void Promote(int square, int pieceType, int color, bool isCapture);
void MakeMove(Move move);
void MakeMove(Move move, bool legalityCheck);
bool InPossibleZug();
};
+2 -2
View File
@@ -12,7 +12,7 @@ static U64 HelperPerft(Board board, int depth) {
for (int i = 0; i < board.currentMoveIndex; i++) {
if (!board.IsLegal(board.moveList[i])) continue;
Board copy = board;
copy.MakeMove(board.moveList[i]);
copy.MakeMove(board.moveList[i], false);
nodes += HelperPerft(copy, depth - 1);
positionIndex--;
}
@@ -28,7 +28,7 @@ void Perft(Board &board, int depth) {
for (int i = 0; i < board.currentMoveIndex; i++) {
if (!board.IsLegal(board.moveList[i])) continue;
Board copy = board;
copy.MakeMove(board.moveList[i]);
copy.MakeMove(board.moveList[i], false);
U64 nodeCount = HelperPerft(copy, depth - 1);
positionIndex--;
totalNodes += nodeCount;
+11 -11
View File
@@ -140,7 +140,7 @@ static SearchResults Quiescence(Board board, int alpha, int beta, int ply) {
if (!board.IsLegal(board.moveList[i])) continue;
if (board.moveList[i].IsCapture()) {
Board copy = board;
copy.MakeMove(board.moveList[i]);
copy.MakeMove(board.moveList[i], false);
int score = -Quiescence(copy, -beta, -alpha, ply + 1).score;
positionIndex--;
@@ -201,7 +201,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) {
if (!doingNullMove && staticEval >= beta) {
if (depth >= 3 && !board.InPossibleZug()) {
Board copy = board;
copy.MakeMove(Move());
copy.MakeMove(Move(), false);
doingNullMove = true;
int score = -PVS<false>(copy, depth - 3, -beta, -beta + 1, ply + 1).score;
@@ -216,14 +216,6 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) {
MOVEGEN::GenerateMoves<All>(board);
if (board.currentMoveIndex == 0) {
if (board.InCheck()) { // checkmate
return -99000 + ply;
} else { // stalemate
return 0;
}
}
SortMoves(board, ply);
int score = -inf;
@@ -239,7 +231,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) {
if (!board.IsLegal(currMove)) continue;
Board copy = board;
copy.MakeMove(currMove);
copy.MakeMove(currMove, false);
int reductions = GetReductions(board, currMove, depth, moveSeen, ply);
@@ -291,6 +283,14 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) {
}
}
if (moveSeen == 0) {
if (board.InCheck()) { // checkmate
return -99000 + ply;
} else { // stalemate
return 0;
}
}
TT.WriteEntry(board.hashKey, depth, results.score, nodeType, results.bestMove);
if (searchStopped) return 0;
return results;
+1 -1
View File
@@ -32,7 +32,7 @@ static void ParsePosition(Board &board, std::string_view command) {
std::vector<std::string> moves = UTILS::split(command.substr(movesIndex + 6, command.length() - (movesIndex + 5)), ' ');
for (std::string_view move : moves) {
board.MakeMove(UTILS::parseMove(board, move));
board.MakeMove(UTILS::parseMove(board, move), false);
}
}