Threefold #22

Merged
rektdie merged 5 commits from threefold into main 2025-03-18 14:25:52 +01:00
3 changed files with 23 additions and 0 deletions
Showing only changes of commit d2b973b869 - Show all commits

No files matched your search

+3
View File
@@ -343,6 +343,9 @@ void Board::MakeMove(Move move) {
enPassantTarget = newEpTarget; enPassantTarget = newEpTarget;
GenAttackMaps(*this); GenAttackMaps(*this);
positionHistory[positionIndex] = hashKey;
positionIndex++;
} }
bool Board::InPossibleZug(bool side) { bool Board::InPossibleZug(bool side) {
+3
View File
@@ -7,6 +7,9 @@
constexpr int nullPieceType = 100; constexpr int nullPieceType = 100;
constexpr int noEPTarget = -1; constexpr int noEPTarget = -1;
inline int positionIndex = 0;
inline U64 positionHistory[1000];
class Board { class Board {
public: public:
Board() { Board() {
+17
View File
@@ -83,6 +83,18 @@ void ListScores(Board &board, int ply) {
} }
} }
static bool IsThreefold(Board &board) {
int count = 0;
for (int i = positionIndex - 1; i >= 0; i--) {
if (positionHistory[i] == board.hashKey) count++;
if (count >= 3) return true;
}
return false;
}
static SearchResults Quiescence(Board board, int alpha, int beta, int ply) { static SearchResults Quiescence(Board board, int alpha, int beta, int ply) {
if (!benchStarted) { if (!benchStarted) {
if (sw.GetElapsedMS() >= timeToSearch) { if (sw.GetElapsedMS() >= timeToSearch) {
@@ -112,6 +124,7 @@ static SearchResults Quiescence(Board board, int alpha, int beta, int ply) {
Board copy = board; Board copy = board;
copy.MakeMove(board.moveList[i]); copy.MakeMove(board.moveList[i]);
int score = -Quiescence(copy, -beta, -alpha, ply + 1).score; int score = -Quiescence(copy, -beta, -alpha, ply + 1).score;
positionIndex--;
if (score >= beta) { if (score >= beta) {
return score; return score;
@@ -139,6 +152,8 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) {
} }
} }
if (!ply && IsThreefold(board)) return 0;
pvLine.SetLength(ply); pvLine.SetLength(ply);
// if NOT PV node then we try to hit the TTable // if NOT PV node then we try to hit the TTable
@@ -217,6 +232,8 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) {
} }
} }
positionIndex--;
// Fail high (beta cutoff) // Fail high (beta cutoff)
if (score >= beta) { if (score >= beta) {
if (!currMove.IsCapture()) { if (!currMove.IsCapture()) {