implemented NMP
This commit is contained in:
1 parent
ada7371c01
commit
27f914eeaf
3 files changed
+61
-15
No files matched your search
+37
-12
@@ -3,6 +3,8 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "tt.h"
|
#include "tt.h"
|
||||||
|
|
||||||
|
static inline int prevEPTarget = noEPTarget;
|
||||||
|
|
||||||
void Board::Init() {
|
void Board::Init() {
|
||||||
SetByFen(StartingFen);
|
SetByFen(StartingFen);
|
||||||
}
|
}
|
||||||
@@ -10,8 +12,6 @@ void Board::Init() {
|
|||||||
void Board::Reset() {
|
void Board::Reset() {
|
||||||
castlingRights = 0;
|
castlingRights = 0;
|
||||||
enPassantTarget = noEPTarget;
|
enPassantTarget = noEPTarget;
|
||||||
halfMoves = 0;
|
|
||||||
fullMoves = 0;
|
|
||||||
sideToMove = White;
|
sideToMove = White;
|
||||||
occupied = 0ULL;
|
occupied = 0ULL;
|
||||||
|
|
||||||
@@ -175,12 +175,6 @@ void Board::SetByFen(const char* fen) {
|
|||||||
const int passantRank = *fen - 49;
|
const int passantRank = *fen - 49;
|
||||||
enPassantTarget = passantFile + passantRank*8;
|
enPassantTarget = passantFile + passantRank*8;
|
||||||
}
|
}
|
||||||
else if (section == 3) {
|
|
||||||
halfMoves = (*fen) - 48;
|
|
||||||
}
|
|
||||||
else if (section == 4) {
|
|
||||||
fullMoves = (*fen) - 48;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -340,14 +334,36 @@ void Board::Promote(int square, int pieceType, int color, bool isCapture) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Board::MakeMove(Move move) {
|
void Board::MakeMove(Move move) {
|
||||||
|
|
||||||
|
// Null Move
|
||||||
|
if (!move) {
|
||||||
|
int newEpTarget = prevEPTarget;
|
||||||
|
prevEPTarget = enPassantTarget;
|
||||||
|
|
||||||
|
sideToMove = !sideToMove;
|
||||||
|
hashKey ^= zSide;
|
||||||
|
|
||||||
|
if (enPassantTarget != noEPTarget) {
|
||||||
|
hashKey ^= zEnPassant[enPassantTarget % 8];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newEpTarget != noEPTarget) {
|
||||||
|
hashKey ^= zEnPassant[newEpTarget % 8];
|
||||||
|
}
|
||||||
|
|
||||||
|
enPassantTarget = newEpTarget;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int newEpTarget = noEPTarget;
|
||||||
|
|
||||||
int attackerPiece = GetPieceType(move.MoveFrom());
|
int attackerPiece = GetPieceType(move.MoveFrom());
|
||||||
int attackerColor = GetPieceColor(move.MoveFrom());
|
int attackerColor = GetPieceColor(move.MoveFrom());
|
||||||
|
|
||||||
int targetPiece = GetPieceType(move.MoveTo());
|
int targetPiece = GetPieceType(move.MoveTo());
|
||||||
int direction = attackerColor ? south : north;
|
int direction = attackerColor ? south : north;
|
||||||
|
|
||||||
int newEpTarget = noEPTarget;
|
|
||||||
|
|
||||||
// Removing attacker piece from old position
|
// Removing attacker piece from old position
|
||||||
RemovePiece(attackerPiece, move.MoveFrom(), attackerColor);
|
RemovePiece(attackerPiece, move.MoveFrom(), attackerColor);
|
||||||
|
|
||||||
@@ -428,8 +444,6 @@ void Board::MakeMove(Move move) {
|
|||||||
// Removing the right to castle on king and rook movement
|
// Removing the right to castle on king and rook movement
|
||||||
UpdateCastlingRights(*this, move.MoveFrom(), attackerPiece, attackerColor);
|
UpdateCastlingRights(*this, move.MoveFrom(), attackerPiece, attackerColor);
|
||||||
|
|
||||||
halfMoves++;
|
|
||||||
if (halfMoves % 2 == 0) fullMoves++;
|
|
||||||
sideToMove = !attackerColor;
|
sideToMove = !attackerColor;
|
||||||
hashKey ^= zSide;
|
hashKey ^= zSide;
|
||||||
|
|
||||||
@@ -445,3 +459,14 @@ void Board::MakeMove(Move move) {
|
|||||||
|
|
||||||
GenAttackMaps(*this);
|
GenAttackMaps(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Board::InPossibleZug(bool side) {
|
||||||
|
Bitboard toCheck;
|
||||||
|
|
||||||
|
// For all pieces other than pawns and king
|
||||||
|
for (int piece = Knight; piece <= Queen; piece++) {
|
||||||
|
toCheck |= (pieces[piece] & colors[side]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return !toCheck;
|
||||||
|
}
|
||||||
+2
-2
@@ -23,8 +23,6 @@ public:
|
|||||||
int currentMoveIndex = 0;
|
int currentMoveIndex = 0;
|
||||||
|
|
||||||
bool sideToMove = White;
|
bool sideToMove = White;
|
||||||
int halfMoves = 0;
|
|
||||||
int fullMoves = 0;
|
|
||||||
|
|
||||||
uint8_t castlingRights = 0;
|
uint8_t castlingRights = 0;
|
||||||
int enPassantTarget = noEPTarget;
|
int enPassantTarget = noEPTarget;
|
||||||
@@ -51,4 +49,6 @@ public:
|
|||||||
|
|
||||||
void Promote(int square, int pieceType, int color, bool isCapture);
|
void Promote(int square, int pieceType, int color, bool isCapture);
|
||||||
void MakeMove(Move move);
|
void MakeMove(Move move);
|
||||||
|
|
||||||
|
bool InPossibleZug(bool side);
|
||||||
};
|
};
|
||||||
+22
-1
@@ -12,6 +12,7 @@ static inline int ply = 0;
|
|||||||
static inline auto timeStart = std::chrono::high_resolution_clock::now();
|
static inline auto timeStart = std::chrono::high_resolution_clock::now();
|
||||||
static inline int timeToSearch = 0;
|
static inline int timeToSearch = 0;
|
||||||
static inline bool searchStopped = false;
|
static inline bool searchStopped = false;
|
||||||
|
static inline bool doingNullMove = false;
|
||||||
|
|
||||||
// [id][ply]
|
// [id][ply]
|
||||||
static inline int killerMoves[2][64];
|
static inline int killerMoves[2][64];
|
||||||
@@ -157,7 +158,27 @@ SearchResults PVS(Board board, int depth, int alpha, int beta) {
|
|||||||
int score = -inf;
|
int score = -inf;
|
||||||
int nodeType = AllNode;
|
int nodeType = AllNode;
|
||||||
|
|
||||||
if (board.InCheck(board.sideToMove)) depth++;
|
if (board.InCheck(board.sideToMove)) {
|
||||||
|
depth++;
|
||||||
|
} else {
|
||||||
|
//Null Move Pruning
|
||||||
|
if (!doingNullMove) {
|
||||||
|
if (ply && depth >= 3 && !board.InPossibleZug(board.sideToMove)) {
|
||||||
|
board.MakeMove(Move());
|
||||||
|
|
||||||
|
doingNullMove = true;
|
||||||
|
ply++;
|
||||||
|
score = -PVS(board, depth - 3, -beta, -beta + 1).score;
|
||||||
|
ply--;
|
||||||
|
doingNullMove = false;
|
||||||
|
|
||||||
|
board.MakeMove(Move());
|
||||||
|
|
||||||
|
if (searchStopped) return 0;
|
||||||
|
if (score >= beta) return beta;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
nodes++;
|
nodes++;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user