was making every move twice | bench 888803
This commit is contained in:
1 parent
030c421364
commit
12c600e1c4
5 files changed
+24
-28
No files matched your search
+11
-15
@@ -164,15 +164,6 @@ bool Board::InCheck() {
|
||||
return GetThreatMaps(!sideToMove) & myKingSquare;
|
||||
}
|
||||
|
||||
bool Board::IsLegal(Move move) {
|
||||
Board copy = *this;
|
||||
copy.MakeMove(move, true);
|
||||
copy.sideToMove = sideToMove;
|
||||
positionIndex--;
|
||||
|
||||
return !copy.InCheck();
|
||||
}
|
||||
|
||||
void Board::SetPiece(int piece, int square, bool color) {
|
||||
pieces[piece].SetBit(square);
|
||||
colors[color].SetBit(square);
|
||||
@@ -225,10 +216,7 @@ void Board::Promote(int square, int pieceType, int color, bool isCapture) {
|
||||
SetPiece(pieceType, square, color);
|
||||
}
|
||||
|
||||
void Board::MakeMove(Move move, bool legalityCheck) {
|
||||
if (!legalityCheck) {
|
||||
SEARCH::nodes++;
|
||||
}
|
||||
bool Board::MakeMove(Move move) {
|
||||
// Null Move
|
||||
if (!move) {
|
||||
int newEpTarget = noEPTarget;
|
||||
@@ -246,7 +234,7 @@ void Board::MakeMove(Move move, bool legalityCheck) {
|
||||
|
||||
enPassantTarget = newEpTarget;
|
||||
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
int newEpTarget = noEPTarget;
|
||||
@@ -350,10 +338,18 @@ void Board::MakeMove(Move move, bool legalityCheck) {
|
||||
|
||||
enPassantTarget = newEpTarget;
|
||||
|
||||
|
||||
MOVEGEN::GenThreatMaps(*this);
|
||||
|
||||
sideToMove = !sideToMove;
|
||||
if (InCheck()) return false;
|
||||
sideToMove = !sideToMove;
|
||||
|
||||
positionIndex++;
|
||||
positionHistory[positionIndex] = hashKey;
|
||||
|
||||
MOVEGEN::GenThreatMaps(*this);
|
||||
SEARCH::nodes++;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Board::InPossibleZug() {
|
||||
|
||||
+1
-2
@@ -47,13 +47,12 @@ public:
|
||||
int GetPieceColor(int square);
|
||||
|
||||
bool InCheck();
|
||||
bool IsLegal(Move move);
|
||||
|
||||
void SetPiece(int piece, int square, bool color);
|
||||
void RemovePiece(int piece, int square, bool color);
|
||||
|
||||
void Promote(int square, int pieceType, int color, bool isCapture);
|
||||
void MakeMove(Move move, bool legalityCheck);
|
||||
bool MakeMove(Move move);
|
||||
|
||||
bool InPossibleZug();
|
||||
};
|
||||
+4
-4
@@ -10,9 +10,9 @@ static U64 HelperPerft(Board board, int depth) {
|
||||
U64 nodes = 0;
|
||||
|
||||
for (int i = 0; i < board.currentMoveIndex; i++) {
|
||||
if (!board.IsLegal(board.moveList[i])) continue;
|
||||
Board copy = board;
|
||||
copy.MakeMove(board.moveList[i], false);
|
||||
bool isLegal = copy.MakeMove(board.moveList[i]);
|
||||
if (!isLegal) continue;
|
||||
nodes += HelperPerft(copy, depth - 1);
|
||||
positionIndex--;
|
||||
}
|
||||
@@ -26,9 +26,9 @@ void Perft(Board &board, int depth) {
|
||||
|
||||
Stopwatch sw;
|
||||
for (int i = 0; i < board.currentMoveIndex; i++) {
|
||||
if (!board.IsLegal(board.moveList[i])) continue;
|
||||
Board copy = board;
|
||||
copy.MakeMove(board.moveList[i], false);
|
||||
bool isLegal = copy.MakeMove(board.moveList[i]);
|
||||
if (!isLegal) continue;
|
||||
U64 nodeCount = HelperPerft(copy, depth - 1);
|
||||
positionIndex--;
|
||||
totalNodes += nodeCount;
|
||||
|
||||
+7
-6
@@ -137,10 +137,10 @@ static SearchResults Quiescence(Board board, int alpha, int beta, int ply) {
|
||||
SearchResults results;
|
||||
|
||||
for (int i = 0; i < board.currentMoveIndex; i++) {
|
||||
if (!board.IsLegal(board.moveList[i])) continue;
|
||||
if (board.moveList[i].IsCapture()) {
|
||||
Board copy = board;
|
||||
copy.MakeMove(board.moveList[i], false);
|
||||
int isLegal = copy.MakeMove(board.moveList[i]);
|
||||
if (!isLegal) continue;
|
||||
int score = -Quiescence(copy, -beta, -alpha, ply + 1).score;
|
||||
positionIndex--;
|
||||
|
||||
@@ -201,7 +201,8 @@ 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(), false);
|
||||
bool isLegal = copy.MakeMove(Move());
|
||||
// Always legal so we dont check it
|
||||
|
||||
doingNullMove = true;
|
||||
int score = -PVS<false>(copy, depth - 3, -beta, -beta + 1, ply + 1).score;
|
||||
@@ -228,10 +229,10 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) {
|
||||
for (int i = 0; i < board.currentMoveIndex; i++) {
|
||||
Move currMove = board.moveList[i];
|
||||
|
||||
if (!board.IsLegal(currMove)) continue;
|
||||
|
||||
Board copy = board;
|
||||
copy.MakeMove(currMove, false);
|
||||
bool isLegal = copy.MakeMove(currMove);
|
||||
|
||||
if (!isLegal) continue;
|
||||
|
||||
int reductions = GetReductions(board, currMove, depth, moveSeen, ply);
|
||||
|
||||
|
||||
+1
-1
@@ -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), false);
|
||||
bool isLegal = board.MakeMove(UTILS::parseMove(board, move));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user