Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 10 additions & 12 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
name: clang-format

on:
workflow_run:
workflows: ["CMake on multiple platforms"]
types:
- completed

pull_request:
branches: [ "main" ]

jobs:
format:
if: >
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'pull_request'
if: github.actor != 'github-actions[bot]'
runs-on: ubuntu-latest
permissions:
contents: write
Expand All @@ -20,6 +16,9 @@ jobs:
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Install clang-format
run: sudo apt-get update && sudo apt-get install -y clang-format

- name: Run clang-format
run: |
clang-format -i $(git ls-files '*.cpp' '*.hpp' '*.h' '*.c')
Expand All @@ -28,8 +27,7 @@ jobs:
run: |
if ! git diff --quiet; then
git config user.email "actions@github.com"
git.config user.name "GitHub Actions"
git add .
git commit -m "Apply clang-format"
git config user.name "GitHub Actions"
git commit -am "Apply clang-format"
git push
fi
fi
2 changes: 0 additions & 2 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: CMake on multiple platforms

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

Expand Down
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ build/
!LICENSE
!CMakeLists.txt
!.gitignore
!.gitattributes
CMakePresets.json
CMakeSettings.json
*.s
.vscode
.vscode
.cache
deps/*
!deps/
*
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "deps/doctest"]
path = deps/doctest
url = https://github.com/doctest/doctest.git
71 changes: 0 additions & 71 deletions .vscode/settings.json

This file was deleted.

116 changes: 111 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ project(chesslib LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

option(ENABLE_COVERAGE "Enable coverage reporting" OFF)
# --- Compiler tuning ---
set(SAN_ENABLED OFF CACHE BOOL "Whether to enable ASan or not")
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
# clang-cl: forward GCC/Clang style constexpr flags via /clang:
Expand All @@ -22,16 +21,21 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
-fconstexpr-steps=2000000000
-fconstexpr-depth=1024
-march=native -mtune=native
-ftemplate-backtrace-limit=0
-ftemplate-backtrace-limit=0 -static
)
endif()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(-fconstexpr-ops-limit=2000000000 -fconstexpr-depth=1024 -march=native -mtune=native -ftemplate-backtrace-limit=0)
add_compile_options(-fconstexpr-ops-limit=2000000000 -fconstexpr-depth=1024 -march=native -mtune=native -ftemplate-backtrace-limit=0 -static)

elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(ARCH_FLAG "/arch:AVX2" CACHE STRING "MSVC architecture flag (/arch:SSE2, /arch:AVX, /arch:AVX2, /arch:AVX512)")
add_compile_options(/constexpr:steps2000000000 /constexpr:depth1024 ${ARCH_FLAG})
endif()

if(ENABLE_COVERAGE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "" FORCE)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF)
endif()
add_compile_definitions(GENERATE_AT_RUNTIME)
if(CMAKE_BUILD_TYPE MATCHES "Debug")
add_compile_definitions(_DEBUG)
Expand Down Expand Up @@ -64,4 +68,106 @@ target_include_directories(test_chess PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${doct
target_link_libraries(NonImportantTests PRIVATE chesslib)
target_include_directories(NonImportantTests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${doctest_SOURCE_DIR})
add_test(NAME test_core COMMAND test_chess)
add_test(NAME api_tests COMMAND NonImportantTests)
add_test(NAME api_tests COMMAND NonImportantTests)
if(ENABLE_COVERAGE)

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
foreach(t chesslib test_chess NonImportantTests)
target_compile_options(${t} PRIVATE
--coverage
-O0
)
target_link_options(${t} PRIVATE
--coverage
)
endforeach()

find_program(GCOVR gcovr REQUIRED)

add_custom_target(coverage
COMMAND ${CMAKE_COMMAND} -E make_directory coverage
COMMAND ${CMAKE_CTEST_COMMAND}
COMMAND ${GCOVR}
-r ${CMAKE_SOURCE_DIR}
--html
--html-details
-o coverage/index.html
--exclude-directories tests
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Generating GCC coverage report"
)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
foreach(t chesslib test_chess NonImportantTests)
target_compile_options(${t} PRIVATE
-fprofile-instr-generate
-fcoverage-mapping
-O0
)
target_link_options(${t} PRIVATE
-fprofile-instr-generate
)
endforeach()

if(WIN32)

find_program(LLVM_PROFDATA llvm-profdata REQUIRED)
find_program(LLVM_COV llvm-cov REQUIRED)

add_custom_target(coverage
COMMAND ${CMAKE_COMMAND} -E make_directory coverage

COMMAND ${CMAKE_COMMAND} -E env
LLVM_PROFILE_FILE=coverage/coverage.profraw
CTEST_PARALLEL_LEVEL=1
${CMAKE_CTEST_COMMAND}

COMMAND ${LLVM_PROFDATA} merge
-sparse
coverage/coverage.profraw
-o coverage/coverage.profdata

COMMAND ${LLVM_COV} show
$<TARGET_FILE:test_chess>
$<TARGET_FILE:NonImportantTests>
-instr-profile=coverage/coverage.profdata
-format=html
-output-dir=coverage
-ignore-filename-regex="tests|doctest"
-Xdemangler=llvm-cxxfilt

WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Generating Clang coverage report (Windows)"
)
else()

find_program(LLVM_PROFDATA llvm-profdata REQUIRED)
find_program(LLVM_COV llvm-cov REQUIRED)

add_custom_target(coverage
COMMAND ${CMAKE_COMMAND} -E make_directory coverage

COMMAND ${CMAKE_COMMAND} -E env
LLVM_PROFILE_FILE=coverage/%m.profraw
${CMAKE_CTEST_COMMAND}

COMMAND ${LLVM_PROFDATA} merge
-sparse
coverage
-o coverage/coverage.profdata

COMMAND ${LLVM_COV} show
$<TARGET_FILE:test_chess>
$<TARGET_FILE:NonImportantTests>
-instr-profile=coverage/coverage.profdata
-format=html
-output-dir=coverage
-ignore-filename-regex="tests|doctest"
-Xdemangler=c++filt

WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Generating Clang coverage report"
)
endif()
endif()

endif()
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
# chesslib
(formerly MultiTypeChess, but it was an absolutely bad name)

This is now.... chesslib (it's super duplicated as I searched) a yet good chess library, as the name.
A chess library that supports Chess960 and decently fast enough.
9 changes: 3 additions & 6 deletions attacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,8 @@ inline static Bitboard att(PieceType pt, Square sq, Bitboard occ) {
return (pt == BISHOP) ? chess::_chess::_HyperbolaBishopAttacks(sq, occ) : chess::_chess::_HyperbolaRookAttacks(sq, occ);
}

inline static std::array<std::array<Bitboard, 64>, 64> generate_between() {
assert(att(BISHOP, SQ_A1, 0) == 9241421688590303744ULL &&
"Well... this is a debug message, but this is a landmine that the magic bitboards are NOT initialized before this, "
"wontwork\n");
std::array<std::array<Bitboard, 64>, 64> squares_between_bb{};
inline static std::array<std::array<Bitboard, SQ_NONE + 1>, SQ_NONE + 1> generate_between() {
std::array<std::array<Bitboard, SQ_NONE + 1>, SQ_NONE + 1> squares_between_bb{};

for (int sq1 = 0; sq1 < 64; ++sq1) {
for (PieceType pt : { BISHOP, ROOK }) {
Expand All @@ -192,5 +189,5 @@ inline static std::array<std::array<Bitboard, 64>, 64> generate_between() {

return squares_between_bb;
}
std::array<std::array<Bitboard, 64>, 64> SQUARES_BETWEEN_BB = generate_between();
std::array<std::array<Bitboard, SQ_NONE + 1>, SQ_NONE + 1> SQUARES_BETWEEN_BB = generate_between();
} // namespace chess::movegen
Loading