Skip to content

Commit 3faf5fa

Browse files
committed
eol norm and Board -> Position
1 parent bc354c3 commit 3faf5fa

11 files changed

Lines changed: 47 additions & 28 deletions

File tree

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ endif
3030
deps:
3131
test -d deps/chesslib || git clone https://github.com/winapiadmin/chesslib deps/chesslib
3232
test -d deps/tbprobe || git clone https://github.com/winapiadmin/tb_probing_tool deps/tbprobe
33-
SRCS = $(wildcard *.cpp) $(wildcard deps/chesslib/*.cpp) $(wildcard deps/tbprobe/*.cpp)
33+
# Tuning is not required on Makefile, use CMake.
34+
SRCS = $(filter-out tuning_cmd.cpp, $(wildcard *.cpp)) $(wildcard deps/chesslib/*.cpp) $(wildcard deps/tbprobe/*.cpp)
3435
OBJS = $(SRCS:.cpp=.o)
3536

3637
all: deps $(TARGET)

eval.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ TUNE(SetRange(1, 50), rammedPawnPenalty);
225225
TUNE(SetRange(1, 100), rookOnSeventhBonus);
226226
TUNE(SetRange(1, 50), earlyQueenPenalty);
227227

228-
EvalComponents eval_components(const chess::Board &board) {
228+
EvalComponents eval_components(const chess::Position &board) {
229229
constexpr int KnightPhase = 1;
230230
constexpr int BishopPhase = 1;
231231
constexpr int RookPhase = 2;
@@ -260,7 +260,8 @@ EvalComponents eval_components(const chess::Board &board) {
260260
int undeveloped = popcount((board.pieces(KNIGHT, c) | board.pieces(BISHOP, c)) & backRank);
261261
if (undeveloped >= 2) {
262262
mgScore -= s * earlyQueenPenalty;
263-
egScore -= s * earlyQueenPenalty;
263+
//disabled intentionally in endgames
264+
//egScore -= s * earlyQueenPenalty;
264265
}
265266
}
266267
}
@@ -714,7 +715,7 @@ EvalComponents eval_components(const chess::Board &board) {
714715
phase = (phase * 256 + TotalPhase / 2) / TotalPhase;
715716
return { mgScore, egScore, phase };
716717
}
717-
Value eval(const chess::Board &board) {
718+
Value eval(const chess::Position &board) {
718719
const int sign = board.side_to_move() == WHITE ? 1 : -1;
719720
auto [mg, eg, phase] = eval_components(board);
720721
return (((mg * phase) + (eg * (256 - phase))) * sign) / 256 + engine::eval::tempo;

eval.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ struct EvalComponents {
5050
extern Value *mgPst[];
5151
extern Value *egPst[];
5252

53-
Value eval(const chess::Board &board);
54-
EvalComponents eval_components(const chess::Board &board);
53+
Value eval(const chess::Position &board);
54+
EvalComponents eval_components(const chess::Position &board);
5555
Value piece_value(chess::PieceType pt);
5656
} // namespace eval
5757
} // namespace engine

movepick.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ inline Square least_valuable_attacker(const Position &board, Bitboard attackers,
4747

4848
return SQ_NONE;
4949
}
50-
Value see(Board &board, Move move) {
50+
Value see(Position &board, Move move) {
5151
Square from = move.from();
5252
Square to = move.to();
5353

@@ -100,7 +100,7 @@ Value see(Board &board, Move move) {
100100
return gain[0];
101101
}
102102

103-
void orderMoves(Board &board, Movelist &moves, Move ttMove, int ply, const engine::search::Session &session, Move prevMove) {
103+
void orderMoves(Position &board, Movelist &moves, Move ttMove, int ply, const engine::search::Session &session, Move prevMove) {
104104
Value scores[300];
105105
size_t n = moves.size();
106106
for (size_t i = 0; i < n; ++i) {

movepick.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ namespace engine::search {
55
struct Session;
66
} // namespace engine::search
77
namespace engine::movepick {
8-
void orderMoves(chess::Board &, chess::Movelist &, chess::Move, int, const engine::search::Session &, chess::Move);
9-
Value see(chess::Board &, chess::Move);
8+
void orderMoves(chess::Position &, chess::Movelist &, chess::Move, int, const engine::search::Session &, chess::Move);
9+
Value see(chess::Position &, chess::Move);
1010
} // namespace engine::movepick

search.cpp

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Value value_from_tt(Value v, int ply, int r50c) {
6767
return v;
6868
}
6969
} // namespace
70-
Value qsearch(Board &board, Value alpha, Value beta, search::Session &session, int ply) {
70+
Value qsearch(Position &board, Value alpha, Value beta, search::Session &session, int ply) {
7171
session.nodes++;
7272
session.qnodes++;
7373
session.seldepth = std::max(session.seldepth, ply);
@@ -179,7 +179,7 @@ Value qsearch(Board &board, Value alpha, Value beta, search::Session &session, i
179179
return best;
180180
}
181181
Value doSearch(
182-
Board &board, int depth, Value alpha, Value beta, search::Session &session, int ply = 0, Move prevMove = Move::none()) {
182+
Position &board, int depth, Value alpha, Value beta, search::Session &session, int ply = 0, Move prevMove = Move::none()) {
183183
session.nodes++;
184184
session.seldepth = std::max(session.seldepth, ply);
185185
if (ply >= MAX_PLY - 1)
@@ -504,9 +504,9 @@ Value doSearch(
504504
}
505505
return maxScore;
506506
}
507-
std::string extract_pv(const chess::Board &root, int maxPly) {
507+
std::string extract_pv(const chess::Position &root, int maxPly) {
508508
std::string pv;
509-
chess::Board pos = root;
509+
chess::Position pos = root;
510510
std::unordered_set<uint64_t> visited;
511511
visited.insert(pos.hash());
512512
for (int ply = 0; ply < maxPly; ply++) {
@@ -538,7 +538,7 @@ std::string extract_pv(const chess::Board &root, int maxPly) {
538538
return pv;
539539
}
540540

541-
void search(const chess::Board &board, const timeman::LimitsType timecontrol) {
541+
void search(const chess::Position &board, const timeman::LimitsType timecontrol) {
542542
stopSearch = false;
543543
tt.newSearch();
544544
static double originalTimeAdjust = -1;
@@ -564,10 +564,27 @@ void search(const chess::Board &board, const timeman::LimitsType timecontrol) {
564564
}
565565

566566
{
567-
Movelist legal;
568-
board.legals(legal);
569-
if (legal.size())
570-
lastPV[0] = legal[0];
567+
Movelist moves;
568+
board.legals(moves);
569+
Position board_ = board;
570+
Move best = Move::none();
571+
Value bestScore = -VALUE_INFINITE;
572+
Session tmpSession{};
573+
for (Move move : moves) {
574+
if (!session.tc.searchmoves.empty() &&
575+
std::find(session.tc.searchmoves.begin(),
576+
session.tc.searchmoves.end(),
577+
chess::uci::moveToUci(move, board.chess960())) == session.tc.searchmoves.end())
578+
continue;
579+
board_.doMove(move);
580+
Value score = -qsearch(board_, -VALUE_INFINITE, VALUE_INFINITE, tmpSession, 0);
581+
if (score > bestScore) {
582+
bestScore = score;
583+
best = move;
584+
}
585+
board_.undoMove();
586+
}
587+
lastPV[0]=best;
571588
}
572589

573590
for (int i = 1; i <= timecontrol.depth; i++) {
@@ -649,7 +666,7 @@ void search(const chess::Board &board, const timeman::LimitsType timecontrol) {
649666
board.legals(moves);
650667

651668
if (moves.size()) {
652-
Board board_ = board;
669+
Position board_ = board;
653670
Move best = Move::none();
654671
Value bestScore = -VALUE_INFINITE;
655672
Session tmpSession{};

search.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct Session {
1919
chess::Color ogcolor;
2020
};
2121
void stop();
22-
void search(const chess::Board &, const timeman::LimitsType);
22+
void search(const chess::Position &, const timeman::LimitsType);
2323
bool isStopped();
2424
extern engine::TranspositionTable tt;
2525
} // namespace engine::search

tb.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ std::size_t wdl_count() { return unique_table_count(tablebase.wdl); }
3737

3838
std::size_t dtz_count() { return unique_table_count(tablebase.dtz); }
3939

40-
int probe_wdl(chess::Board &board) {
40+
int probe_wdl(chess::Position &board) {
4141
try {
4242
return *tablebase.get_wdl(board, TB_ERROR);
4343
} catch (const std::exception &) {
4444
return TB_ERROR;
4545
}
4646
}
4747

48-
int probe_dtz(chess::Board &board) {
48+
int probe_dtz(chess::Position &board) {
4949
try {
5050
return *tablebase.get_dtz(board, TB_ERROR);
5151
} catch (const std::exception &) {

tb.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ void init(const std::string &path);
1010
constexpr int TB_ERROR = 1000;
1111
std::size_t wdl_count();
1212
std::size_t dtz_count();
13-
int probe_wdl(chess::Board &board);
14-
int probe_dtz(chess::Board &board);
13+
int probe_wdl(chess::Position &board);
14+
int probe_dtz(chess::Position &board);
1515
} // namespace engine::tb

tt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class TranspositionTable {
102102
~TranspositionTable() { delete[] table; }
103103

104104
void resize(int sizeInMB) {
105-
int new_size = sizeInMB * 1048576 / sizeof(TTEntry);
105+
size_t new_size = sizeInMB * 1048576LL / sizeof(TTEntry);
106106
if (new_size % 2 != 0)
107107
new_size--;
108108

0 commit comments

Comments
 (0)