Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
598da59
fix bug and improvements
winapiadmin May 24, 2026
19958f3
Apply clang-format
actions-user May 24, 2026
1eca728
Refactor sideToMove to side_to_move for consistency
winapiadmin Jun 1, 2026
53f80a9
Fix method call to use correct side_to_move()
winapiadmin Jun 1, 2026
8d3c450
Update movepick.cpp
winapiadmin Jun 1, 2026
5cb6226
Fix case of FEN in setFEN method
winapiadmin Jun 1, 2026
864a7a9
Update uci.cpp
winapiadmin Jun 1, 2026
84643b7
a lil bit of tuning
winapiadmin Jun 7, 2026
c8ed2f4
formats
winapiadmin Jun 7, 2026
bf5461e
tb
winapiadmin Jun 7, 2026
ec0c935
Apply clang-format
actions-user Jun 7, 2026
01fcb3c
fix regression:)))) it's significantly stronger as internally needed
winapiadmin Jun 9, 2026
748a851
weights and standard clang-format
winapiadmin Jun 9, 2026
2168635
Apply clang-format
actions-user Jun 9, 2026
c1ccc8f
commented tunes
winapiadmin Jun 9, 2026
e2330f1
tuning
winapiadmin Jul 3, 2026
17d8bf4
timeman improve: use ply
winapiadmin Jul 7, 2026
97d8541
Apply clang-format
actions-user Jul 7, 2026
cf1d890
Update tune.cpp
winapiadmin Jul 7, 2026
d0aa0b8
Apply clang-format
actions-user Jul 7, 2026
7d4d48a
Update CMakeLists.txt
winapiadmin Jul 7, 2026
259e89e
Update games.yml
winapiadmin Jul 7, 2026
bc354c3
Merge branch 'test_chesslib' into 5-missing-hash-resize
winapiadmin Jul 8, 2026
3faf5fa
eol norm and Board -> Position
winapiadmin Jul 8, 2026
6dc67fc
Apply clang-format
actions-user Jul 8, 2026
fba7bd7
resolved issues
winapiadmin Jul 8, 2026
0608593
Merge branch '5-missing-hash-resize' of https://github.com/winapiadmi…
winapiadmin Jul 8, 2026
dd9c5ab
Apply clang-format
actions-user Jul 8, 2026
a78e094
--------------------------------------------------
winapiadmin Jul 8, 2026
ac259c5
Apply clang-format
actions-user Jul 8, 2026
d9e061a
some diffs
winapiadmin Jul 8, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
BasedOnStyle: LLVM
IndentWidth: 4
ContinuationIndentWidth: 4
ColumnLimit: 128
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
BinPackParameters: false
BinPackArguments: false
BraceWrapping:
# AfterInitializerList: true
AfterFunction: true
BeforeElse: false
IndentBraces: false
AlignArrayOfStructures: Right
Cpp11BracedListStyle: false
SpacesInContainerLiterals: false
31 changes: 20 additions & 11 deletions .github/workflows/games.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,27 @@ on:
base_ref:
description: "Base branch, tag, or commit"
required: false
default: "HandcraftedEngine"
default: "test_chesslib"
rounds:
description: "Max rounds for SPRT"
required: false
default: "6000"
tc:
description: "Time control (e.g. 60+0.5 or 10+0.1)"
description: "Time control (e.g. 60+0.6 or 10+0.1)"
required: false
default: "60+0.5"
default: "60+0.6"
elo0:
description: "elo0"
required: false
default: "0.5"
elo1:
description: "elo1"
required: false
default: "2.5"
output_exec:
description: "Executable output file name"
required: false
default: "chess_engine"
default: "engine"

permissions:
contents: write
Expand All @@ -31,14 +39,14 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
path: test_chesslib
path: new

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

- name: Build new engine
run: |
cd test_chesslib
cd new
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
Expand All @@ -48,7 +56,7 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: new-engine
path: test_chesslib/build/engine
path: new/build/engine


build-base:
Expand All @@ -58,14 +66,14 @@ jobs:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.base_ref }}
path: handcrafted
path: base

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

- name: Build base engine
run: |
cd handcrafted
cd base
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
Expand All @@ -75,7 +83,7 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: base-engine
path: handcrafted/build/${{ github.event.inputs.output_exec }}
path: base/build/${{ github.event.inputs.output_exec }}


test:
Expand Down Expand Up @@ -115,7 +123,7 @@ jobs:
-rounds ${{ github.event.inputs.rounds }} \
-concurrency $(nproc) \
-pgnout notation=san nodes=true file=games.pgn \
-sprt elo0=0 elo1=2 alpha=0.05 beta=0.05 | tee results.txt
-sprt elo0=${{ github.event.inputs.elo0 }} elo1=${{ github.event.inputs.elo1 }} alpha=0.05 beta=0.05 | tee results.txt

./ordo-linux64 -o ratings.txt -- games.pgn
sed -n '/Results of new vs base/,/^--------------------------------------------------$/p' results.txt >> ratings.txt
Expand All @@ -127,3 +135,4 @@ jobs:
path: |
games.pgn
ratings.txt
results.txt
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
!.gitignore
!CMakeLists.txt
!.github/
!.github/**
!.github/**
!.clang-format
45 changes: 40 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,35 @@ FetchContent_Declare(
GIT_REPOSITORY https://github.com/winapiadmin/chesslib.git
GIT_TAG main
)
FetchContent_MakeAvailable(chesslib)
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")
target_link_libraries(engine PRIVATE chesslib)
FetchContent_Declare(
tbprobe
GIT_REPOSITORY https://github.com/winapiadmin/tb_probing_tool.git
GIT_TAG main
)
set(BUILD_GAVIOTA OFF CACHE BOOL "Enable Gaviota TB probing" FORCE)
option(ENGINE_TUNING "enable Texel tuning (requires csv-parser)" OFF)
FetchContent_MakeAvailable(chesslib tbprobe)
set(SOURCES
"main.cpp"
"timeman.cpp"
"eval.cpp"
"tune.cpp"
"ucioption.cpp"
"tt.cpp"
"uci.cpp"
"search.cpp"
"score.cpp"
"movepick.cpp"
"tb.cpp"
)

if(ENGINE_TUNING)
list(APPEND SOURCES "tune_cmd.cpp")
endif()

add_executable(engine ${SOURCES})

target_link_libraries(engine PRIVATE chesslib syzygy_probe)
target_include_directories(engine PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${chesslib_SOURCE_DIR})
execute_process(
COMMAND git rev-parse --short HEAD
Expand All @@ -39,5 +65,14 @@ else()
endif()

message(STATUS "Build Version: ${BUILD_VERSION}")
add_definitions(-DBUILD_VERSION="${BUILD_VERSION}")

target_compile_definitions(engine PRIVATE BUILD_VERSION="${BUILD_VERSION}")
if (ENGINE_TUNING)
FetchContent_Declare(
csv
GIT_REPOSITORY https://github.com/vincentlaucsb/csv-parser.git
GIT_TAG master
)
FetchContent_MakeAvailable(csv)
target_link_libraries(engine PRIVATE csv)
target_compile_definitions(engine PRIVATE USE_CSV_PARSER)
endif()
47 changes: 47 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# :( openbench and fishtest require make
TARGET = engine

CXX ?= g++
CXXFLAGS ?= -std=c++17 -Wall -Wextra
OPTFLAGS ?= -O3
ifeq ($(LTO), yes)
OPTFLAGS += -flto
endif
ifeq ($(debug),no)
CXXFLAGS += -DNDEBUG
endif
ARCH ?= native

ifeq ($(ARCH), native)
CXXFLAGS += -march=native -mtune=native
endif
ifeq ($(ARCH), avx2)
CXXFLAGS += -march=haswell -mavx2 -mbmi -mbmi2 -msse4.1
endif
ifeq ($(ARCH), bmi2)
CXXFLAGS += -mbmi2
endif
ifeq ($(ARCH), sse41)
CXXFLAGS += -msse4.1
endif
ifeq ($(ARCH), x86-64)
CXXFLAGS += -march=x86-64
endif
deps:
test -d deps/chesslib || git clone https://github.com/winapiadmin/chesslib deps/chesslib
test -d deps/tbprobe || git clone https://github.com/winapiadmin/tb_probing_tool deps/tbprobe
# Tuning is not required on Makefile, use CMake.
SRCS = $(filter-out tune_cmd.cpp, $(wildcard *.cpp)) $(wildcard deps/chesslib/*.cpp) $(wildcard deps/tbprobe/*.cpp)
OBJS = $(SRCS:.cpp=.o)

.PHONY: all clean deps
all: deps $(TARGET)

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

%.o: %.cpp
$(CXX) $(CXXFLAGS) $(OPTFLAGS) -Ideps/chesslib -Ideps/tbprobe/syzygy -c $< -o $@

clean:
rm -f $(OBJS) $(TARGET)
139 changes: 139 additions & 0 deletions Weights.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#ifndef WEIGHTS_H
#define WEIGHTS_H
#include "eval.h"
namespace engine::eval {
inline Value tempo = 20;
inline Value PawnValue = 100;
inline Value KnightValue = 320;
inline Value BishopValue = 330;
inline Value RookValue = 500;
inline Value QueenValue = 900;
inline Value fianchettoBonus = 20;
inline Value trappedBishopPenalty = 60;
inline Value centerWeight = 5;
inline Value mopUpKingDistWeight = 5;
inline Value mopUpEdgeDistWeight = 10;
inline Value spaceWeight = 2;
inline Value bishopPairMg = 25;
inline Value bishopPairEg = 50;
inline Value rookOpenFileMg = 25;
inline Value rookOpenFileEg = 20;
inline Value rookSemiOpenFileMg = 15;
inline Value rookSemiOpenFileEg = 12;
inline Value doubledPawnMg = 10;
inline Value doubledPawnEg = 20;
inline Value isolatedPawnMg = 15;
inline Value isolatedPawnEg = 25;
inline Value kingShelterBaseMg = 20;
inline Value kingShelterBaseEg = 5;
inline Value kingShelterDecayMg = 4;
inline Value kingShelterDecayEg = 1;
inline Value kqkDistWeight = 15;
inline Value kqkEdgeWeight = 15;
inline Value krkDistWeight = 5;
inline Value krkEdgeWeight = 10;
inline Value kpkWeight = 15;
inline Value mgMobilityCnt[7][8] = {
{ 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0 },
{ -15, -8, -2, 4, 10, 16, 22, 28 },
{ -20, -12, -4, 5, 14, 23, 32, 40 },
{ -25, -15, -5, 5, 15, 25, 35, 45 },
{ -30, -18, -6, 6, 18, 30, 42, 55 },
{ -10, -5, 0, 5, 10, 15, 20, 25 }
};
inline Value egMobilityCnt[7][8] = {
{ 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0 },
{ -20, -12, -4, 5, 14, 23, 32, 40 },
{ -25, -15, -5, 5, 16, 27, 38, 50 },
{ -30, -18, -6, 6, 18, 30, 42, 55 },
{ -35, -22, -8, 8, 22, 35, 48, 60 },
{ -15, -8, -2, 4, 10, 16, 22, 28 }
};
inline Value kingTropismMg[7] = { 0, 0, 3, 2, 2, 5, 0 };
inline Value kingTropismEg[7] = { 0, 0, 2, 2, 3, 4, 0 };
inline Value passedBonusMg[7] = { 0, 5, 15, 40, 80, 140, 200 };
inline Value passedBonusEg[7] = { 0, 10, 30, 70, 140, 230, 350 };
inline Value mg_knight_table[64] = { -50, -40, -30, -30, -30, -30, -40, -50, -40, -20, 0, 5, 5, 0, -20, -40,
-30, 5, 10, 15, 15, 10, 5, -30, -30, 0, 15, 20, 20, 15, 0, -30,
-30, 5, 15, 20, 20, 15, 5, -30, -30, 0, 10, 15, 15, 10, 0, -30,
-40, -20, 0, 0, 0, 0, -20, -40, -50, -40, -30, -30, -30, -30, -40, -50 };
inline Value mg_bishop_table[64] = { -20, -10, -10, -10, -10, -10, -10, -20, -10, 0, 0, 0, 0, 0, 0, -10,
-10, 0, 10, 10, 10, 10, 0, -10, -10, 0, 5, 10, 10, 5, 0, -10,
-10, 5, 5, 10, 10, 5, 5, -10, -10, 0, 10, 10, 10, 10, 0, -10,
-10, 0, 0, 0, 0, 0, 0, -10, -20, -10, -10, -10, -10, -10, -10, -20 };
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,
5, 0, 0, 5, 5, 5, 5, 5, 5, 0, 0, 5, 5, 5, 5, 5, 5, 0, 0, 5, 5, 5,
5, 5, 5, 0, 10, 15, 15, 15, 15, 15, 15, 10, 0, 0, 0, 0, 0, 0, 0, 0 };
inline Value mg_king_table[64] = { -30, -40, -40, -50, -50, -40, -40, -30, -30, -40, -40, -50, -50, -40, -40, -30,
-30, -40, -40, -50, -50, -40, -40, -30, -30, -40, -40, -50, -50, -40, -40, -30,
-20, -30, -30, -40, -40, -30, -30, -20, -10, -20, -20, -20, -20, -20, -20, -10,
20, 20, 0, 0, 0, 0, 20, 20, 20, 30, 10, 0, 0, 10, 30, 20 };
inline Value mg_queen_table[64] = { -20, -10, -10, -5, -5, -10, -10, -20, -10, 0, 5, 0, 0, 0, 0, -10,
-10, 5, 5, 5, 5, 5, 0, -10, 0, 0, 5, 5, 5, 5, 0, -5,
-5, 0, 5, 5, 5, 5, 0, -5, -10, 0, 5, 5, 5, 5, 0, -10,
-10, 0, 0, 0, 0, 0, 0, -10, -20, -10, -10, -5, -5, -10, -10, -20 };
inline Value eg_knight_table[64] = { -50, -40, -20, -20, -20, -20, -40, -50, -40, -10, 5, 10, 10, 5, -10, -40,
-30, 10, 20, 25, 25, 20, 10, -30, -30, 15, 25, 30, 30, 25, 15, -30,
-30, 15, 25, 30, 30, 25, 15, -30, -30, 10, 20, 25, 25, 20, 10, -30,
-40, -10, 5, 10, 10, 5, -10, -40, -50, -40, -20, -20, -20, -20, -40, -50 };
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,
10, -5, -5, 10, 20, 25, 25, 20, 10, -5, -5, 10, 20, 25, 25, 20, 10, -5, -5, 10, 15, 20,
20, 15, 10, -5, -5, 5, 10, 10, 10, 10, 5, -5, -10, -5, -5, -5, -5, -5, -5, -10 };
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,
5, 0, 0, 5, 10, 15, 15, 10, 5, 0, 10, 15, 20, 25, 25, 20, 15, 10, 10, 15, 20, 25,
25, 20, 15, 10, 20, 25, 30, 35, 35, 30, 25, 20, 0, 0, 0, 5, 5, 0, 0, 0 };
inline Value eg_king_table[64] = { -50, -40, -30, -20, -20, -30, -40, -50, -40, -20, 0, 10, 10, 0, -20, -40,
-30, 0, 20, 30, 30, 20, 0, -30, -20, 10, 30, 40, 40, 30, 10, -20,
-20, 10, 30, 40, 40, 30, 10, -20, -30, 0, 20, 30, 30, 20, 0, -30,
-40, -20, 0, 10, 10, 0, -20, -40, -50, -40, -30, -20, -20, -30, -40, -50 };
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,
5, -5, -5, 10, 15, 20, 20, 15, 10, -5, -5, 10, 15, 20, 20, 15, 10, -5, -5, 5, 10, 15,
15, 10, 5, -5, -5, 0, 5, 5, 5, 5, 0, -5, -10, -5, -5, 0, 0, -5, -5, -10 };
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,
5, 5, 2, -2, -5, -10, -5, 10, 20, 20, 10, -5, -10, -20, -10, 25, 40, 40, 25,
-10, -20, -35, -20, 50, 80, 80, 50, -20, -35, -55, -40, 90, 130, 130, 90, -40, -55 };
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,
5, 5, 2, -2, -5, -10, -5, 10, 20, 20, 10, -5, -10, -20, -10, 30, 55, 55, 30,
-10, -20, -35, -20, 70, 110, 110, 70, -20, -35, -60, -45, 120, 180, 180, 120, -45, -60 };
inline Value developedMg = 8;
inline Value developedEg = 4;
inline Value outpostBonusKnight[2] = { 15, 30 };
inline Value outpostBonusBishop[2] = { 10, 25 };
inline Value kingProtector[6][2] = {
{ 0, 0 },
{ 8, 12 },
{ 5, 10 },
{ 10, 15 },
{ 3, 5 },
{ 0, 0 }
};
inline Value threatByMinor[7][2] = {
{ 0, 0 },
{ 0, 0 },
{ 15, 25 },
{ 15, 25 },
{ 25, 35 },
{ 35, 50 }
};
inline Value threatByRook[7][2] = {
{ 0, 0 },
{ 0, 0 },
{ 10, 15 },
{ 10, 15 },
{ 20, 25 },
{ 25, 35 }
};
inline Value hangingScore = 70;
inline Value overloadScore = 25;
inline Value threatByRankScore = 10;
inline Value minorImWt = 30;
inline Value bishopImWt = 15;
inline Value rookImWt = 20;
inline Value queenImWt = 50;
inline Value rammedPawnPenalty = 10;
inline Value rookOnSeventhBonus = 30;
inline Value earlyQueenPenalty = 5;
} // namespace engine::eval
#endif
Loading
Loading