Skip to content

Commit 528ba55

Browse files
committed
fixed tons of bugs
1 parent 3deff9f commit 528ba55

3 files changed

Lines changed: 13 additions & 10 deletions

File tree

eval.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#pragma once
2-
#include <cstdint>
3-
#include <cstdlib>
42
#include <fwd_decl.h>
53
using Value = int;
64
namespace engine {

search.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <atomic>
77
#include <moves_io.h>
88
#include <position.h>
9+
#include <printers.h>
910
using namespace chess;
1011
namespace engine {
1112
TranspositionTable search::tt(16);
@@ -26,6 +27,9 @@ void update_pv(Move *pv, Move move, const Move *childPv) {
2627
}
2728
Value qsearch(Board &board, Value alpha, Value beta, Session &session,
2829
int ply = 0) {
30+
if (session.tm.elapsed() >= session.tm.optimum() ||
31+
stopSearch.load(std::memory_order_relaxed))
32+
return VALUE_NONE;
2933
session.nodes++;
3034
session.seldepth = std::max(session.seldepth, ply);
3135
int standPat = eval::eval(board);
@@ -38,8 +42,10 @@ Value qsearch(Board &board, Value alpha, Value beta, Session &session,
3842
board.legals<MoveGenType::CAPTURE>(moves);
3943
for (Move move : moves) {
4044
board.doMove(move);
41-
Value score = -qsearch(board, -beta, -alpha, session, ply + 1);
45+
Value score = qsearch(board, -beta, -alpha, session, ply + 1);
4246
board.undoMove();
47+
if (score==VALUE_NONE) return VALUE_NONE;
48+
score=-score;
4349
if (score >= beta)
4450
return score;
4551
if (score > maxScore)
@@ -95,7 +101,7 @@ Value doSearch(Board &board, int depth, Value alpha, Value beta,
95101
preferred = Move(entry->getMove());
96102
}
97103
if (depth == 0) {
98-
return qsearch(board, alpha, beta, session, ply + 1);
104+
return qsearch(board, alpha, beta, session, ply);
99105
}
100106
Value maxScore = -VALUE_INFINITE;
101107
Movelist moves;
@@ -109,11 +115,10 @@ Value doSearch(Board &board, int depth, Value alpha, Value beta,
109115
int R=2+depth/6;
110116
board.doNullMove();
111117
Value score=doSearch(board, depth-1-R, -beta, -beta+1, session, ply+1);
112-
118+
board.undoMove();
113119
if (score == VALUE_NONE)
114120
return VALUE_NONE;
115121
score=-score;
116-
board.undoMove();
117122
if (score>=beta) return beta;
118123
}
119124
for (Move move : moves) {
@@ -190,7 +195,7 @@ void search::search(const chess::Board &board,
190195
Value score_ =
191196
doSearch(board_, i, -VALUE_INFINITE, VALUE_INFINITE, session);
192197
if (session.tm.elapsed() >= session.tm.optimum() ||
193-
stopSearch.load(std::memory_order_relaxed) || score_ == VALUE_NONE)
198+
stopSearch.load(std::memory_order_relaxed) || abs(score_) == VALUE_NONE)
194199
break;
195200
InfoFull info{};
196201
info.depth = i;

tt.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ struct TTEntry {
3737
<< GEN_SHIFT;
3838

3939
// getters
40-
inline uint16_t getScore() const noexcept {
41-
return static_cast<uint16_t>((pack & SCORE_MASK) >> SCORE_SHIFT);
40+
inline int16_t getScore() const noexcept {
41+
return static_cast<int16_t>((pack & SCORE_MASK) >> SCORE_SHIFT);
4242
}
4343

4444
inline uint8_t getDepth() const noexcept {
@@ -176,4 +176,4 @@ class TranspositionTable {
176176
return (used * 1000) / buckets;
177177
}
178178
};
179-
} // namespace engine
179+
} // namespace engine

0 commit comments

Comments
 (0)