Skip to content

Commit 7926388

Browse files
winapiadminactions-usergithub-advanced-security[bot]
authored
chesslib integration and improvements (#7)
* Delete Makefile * integrated library * Create games.yml * Update games.yml * Update timeman.cpp * Update games.yml * Update games.yml * Update games.yml * Update games.yml * Update games.yml * Update games.yml * Update eval.cpp * Update eval.cpp * Update eval.h * Update movepick.cpp * Update movepick.h * Update movepick.cpp * Update search.cpp * Update eval.h * Update eval.cpp * Update movepick.h * Update search.cpp * Update search.cpp * Update movepick.cpp * Update movepick.cpp * Update movepick.cpp * Update movepick.cpp * Update movepick.cpp * Update games.yml * Update games.yml * Update games.yml * extend time control (6*time) * Update games.yml * set pv if really hit TT * Update games.yml * Update search.cpp * Update games.yml * Update games.yml * fix regression of null pointer deref * clear PV * Update search.cpp * fix overflow * implemented quiescence and fix illegal PV (variable shadowing) * no functional changes * fix typo * Update games.yml * Update games.yml * Update games.yml * update source * Update uci.cpp * some features and improvements (#3) fixed some bugs implemented LMR and NMP, features, etc. Passed STC: -------------------------------------------------- Results of new vs base (10+0.1, NULL, 16MB, UHO_Lichess_4852_v1.epd): Elo: 51.67 +/- 8.40, nElo: 92.31 +/- 14.79 LOS: 100.00 %, DrawRatio: 47.36 %, PairsRatio: 2.82 Games: 2120, Wins: 517, Losses: 204, Draws: 1399, Points: 1216.5 (57.38 %) Ptnml(0-2): [8, 138, 502, 357, 55], WL/DD Ratio: 0.11 LLR: 2.95 (100.2%) (-2.94, 2.94) [0.00, 2.00] -------------------------------------------------- Passed LTC: -------------------------------------------------- Results of new vs base (60+0.6, NULL, 16MB, UHO_Lichess_4852_v1.epd): Elo: 108.69 +/- 10.86, nElo: 199.39 +/- 18.67 LOS: 100.00 %, DrawRatio: 41.80 %, PairsRatio: 12.34 Games: 1330, Wins: 461, Losses: 58, Draws: 811, Points: 866.5 (65.15 %) Ptnml(0-2): [1, 28, 278, 283, 75], WL/DD Ratio: 0.11 LLR: 2.95 (100.1%) (-2.94, 2.94) [0.00, 2.00] -------------------------------------------------- * some QoL changes and specifically, BUGS. * library side fix nullmoves * Apply clang-format * Update eval.cpp * Update search.cpp * Fix typo in move type check for score calculation * Update uci.cpp * Fix FEN setting in engine loop * Update uci.cpp * 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> * Update games.yml * Update Makefile * resolved some issues, no functional changes * Apply clang-format * Potential fix for pull request finding 'CodeQL / Workflow does not contain permissions' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --------- Co-authored-by: GitHub Actions <actions@github.com> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent fc35fab commit 7926388

40 files changed

Lines changed: 4475 additions & 7278 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/clang-format.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: clang-format
2+
3+
on:
4+
pull_request:
5+
branches: [ "main" ]
6+
push:
7+
branches-ignore:
8+
- main
9+
jobs:
10+
format:
11+
if: github.actor != 'github-actions[bot]'
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: write
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
token: ${{ secrets.GITHUB_TOKEN }}
20+
21+
- name: Install clang-format
22+
run: pip install clang-format==18.1.0
23+
24+
- name: Run clang-format
25+
run: |
26+
clang-format -i $(git ls-files '*.cpp' '*.hpp' '*.h' '*.c')
27+
28+
- name: Commit and push changes
29+
run: |
30+
if ! git diff --quiet; then
31+
git config user.email "actions@github.com"
32+
git config user.name "GitHub Actions"
33+
git commit -am "Apply clang-format"
34+
git push
35+
fi

.github/workflows/games.yml

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
name: Fastchess SPRT Test (Linux)
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
base_ref:
7+
description: "Base branch, tag, or commit"
8+
required: false
9+
default: "test_chesslib"
10+
rounds:
11+
description: "Max rounds for SPRT"
12+
required: false
13+
default: "6000"
14+
tc:
15+
description: "Time control (e.g. 60+0.6 or 10+0.1)"
16+
required: false
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"
26+
output_exec:
27+
description: "Executable output file name"
28+
required: false
29+
default: "engine"
30+
31+
permissions:
32+
contents: read
33+
34+
jobs:
35+
36+
build-new:
37+
runs-on: ubuntu-latest
38+
39+
steps:
40+
- uses: actions/checkout@v4
41+
with:
42+
path: new
43+
persist-credentials: false
44+
45+
- name: Install deps
46+
run: sudo apt update && sudo apt install -y build-essential cmake
47+
48+
- name: Build new engine
49+
run: |
50+
cd new
51+
mkdir build
52+
cd build
53+
cmake .. -DCMAKE_BUILD_TYPE=Release
54+
make -j$(nproc)
55+
56+
- name: Upload new engine
57+
uses: actions/upload-artifact@v4
58+
with:
59+
name: new-engine
60+
path: new/build/engine
61+
62+
63+
build-base:
64+
runs-on: ubuntu-latest
65+
66+
steps:
67+
- uses: actions/checkout@v4
68+
with:
69+
ref: ${{ github.event.inputs.base_ref }}
70+
path: base
71+
persist-credentials: false
72+
73+
- name: Install deps
74+
run: sudo apt update && sudo apt install -y build-essential cmake
75+
76+
- name: Build base engine
77+
run: |
78+
cd base
79+
mkdir build
80+
cd build
81+
cmake .. -DCMAKE_BUILD_TYPE=Release
82+
make -j$(nproc)
83+
84+
- name: Upload base engine
85+
uses: actions/upload-artifact@v4
86+
with:
87+
name: base-engine
88+
path: base/build/${{ github.event.inputs.output_exec }}
89+
90+
91+
test:
92+
runs-on: ubuntu-latest
93+
needs: [build-new, build-base]
94+
95+
steps:
96+
- name: Download engines
97+
uses: actions/download-artifact@v4
98+
99+
- name: Install tools
100+
env:
101+
OUTPUT_EXEC: ${{ github.event.inputs.output_exec }}
102+
run: |
103+
sudo apt update
104+
sudo apt install -y wget unzip
105+
106+
wget https://github.com/Disservin/fastchess/releases/download/v1.8.0-alpha/fastchess-linux-x86-64.tar
107+
tar -xf fastchess-linux-x86-64.tar
108+
chmod +x fastchess-linux-x86-64/fastchess
109+
mv fastchess-linux-x86-64/fastchess fastchess
110+
111+
wget https://github.com/official-stockfish/books/raw/refs/heads/master/UHO_Lichess_4852_v1.epd.zip
112+
unzip UHO_Lichess_4852_v1.epd.zip
113+
114+
wget https://github.com/michiguel/Ordo/releases/download/1.0/ordo-linux64
115+
chmod +x ordo-linux64
116+
117+
chmod +x new-engine/engine
118+
chmod +x base-engine/$OUTPUT_EXEC
119+
120+
- name: Run fastchess
121+
env:
122+
ELO0: ${{ github.event.inputs.elo0 }}
123+
ELO1: ${{ github.event.inputs.elo1 }}
124+
TC: ${{ github.event.inputs.tc }}
125+
OUTPUT_EXEC: ${{ github.event.inputs.output_exec }}
126+
ROUNDS: ${{ github.event.inputs.rounds }}
127+
run: |
128+
./fastchess -recover \
129+
-engine cmd=new-engine/engine name=new \
130+
-engine cmd=base-engine/$OUTPUT_EXEC name=base \
131+
-openings file=UHO_Lichess_4852_v1.epd format=epd order=random \
132+
-each tc=$TC \
133+
-rounds $ROUNDS \
134+
-concurrency $(nproc) \
135+
-pgnout notation=san nodes=true file=games.pgn \
136+
-sprt elo0=$ELO0 elo1=$ELO1 alpha=0.05 beta=0.05 | tee results.txt
137+
./ordo-linux64 -o ratings.txt -- games.pgn
138+
- name: Upload results
139+
uses: actions/upload-artifact@v4
140+
with:
141+
name: results
142+
path: |
143+
games.pgn
144+
ratings.txt
145+
results.txt

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33

44
# But not these directories and files
55
!*.cpp
6-
!*.hpp
76
!*.h
87
!Makefile
98
!README.md
109
!LICENSE
1110
!.gitignore
12-
!CMakeLists.txt
11+
!CMakeLists.txt
12+
!.github/
13+
!.github/**
14+
!.clang-format

CMakeLists.txt

Lines changed: 67 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,81 @@
11
cmake_minimum_required(VERSION 3.10)
2-
project(chess_engine)
2+
project(cppchess_engine)
33

44
# Use C++17
55
set(CMAKE_CXX_STANDARD 17)
66
set(CMAKE_CXX_STANDARD_REQUIRED ON)
7-
8-
# Optional: enable warnings (MSVC specific flags)
9-
if (MSVC)
10-
add_compile_options(/W4 /permissive-)
11-
else()
12-
add_compile_options(-Wall -Wextra -pedantic)
13-
endif()
14-
15-
# Add the source files
16-
set(SOURCES
17-
main.cpp
18-
eval.cpp
19-
search.cpp
20-
tt.cpp
21-
movepick.cpp
22-
uci.cpp
23-
ucioptions.cpp
24-
timeman.cpp
7+
include(FetchContent)
8+
set(BUILD_TESTING OFF)
9+
FetchContent_Declare(
10+
chesslib
11+
GIT_REPOSITORY https://github.com/winapiadmin/chesslib.git
12+
GIT_TAG main
13+
)
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"
2534
)
2635

27-
# Define the executable
28-
add_executable(${PROJECT_NAME} ${SOURCES})
29-
30-
# Threading support
31-
find_package(Threads REQUIRED)
32-
target_link_libraries(${PROJECT_NAME} Threads::Threads)
33-
34-
# Platform-specific threading configurations
35-
if(WIN32)
36-
if(MSVC)
37-
# Windows with MSVC - uses Windows threading API
38-
target_compile_definitions(${PROJECT_NAME} PRIVATE WIN32_LEAN_AND_MEAN)
39-
elseif(MINGW)
40-
# MinGW on Windows - uses pthread
41-
target_compile_definitions(${PROJECT_NAME} PRIVATE _WIN32_WINNT=0x0601)
42-
# MinGW might need explicit pthread linking
43-
if(CMAKE_THREAD_LIBS_INIT)
44-
target_link_libraries(${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT})
45-
endif()
46-
endif()
47-
elseif(UNIX)
48-
# Unix/Linux systems - uses pthread
49-
if(CMAKE_THREAD_LIBS_INIT)
50-
target_link_libraries(${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT})
51-
endif()
52-
# Some older systems might need explicit -pthread flag
53-
if(CMAKE_USE_PTHREADS_INIT)
54-
target_compile_options(${PROJECT_NAME} PRIVATE -pthread)
55-
target_link_options(${PROJECT_NAME} PRIVATE -pthread)
56-
endif()
36+
if(ENGINE_TUNING)
37+
list(APPEND SOURCES "tune_cmd.cpp")
5738
endif()
5839

59-
# Optional: Add atomic library support for older compilers
60-
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9")
61-
target_link_libraries(${PROJECT_NAME} atomic)
62-
endif()
40+
add_executable(engine ${SOURCES})
6341

64-
# Set default build type if none is specified
65-
if(NOT CMAKE_BUILD_TYPE)
66-
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the build type (Debug, Release, etc.)" FORCE)
42+
target_link_libraries(engine PRIVATE chesslib syzygy_probe)
43+
target_include_directories(engine PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${chesslib_SOURCE_DIR})
44+
execute_process(
45+
COMMAND git rev-parse --short HEAD
46+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
47+
ERROR_QUIET
48+
OUTPUT_VARIABLE GIT_SHA
49+
OUTPUT_STRIP_TRAILING_WHITESPACE
50+
)
51+
if(GIT_SHA STREQUAL "")
52+
set(GIT_SHA "unknown")
6753
endif()
54+
execute_process(
55+
COMMAND git describe --tags --exact-match
56+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
57+
OUTPUT_VARIABLE GIT_TAG
58+
ERROR_QUIET
59+
OUTPUT_STRIP_TRAILING_WHITESPACE
60+
)
6861

69-
# Optional: Add specific compile flags per build type
70-
if(NOT MSVC)
71-
set(CMAKE_CXX_FLAGS_DEBUG "-g -march=native -mtune=native")
72-
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -march=native -mtune=native -funroll-loops -ftree-vectorize -fomit-frame-pointer")
62+
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR NOT CMAKE_BUILD_TYPE)
63+
set(BUILD_VERSION "debug-${GIT_SHA}")
64+
elseif(GIT_TAG)
65+
set(BUILD_VERSION "${GIT_TAG}")
7366
else()
74-
set(CMAKE_CXX_FLAGS_DEBUG "/Zi /Od")
75-
set(CMAKE_CXX_FLAGS_RELEASE "/O2 /DNDEBUG")
67+
set(BUILD_VERSION "release-${GIT_SHA}")
68+
endif()
69+
70+
message(STATUS "Build Version: ${BUILD_VERSION}")
71+
target_compile_definitions(engine PRIVATE BUILD_VERSION="${BUILD_VERSION}")
72+
if (ENGINE_TUNING)
73+
FetchContent_Declare(
74+
csv
75+
GIT_REPOSITORY https://github.com/vincentlaucsb/csv-parser.git
76+
GIT_TAG master
77+
)
78+
FetchContent_MakeAvailable(csv)
79+
target_link_libraries(engine PRIVATE csv)
80+
target_compile_definitions(engine PRIVATE USE_CSV_PARSER)
7681
endif()

0 commit comments

Comments
 (0)