Skip to content

Commit b242210

Browse files
committed
resolved some issues, no functional changes
1 parent aa08fd3 commit b242210

14 files changed

Lines changed: 88 additions & 106 deletions

File tree

.github/workflows/clang-format.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
token: ${{ secrets.GITHUB_TOKEN }}
2020

2121
- name: Install clang-format
22-
run: sudo apt-get update && sudo apt-get install -y clang-format
22+
run: pip install clang-format==18.1.0
2323

2424
- name: Run clang-format
2525
run: |

.github/workflows/games.yml

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ on:
2828
required: false
2929
default: "engine"
3030

31-
permissions:
32-
contents: write
33-
3431
jobs:
3532

3633
build-new:
@@ -40,6 +37,7 @@ jobs:
4037
- uses: actions/checkout@v4
4138
with:
4239
path: new
40+
persist-credentials: false
4341

4442
- name: Install deps
4543
run: sudo apt update && sudo apt install -y build-essential cmake
@@ -67,6 +65,7 @@ jobs:
6765
with:
6866
ref: ${{ github.event.inputs.base_ref }}
6967
path: base
68+
persist-credentials: false
7069

7170
- name: Install deps
7271
run: sudo apt update && sudo apt install -y build-essential cmake
@@ -95,6 +94,8 @@ jobs:
9594
uses: actions/download-artifact@v4
9695

9796
- name: Install tools
97+
env:
98+
OUTPUT_EXEC: ${{ github.event.inputs.output_exec }}
9899
run: |
99100
sudo apt update
100101
sudo apt install -y wget unzip
@@ -111,24 +112,26 @@ jobs:
111112
chmod +x ordo-linux64
112113
113114
chmod +x new-engine/engine
114-
chmod +x base-engine/${{ github.event.inputs.output_exec }}
115+
chmod +x base-engine/$OUTPUT_EXEC
115116
116117
- name: Run fastchess
118+
env:
119+
ELO0: ${{ github.event.inputs.elo0 }}
120+
ELO1: ${{ github.event.inputs.elo1 }}
121+
TC: ${{ github.event.inputs.tc }}
122+
OUTPUT_EXEC: ${{ github.event.inputs.output_exec }}
123+
ROUNDS: ${{ github.event.inputs.rounds }}
117124
run: |
118125
./fastchess -recover \
119-
-engine cmd=new-engine/engine name=new \
120-
-engine cmd=base-engine/${{ github.event.inputs.output_exec }} name=base \
121-
-openings file=UHO_Lichess_4852_v1.epd format=epd order=random \
122-
-each tc=${{ github.event.inputs.tc }} \
123-
-rounds ${{ github.event.inputs.rounds }} \
124-
-concurrency $(nproc) \
125-
-pgnout notation=san nodes=true file=games.pgn \
126-
-repeat \
127-
-sprt elo0=${{ github.event.inputs.elo0 }} elo1=${{ github.event.inputs.elo1 }} alpha=0.05 beta=0.05 | tee results.txt
128-
126+
-engine cmd=new-engine/engine name=new \
127+
-engine cmd=base-engine/$OUTPUT_EXEC name=base \
128+
-openings file=UHO_Lichess_4852_v1.epd format=epd order=random \
129+
-each tc=$TC \
130+
-rounds $ROUNDS \
131+
-concurrency $(nproc) \
132+
-pgnout notation=san nodes=true file=games.pgn \
133+
-sprt elo0=$ELO0 elo1=$ELO1 alpha=0.05 beta=0.05 | tee results.txt
129134
./ordo-linux64 -o ratings.txt -- games.pgn
130-
sed -n '/Results of new vs base/,/^--------------------------------------------------$/p' results.txt >> ratings.txt
131-
sed -n '/Total Time/,/^--------------------------------------------------$/p' results.txt >> ratings.txt
132135
- name: Upload results
133136
uses: actions/upload-artifact@v4
134137
with:

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,13 @@ target_include_directories(engine PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${chesslib
4444
execute_process(
4545
COMMAND git rev-parse --short HEAD
4646
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
47+
ERROR_QUIET
4748
OUTPUT_VARIABLE GIT_SHA
4849
OUTPUT_STRIP_TRAILING_WHITESPACE
4950
)
50-
51+
if(GIT_SHA STREQUAL "")
52+
set(GIT_SHA "unknown")
53+
endif()
5154
execute_process(
5255
COMMAND git describe --tags --exact-match
5356
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ endif
3333
deps:
3434
test -d deps/chesslib || git clone https://github.com/winapiadmin/chesslib deps/chesslib
3535
test -d deps/tbprobe || git clone https://github.com/winapiadmin/tb_probing_tool deps/tbprobe
36+
all: deps
37+
@$(MAKE) --no-print-directory $(TARGET)
3638
# Tuning is not required on Makefile, use CMake.
37-
CHESSLIB_SRCS := $(filter-out %tests.cpp,$(wildcard deps/chesslib/*.cpp))
3839
SRCS := \
3940
$(filter-out tune_cmd.cpp,$(wildcard *.cpp)) \
40-
$(CHESSLIB_SRCS) \
41+
$(filter-out %tests.cpp,$(wildcard deps/chesslib/*.cpp)) \
4142
deps/tbprobe/syzygy/tbprobe.cpp
4243
OBJS = $(SRCS:.cpp=.o)
4344
SHA := $(shell git rev-parse --short HEAD 2>/dev/null)
@@ -52,7 +53,6 @@ endif
5253

5354
CXXFLAGS += -DBUILD_VERSION=\"$(BUILD_VERSION)\"
5455
.PHONY: all clean deps
55-
all: deps $(TARGET)
5656

5757
$(TARGET): $(OBJS)
5858
$(CXX) $(CXXFLAGS) $(OPTFLAGS) -o $(TARGET) $(OBJS)

eval.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,8 @@ EvalComponents eval_components(const chess::Position &board) {
695695
// Draw detection: score 0 for positions where neither side can force a win
696696
int totalPieces = popcount(board.occ());
697697
int pawnCount = board.count<PAWN>();
698+
if (board.is_insufficient_material())
699+
return { 0, 0, 0 };
698700

699701
// KBKB same-colored bishops (no pawns) - drawn
700702
if (totalPieces == 4 && pawnCount == 0 && board.count<BISHOP>() == 2 && board.count<KNIGHT>() == 0 &&

score.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Score {
3939
int value;
4040
};
4141

42-
Score() = default;
42+
Score() : score(InternalUnits{VALUE_ZERO}){};
4343
Score(Value v);
4444

4545
template <typename T> bool is() const { return std::holds_alternative<T>(score); }
@@ -54,4 +54,4 @@ class Score {
5454

5555
} // namespace engine
5656

57-
#endif // #ifndef SCORE_H_INCLUDED
57+
#endif // #ifndef SCORE_H_INCLUDED

search.cpp

Lines changed: 8 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ Value doSearch(
197197
if (alpha >= beta)
198198
return alpha;
199199

200-
session.pv[ply][0] = Move::none();
201200
if (board.is_draw(3) || board.is_insufficient_material())
202201
return VALUE_DRAW;
203202

@@ -215,20 +214,14 @@ Value doSearch(
215214

216215
if (flag == EXACT && ply > 0) {
217216
session.ttCutoffs++;
218-
session.pv[ply][0] = Move(entry->getMove());
219-
session.pv[ply][1] = Move::none();
220217
return ttScore;
221218
}
222219
if (flag == LOWERBOUND && ttScore >= beta && ply > 0) {
223220
session.ttCutoffs++;
224-
session.pv[ply][0] = Move(entry->getMove());
225-
session.pv[ply][1] = Move::none();
226221
return ttScore;
227222
}
228223
if (flag == UPPERBOUND && ttScore <= alpha && ply > 0) {
229224
session.ttCutoffs++;
230-
session.pv[ply][0] = Move(entry->getMove());
231-
session.pv[ply][1] = Move::none();
232225
return ttScore;
233226
}
234227
}
@@ -326,7 +319,6 @@ Value doSearch(
326319
Movelist moves;
327320
board.legals(moves);
328321
if (!moves.size()) {
329-
session.pv[ply][0] = Move::none();
330322
return board.checkers() ? mated_in(ply) : 0;
331323
}
332324
movepick::orderMoves(board, moves, ttMove, ply, session, prevMove);
@@ -364,6 +356,7 @@ Value doSearch(
364356
}
365357

366358
Value maxScore = -VALUE_INFINITE;
359+
Move bestMove = Move::none();
367360
int movesSearched = 0;
368361

369362
for (size_t i = 0; i < moves.size(); ++i) {
@@ -463,7 +456,7 @@ Value doSearch(
463456

464457
if (score > maxScore) {
465458
maxScore = score;
466-
update_pv(session.pv[ply], move, session.pv[ply + 1]);
459+
bestMove = move;
467460
}
468461

469462
if (score > alpha) {
@@ -501,7 +494,7 @@ Value doSearch(
501494
if (maxScore != -VALUE_INFINITE) {
502495
TTFlag flag = maxScore >= beta ? LOWERBOUND : maxScore <= alphaOrig ? UPPERBOUND : EXACT;
503496

504-
tt.store(hash, session.pv[ply][0], value_to_tt(maxScore, ply), depth, flag);
497+
tt.store(hash, bestMove, value_to_tt(maxScore, ply), depth, flag);
505498
}
506499
return maxScore;
507500
}
@@ -544,7 +537,7 @@ void search(const chess::Position &board, const timeman::LimitsType timecontrol)
544537
session.tm.init(session.tc, board.side_to_move(), board.ply(), originalTimeAdjust);
545538
session.lastLogTime = session.tm.elapsed();
546539
session.ogcolor = board.side_to_move();
547-
chess::Move lastPV[MAX_PLY]{};
540+
chess::Move lastBestMove{};
548541
Value prevScore = VALUE_NONE;
549542

550543
if (!session.tc.searchmoves.empty()) {
@@ -584,7 +577,7 @@ void search(const chess::Position &board, const timeman::LimitsType timecontrol)
584577
}
585578
board_.undoMove();
586579
}
587-
lastPV[0] = best;
580+
lastBestMove = best;
588581
}
589582

590583
for (int i = 1; i <= timecontrol.depth; i++) {
@@ -647,64 +640,20 @@ void search(const chess::Position &board, const timeman::LimitsType timecontrol)
647640
size_t sp = pvStr.find(' ');
648641
std::string firstMove = (sp == std::string::npos) ? pvStr : pvStr.substr(0, sp);
649642
if (!firstMove.empty())
650-
lastPV[0] = chess::Move(chess::uci::uciToMove(board, firstMove).raw());
643+
lastBestMove = chess::Move(chess::uci::uciToMove(board, firstMove).raw());
651644
std::stringstream ss;
652645
ss << "qnodes " << session.qnodes << " lmrResearches " << session.lmrResearches << " ttHits " << session.ttHits
653646
<< " ttCutoffs " << session.ttCutoffs << " nullCutoffs " << session.nullCutoffs;
654647
info.extrainfo = ss.str();
655648
report(info);
656649
}
657-
if (lastPV[0].is_ok())
658-
report(chess::uci::moveToUci(lastPV[0], board.chess960()));
650+
if (lastBestMove.is_ok())
651+
report(chess::uci::moveToUci(lastBestMove, board.chess960()));
659652
else {
660653
std::cerr << "info string Warning: Did not search\n";
661654
TTEntry *entry = tt.lookup(board.hash());
662655
if (entry && entry->getMove() != Move::none().raw())
663656
report(chess::uci::moveToUci(Move(entry->getMove()), board.chess960()));
664-
else {
665-
Movelist moves;
666-
board.legals(moves);
667-
668-
if (moves.size()) {
669-
Position board_ = board;
670-
Move best = Move::none();
671-
Value bestScore = -VALUE_INFINITE;
672-
double unusedTimeAdjust = -1;
673-
Session tmpSession;
674-
tmpSession.tc = session.tc;
675-
tmpSession.tm.init(session.tc, board.side_to_move(), board.ply(), unusedTimeAdjust);
676-
for (Move move : moves) {
677-
if (!session.tc.searchmoves.empty() &&
678-
std::find(session.tc.searchmoves.begin(),
679-
session.tc.searchmoves.end(),
680-
chess::uci::moveToUci(move, board.chess960())) == session.tc.searchmoves.end())
681-
continue;
682-
board_.doMove(move);
683-
Value score = -qsearch(board_, -VALUE_INFINITE, VALUE_INFINITE, tmpSession, 0);
684-
if (score > bestScore) {
685-
bestScore = score;
686-
best = move;
687-
}
688-
board_.undoMove();
689-
}
690-
691-
if (best.is_ok()) {
692-
InfoFull info{};
693-
info.depth = 1;
694-
info.nodes = 1;
695-
info.score = 0;
696-
info.multiPV = 1;
697-
info.pv = std::string(chess::uci::moveToUci(best, board.chess960()));
698-
report(info);
699-
700-
report(chess::uci::moveToUci(best, board.chess960()));
701-
} else {
702-
report("0000");
703-
}
704-
} else {
705-
report("0000");
706-
}
707-
}
708657
}
709658
}
710659
} // namespace engine::search

search.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ struct Session {
1010
int seldepth = 0;
1111
uint64_t nodes = 0, qnodes = 0, lmrResearches = 0;
1212
uint64_t tbHits = 0, ttHits = 0, ttCutoffs = 0, nullCutoffs = 0;
13-
chess::Move pv[MAX_PLY][MAX_PLY]{};
1413
Value historyHeuristic[chess::SQUARE_NB][chess::SQUARE_NB]{};
1514
chess::Move killerMoves[MAX_PLY][2]{};
1615
chess::Move counterMoves[4096]{};

timeman.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void TimeManagement::init(LimitsType &limits, chess::Color us, int ply, double &
2323
// If we have no time, we don't need to fully initialize TM.
2424
// startTime is used by movetime and useNodesTime is used in elapsed calls.
2525
startTime = limits.startTime;
26-
if (limits.movetime != 0 && limits.time[us] == 0) {
26+
if (limits.movetime != 0) {
2727
optimumTime = maximumTime = TimePoint(limits.movetime);
2828
return;
2929
}
@@ -77,8 +77,9 @@ void TimeManagement::init(LimitsType &limits, chess::Color us, int ply, double &
7777
}
7878

7979
// Limit the maximum possible time for this move
80-
optimumTime = TimePoint(optScale * timeLeft);
81-
maximumTime = TimePoint(std::min(0.825179 * time - moveOverhead, maxScale * optimumTime)) - 10;
80+
optimumTime = std::max(TimePoint(1), TimePoint(optScale * timeLeft));
81+
const TimePoint maxCandidate = TimePoint(std::min(0.825179 * time - moveOverhead, maxScale * optimumTime)) - 10;
82+
maximumTime = std::max(optimumTime, maxCandidate);
8283
}
8384

8485
} // namespace engine::timeman

timeman.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#pragma once
2-
#include <chrono>
32
#include <types.h>
3+
#include <chrono>
44
#include <vector>
5+
#include <string>
56
namespace engine::timeman {
67
using TimePoint = std::chrono::milliseconds::rep;
78
constexpr TimePoint INFINITE_TIME = 864000000;
@@ -14,7 +15,7 @@ struct LimitsType {
1415

1516
// Init explicitly due to broken value-initialization of non POD in MSVC
1617
LimitsType() {
17-
time[chess::WHITE] = time[chess::BLACK] = inc[chess::WHITE] = inc[chess::BLACK] = movetime = TimePoint(0);
18+
time[chess::WHITE] = time[chess::BLACK] = inc[chess::WHITE] = inc[chess::BLACK] = movetime = startTime = TimePoint(0);
1819
movestogo = mate = perft = infinite = 0;
1920
depth = 64;
2021
nodes = 0;
@@ -45,4 +46,4 @@ class TimeManagement {
4546
TimePoint optimumTime;
4647
TimePoint maximumTime;
4748
};
48-
} // namespace engine::timeman
49+
} // namespace engine::timeman

0 commit comments

Comments
 (0)