Skip to content

Commit a522468

Browse files
improvements and bugfix (#6)
Passed STC (elo1=2): https://github.com/winapiadmin/cppchess_engine/actions/runs/28851470047 (mostly) pass LTC (elo1=2): https://github.com/winapiadmin/cppchess_engine/actions/runs/28864852436 Passed STC (elo1=5): https://github.com/winapiadmin/cppchess_engine/actions/runs/28876353922/job/85652602141 Passed LTC (elo1=5): https://github.com/winapiadmin/cppchess_engine/actions/runs/28876032178 Improvement since beginning of the PR: -------------------------------------------------- Results of new vs base (10+0.1, NULL, 64MB, UHO_Lichess_4852_v1.epd): Elo: 111.48 +/- 22.41, nElo: 152.89 +/- 28.67 LOS: 100.00 %, DrawRatio: 30.14 %, PairsRatio: 4.05 Games: 564, Wins: 256, Losses: 81, Draws: 227, Points: 369.5 (65.51 %) Ptnml(0-2): [4, 35, 85, 98, 60], WL/DD Ratio: 0.81 LLR: 2.95 (100.3%) (-2.94, 2.94) [0.00, 5.00] --------- Co-authored-by: GitHub Actions <actions@github.com>
1 parent 6adfd1f commit a522468

29 files changed

Lines changed: 3811 additions & 1309 deletions

.clang-format

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
BasedOnStyle: LLVM
2+
IndentWidth: 4
3+
ContinuationIndentWidth: 4
4+
ColumnLimit: 128
5+
AllowAllArgumentsOnNextLine: false
6+
AllowAllConstructorInitializersOnNextLine: false
7+
BinPackParameters: false
8+
BinPackArguments: false
9+
BraceWrapping:
10+
# AfterInitializerList: true
11+
AfterFunction: true
12+
BeforeElse: false
13+
IndentBraces: false
14+
AlignArrayOfStructures: Right
15+
Cpp11BracedListStyle: false
16+
SpacesInContainerLiterals: false

.github/workflows/games.yml

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,27 @@ on:
66
base_ref:
77
description: "Base branch, tag, or commit"
88
required: false
9-
default: "HandcraftedEngine"
9+
default: "test_chesslib"
1010
rounds:
1111
description: "Max rounds for SPRT"
1212
required: false
1313
default: "6000"
1414
tc:
15-
description: "Time control (e.g. 60+0.5 or 10+0.1)"
15+
description: "Time control (e.g. 60+0.6 or 10+0.1)"
1616
required: false
17-
default: "60+0.5"
17+
default: "60+0.6"
18+
elo0:
19+
description: "elo0"
20+
required: false
21+
default: "0.5"
22+
elo1:
23+
description: "elo1"
24+
required: false
25+
default: "2.5"
1826
output_exec:
1927
description: "Executable output file name"
2028
required: false
21-
default: "chess_engine"
29+
default: "engine"
2230

2331
permissions:
2432
contents: write
@@ -31,14 +39,14 @@ jobs:
3139
steps:
3240
- uses: actions/checkout@v4
3341
with:
34-
path: test_chesslib
42+
path: new
3543

3644
- name: Install deps
3745
run: sudo apt update && sudo apt install -y build-essential cmake
3846

3947
- name: Build new engine
4048
run: |
41-
cd test_chesslib
49+
cd new
4250
mkdir build
4351
cd build
4452
cmake .. -DCMAKE_BUILD_TYPE=Release
@@ -48,7 +56,7 @@ jobs:
4856
uses: actions/upload-artifact@v4
4957
with:
5058
name: new-engine
51-
path: test_chesslib/build/engine
59+
path: new/build/engine
5260

5361

5462
build-base:
@@ -58,14 +66,14 @@ jobs:
5866
- uses: actions/checkout@v4
5967
with:
6068
ref: ${{ github.event.inputs.base_ref }}
61-
path: handcrafted
69+
path: base
6270

6371
- name: Install deps
6472
run: sudo apt update && sudo apt install -y build-essential cmake
6573

6674
- name: Build base engine
6775
run: |
68-
cd handcrafted
76+
cd base
6977
mkdir build
7078
cd build
7179
cmake .. -DCMAKE_BUILD_TYPE=Release
@@ -75,7 +83,7 @@ jobs:
7583
uses: actions/upload-artifact@v4
7684
with:
7785
name: base-engine
78-
path: handcrafted/build/${{ github.event.inputs.output_exec }}
86+
path: base/build/${{ github.event.inputs.output_exec }}
7987

8088

8189
test:
@@ -115,7 +123,7 @@ jobs:
115123
-rounds ${{ github.event.inputs.rounds }} \
116124
-concurrency $(nproc) \
117125
-pgnout notation=san nodes=true file=games.pgn \
118-
-sprt elo0=0 elo1=2 alpha=0.05 beta=0.05 | tee results.txt
126+
-sprt elo0=${{ github.event.inputs.elo0 }} elo1=${{ github.event.inputs.elo1 }} alpha=0.05 beta=0.05 | tee results.txt
119127
120128
./ordo-linux64 -o ratings.txt -- games.pgn
121129
sed -n '/Results of new vs base/,/^--------------------------------------------------$/p' results.txt >> ratings.txt
@@ -127,3 +135,4 @@ jobs:
127135
path: |
128136
games.pgn
129137
ratings.txt
138+
results.txt

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
!.gitignore
1111
!CMakeLists.txt
1212
!.github/
13-
!.github/**
13+
!.github/**
14+
!.clang-format

CMakeLists.txt

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,35 @@ FetchContent_Declare(
1111
GIT_REPOSITORY https://github.com/winapiadmin/chesslib.git
1212
GIT_TAG main
1313
)
14-
FetchContent_MakeAvailable(chesslib)
15-
add_executable(engine "main.cpp" "timeman.cpp" "timeman.h" "eval.h" "eval.cpp" "tune.h" "ucioption.h" "tune.cpp" "ucioption.cpp" "tt.h" "tt.cpp" "uci.cpp" "uci.h" "search.h" "search.cpp" "score.h" "score.cpp" "movepick.h" "movepick.cpp")
16-
target_link_libraries(engine PRIVATE chesslib)
14+
FetchContent_Declare(
15+
tbprobe
16+
GIT_REPOSITORY https://github.com/winapiadmin/tb_probing_tool.git
17+
GIT_TAG main
18+
)
19+
set(BUILD_GAVIOTA OFF CACHE BOOL "Enable Gaviota TB probing" FORCE)
20+
option(ENGINE_TUNING "enable Texel tuning (requires csv-parser)" OFF)
21+
FetchContent_MakeAvailable(chesslib tbprobe)
22+
set(SOURCES
23+
"main.cpp"
24+
"timeman.cpp"
25+
"eval.cpp"
26+
"tune.cpp"
27+
"ucioption.cpp"
28+
"tt.cpp"
29+
"uci.cpp"
30+
"search.cpp"
31+
"score.cpp"
32+
"movepick.cpp"
33+
"tb.cpp"
34+
)
35+
36+
if(ENGINE_TUNING)
37+
list(APPEND SOURCES "tune_cmd.cpp")
38+
endif()
39+
40+
add_executable(engine ${SOURCES})
41+
42+
target_link_libraries(engine PRIVATE chesslib syzygy_probe)
1743
target_include_directories(engine PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${chesslib_SOURCE_DIR})
1844
execute_process(
1945
COMMAND git rev-parse --short HEAD
@@ -39,5 +65,14 @@ else()
3965
endif()
4066

4167
message(STATUS "Build Version: ${BUILD_VERSION}")
42-
add_definitions(-DBUILD_VERSION="${BUILD_VERSION}")
43-
68+
target_compile_definitions(engine PRIVATE BUILD_VERSION="${BUILD_VERSION}")
69+
if (ENGINE_TUNING)
70+
FetchContent_Declare(
71+
csv
72+
GIT_REPOSITORY https://github.com/vincentlaucsb/csv-parser.git
73+
GIT_TAG master
74+
)
75+
FetchContent_MakeAvailable(csv)
76+
target_link_libraries(engine PRIVATE csv)
77+
target_compile_definitions(engine PRIVATE USE_CSV_PARSER)
78+
endif()

Makefile

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# :( openbench and fishtest require make
2+
TARGET = engine
3+
4+
CXX ?= g++
5+
CXXFLAGS ?= -std=c++17 -Wall -Wextra
6+
OPTFLAGS ?= -O3
7+
ifeq ($(LTO), yes)
8+
OPTFLAGS += -flto
9+
endif
10+
ifeq ($(debug),no)
11+
CXXFLAGS += -DNDEBUG
12+
endif
13+
ARCH ?= native
14+
15+
ifeq ($(ARCH), native)
16+
CXXFLAGS += -march=native -mtune=native
17+
endif
18+
ifeq ($(ARCH), avx2)
19+
CXXFLAGS += -march=haswell -mavx2 -mbmi -mbmi2 -msse4.1
20+
endif
21+
ifeq ($(ARCH), bmi2)
22+
CXXFLAGS += -mbmi2
23+
endif
24+
ifeq ($(ARCH), sse41)
25+
CXXFLAGS += -msse4.1
26+
endif
27+
ifeq ($(ARCH), x86-64)
28+
CXXFLAGS += -march=x86-64
29+
endif
30+
deps:
31+
test -d deps/chesslib || git clone https://github.com/winapiadmin/chesslib deps/chesslib
32+
test -d deps/tbprobe || git clone https://github.com/winapiadmin/tb_probing_tool deps/tbprobe
33+
# Tuning is not required on Makefile, use CMake.
34+
SRCS = $(filter-out tune_cmd.cpp, $(wildcard *.cpp)) $(wildcard deps/chesslib/*.cpp) $(wildcard deps/tbprobe/*.cpp)
35+
OBJS = $(SRCS:.cpp=.o)
36+
37+
.PHONY: all clean deps
38+
all: deps $(TARGET)
39+
40+
$(TARGET): $(OBJS)
41+
$(CXX) $(CXXFLAGS) $(OPTFLAGS) -o $(TARGET) $(OBJS)
42+
43+
%.o: %.cpp
44+
$(CXX) $(CXXFLAGS) $(OPTFLAGS) -Ideps/chesslib -Ideps/tbprobe/syzygy -c $< -o $@
45+
46+
clean:
47+
rm -f $(OBJS) $(TARGET)

Weights.h

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#ifndef WEIGHTS_H
2+
#define WEIGHTS_H
3+
#include "eval.h"
4+
namespace engine::eval {
5+
inline Value tempo = 20;
6+
inline Value PawnValue = 100;
7+
inline Value KnightValue = 320;
8+
inline Value BishopValue = 330;
9+
inline Value RookValue = 500;
10+
inline Value QueenValue = 900;
11+
inline Value fianchettoBonus = 20;
12+
inline Value trappedBishopPenalty = 60;
13+
inline Value centerWeight = 5;
14+
inline Value mopUpKingDistWeight = 5;
15+
inline Value mopUpEdgeDistWeight = 10;
16+
inline Value spaceWeight = 2;
17+
inline Value bishopPairMg = 25;
18+
inline Value bishopPairEg = 50;
19+
inline Value rookOpenFileMg = 25;
20+
inline Value rookOpenFileEg = 20;
21+
inline Value rookSemiOpenFileMg = 15;
22+
inline Value rookSemiOpenFileEg = 12;
23+
inline Value doubledPawnMg = 10;
24+
inline Value doubledPawnEg = 20;
25+
inline Value isolatedPawnMg = 15;
26+
inline Value isolatedPawnEg = 25;
27+
inline Value kingShelterBaseMg = 20;
28+
inline Value kingShelterBaseEg = 5;
29+
inline Value kingShelterDecayMg = 4;
30+
inline Value kingShelterDecayEg = 1;
31+
inline Value kqkDistWeight = 15;
32+
inline Value kqkEdgeWeight = 15;
33+
inline Value krkDistWeight = 5;
34+
inline Value krkEdgeWeight = 10;
35+
inline Value kpkWeight = 15;
36+
inline Value mgMobilityCnt[7][8] = {
37+
{ 0, 0, 0, 0, 0, 0, 0, 0 },
38+
{ 0, 0, 0, 0, 0, 0, 0, 0 },
39+
{ -15, -8, -2, 4, 10, 16, 22, 28 },
40+
{ -20, -12, -4, 5, 14, 23, 32, 40 },
41+
{ -25, -15, -5, 5, 15, 25, 35, 45 },
42+
{ -30, -18, -6, 6, 18, 30, 42, 55 },
43+
{ -10, -5, 0, 5, 10, 15, 20, 25 }
44+
};
45+
inline Value egMobilityCnt[7][8] = {
46+
{ 0, 0, 0, 0, 0, 0, 0, 0 },
47+
{ 0, 0, 0, 0, 0, 0, 0, 0 },
48+
{ -20, -12, -4, 5, 14, 23, 32, 40 },
49+
{ -25, -15, -5, 5, 16, 27, 38, 50 },
50+
{ -30, -18, -6, 6, 18, 30, 42, 55 },
51+
{ -35, -22, -8, 8, 22, 35, 48, 60 },
52+
{ -15, -8, -2, 4, 10, 16, 22, 28 }
53+
};
54+
inline Value kingTropismMg[7] = { 0, 0, 3, 2, 2, 5, 0 };
55+
inline Value kingTropismEg[7] = { 0, 0, 2, 2, 3, 4, 0 };
56+
inline Value passedBonusMg[7] = { 0, 5, 15, 40, 80, 140, 200 };
57+
inline Value passedBonusEg[7] = { 0, 10, 30, 70, 140, 230, 350 };
58+
inline Value mg_knight_table[64] = { -50, -40, -30, -30, -30, -30, -40, -50, -40, -20, 0, 5, 5, 0, -20, -40,
59+
-30, 5, 10, 15, 15, 10, 5, -30, -30, 0, 15, 20, 20, 15, 0, -30,
60+
-30, 5, 15, 20, 20, 15, 5, -30, -30, 0, 10, 15, 15, 10, 0, -30,
61+
-40, -20, 0, 0, 0, 0, -20, -40, -50, -40, -30, -30, -30, -30, -40, -50 };
62+
inline Value mg_bishop_table[64] = { -20, -10, -10, -10, -10, -10, -10, -20, -10, 0, 0, 0, 0, 0, 0, -10,
63+
-10, 0, 10, 10, 10, 10, 0, -10, -10, 0, 5, 10, 10, 5, 0, -10,
64+
-10, 5, 5, 10, 10, 5, 5, -10, -10, 0, 10, 10, 10, 10, 0, -10,
65+
-10, 0, 0, 0, 0, 0, 0, -10, -20, -10, -10, -10, -10, -10, -10, -20 };
66+
inline Value mg_rook_table[64] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 0, 0, 5, 5, 5, 5, 5,
67+
5, 0, 0, 5, 5, 5, 5, 5, 5, 0, 0, 5, 5, 5, 5, 5, 5, 0, 0, 5, 5, 5,
68+
5, 5, 5, 0, 10, 15, 15, 15, 15, 15, 15, 10, 0, 0, 0, 0, 0, 0, 0, 0 };
69+
inline Value mg_king_table[64] = { -30, -40, -40, -50, -50, -40, -40, -30, -30, -40, -40, -50, -50, -40, -40, -30,
70+
-30, -40, -40, -50, -50, -40, -40, -30, -30, -40, -40, -50, -50, -40, -40, -30,
71+
-20, -30, -30, -40, -40, -30, -30, -20, -10, -20, -20, -20, -20, -20, -20, -10,
72+
20, 20, 0, 0, 0, 0, 20, 20, 20, 30, 10, 0, 0, 10, 30, 20 };
73+
inline Value mg_queen_table[64] = { -20, -10, -10, -5, -5, -10, -10, -20, -10, 0, 5, 0, 0, 0, 0, -10,
74+
-10, 5, 5, 5, 5, 5, 0, -10, 0, 0, 5, 5, 5, 5, 0, -5,
75+
-5, 0, 5, 5, 5, 5, 0, -5, -10, 0, 5, 5, 5, 5, 0, -10,
76+
-10, 0, 0, 0, 0, 0, 0, -10, -20, -10, -10, -5, -5, -10, -10, -20 };
77+
inline Value eg_knight_table[64] = { -50, -40, -20, -20, -20, -20, -40, -50, -40, -10, 5, 10, 10, 5, -10, -40,
78+
-30, 10, 20, 25, 25, 20, 10, -30, -30, 15, 25, 30, 30, 25, 15, -30,
79+
-30, 15, 25, 30, 30, 25, 15, -30, -30, 10, 20, 25, 25, 20, 10, -30,
80+
-40, -10, 5, 10, 10, 5, -10, -40, -50, -40, -20, -20, -20, -20, -40, -50 };
81+
inline Value eg_bishop_table[64] = { -10, -5, -5, -5, -5, -5, -5, -10, -5, 5, 10, 10, 10, 10, 5, -5, -5, 10, 15, 20, 20, 15,
82+
10, -5, -5, 10, 20, 25, 25, 20, 10, -5, -5, 10, 20, 25, 25, 20, 10, -5, -5, 10, 15, 20,
83+
20, 15, 10, -5, -5, 5, 10, 10, 10, 10, 5, -5, -10, -5, -5, -5, -5, -5, -5, -10 };
84+
inline Value eg_rook_table[64] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 10, 15, 15, 10, 5, 0, 0, 5, 10, 15, 15, 10,
85+
5, 0, 0, 5, 10, 15, 15, 10, 5, 0, 10, 15, 20, 25, 25, 20, 15, 10, 10, 15, 20, 25,
86+
25, 20, 15, 10, 20, 25, 30, 35, 35, 30, 25, 20, 0, 0, 0, 5, 5, 0, 0, 0 };
87+
inline Value eg_king_table[64] = { -50, -40, -30, -20, -20, -30, -40, -50, -40, -20, 0, 10, 10, 0, -20, -40,
88+
-30, 0, 20, 30, 30, 20, 0, -30, -20, 10, 30, 40, 40, 30, 10, -20,
89+
-20, 10, 30, 40, 40, 30, 10, -20, -30, 0, 20, 30, 30, 20, 0, -30,
90+
-40, -20, 0, 10, 10, 0, -20, -40, -50, -40, -30, -20, -20, -30, -40, -50 };
91+
inline Value eg_queen_table[64] = { -10, -5, -5, 0, 0, -5, -5, -10, -5, 0, 5, 5, 5, 5, 0, -5, -5, 5, 10, 15, 15, 10,
92+
5, -5, -5, 10, 15, 20, 20, 15, 10, -5, -5, 10, 15, 20, 20, 15, 10, -5, -5, 5, 10, 15,
93+
15, 10, 5, -5, -5, 0, 5, 5, 5, 5, 0, -5, -10, -5, -5, 0, 0, -5, -5, -10 };
94+
inline Value mg_pawn_table[56] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -5, -2, 2,
95+
5, 5, 2, -2, -5, -10, -5, 10, 20, 20, 10, -5, -10, -20, -10, 25, 40, 40, 25,
96+
-10, -20, -35, -20, 50, 80, 80, 50, -20, -35, -55, -40, 90, 130, 130, 90, -40, -55 };
97+
inline Value eg_pawn_table[56] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -5, -2, 2,
98+
5, 5, 2, -2, -5, -10, -5, 10, 20, 20, 10, -5, -10, -20, -10, 30, 55, 55, 30,
99+
-10, -20, -35, -20, 70, 110, 110, 70, -20, -35, -60, -45, 120, 180, 180, 120, -45, -60 };
100+
inline Value developedMg = 8;
101+
inline Value developedEg = 4;
102+
inline Value outpostBonusKnight[2] = { 15, 30 };
103+
inline Value outpostBonusBishop[2] = { 10, 25 };
104+
inline Value kingProtector[6][2] = {
105+
{ 0, 0 },
106+
{ 8, 12 },
107+
{ 5, 10 },
108+
{ 10, 15 },
109+
{ 3, 5 },
110+
{ 0, 0 }
111+
};
112+
inline Value threatByMinor[7][2] = {
113+
{ 0, 0 },
114+
{ 0, 0 },
115+
{ 15, 25 },
116+
{ 15, 25 },
117+
{ 25, 35 },
118+
{ 35, 50 }
119+
};
120+
inline Value threatByRook[7][2] = {
121+
{ 0, 0 },
122+
{ 0, 0 },
123+
{ 10, 15 },
124+
{ 10, 15 },
125+
{ 20, 25 },
126+
{ 25, 35 }
127+
};
128+
inline Value hangingScore = 70;
129+
inline Value overloadScore = 25;
130+
inline Value threatByRankScore = 10;
131+
inline Value minorImWt = 30;
132+
inline Value bishopImWt = 15;
133+
inline Value rookImWt = 20;
134+
inline Value queenImWt = 50;
135+
inline Value rammedPawnPenalty = 10;
136+
inline Value rookOnSeventhBonus = 30;
137+
inline Value earlyQueenPenalty = 5;
138+
} // namespace engine::eval
139+
#endif

0 commit comments

Comments
 (0)