Skip to content

Commit 2c0ce79

Browse files
authored
maintaince pr (#34)
1. improved repetition check 2. removing timeout of tests 3. clean illegal castling in FEN (this shouldn't be, yet it's fine) 4. tidied up code 5. replaced `HeapAllocatedValueList` with `std::vector` with reserve 6. replaced some ASSUMEs with asserts 7. added `START_FEN` and `START_CHESS960_FEN` 8. basically implementing X-FEN instead of Shredder FEN (i didn't know this fact)
1 parent dff750f commit 2c0ce79

21 files changed

Lines changed: 582 additions & 601 deletions

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
./** text=auto eol=lf

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,7 @@ Test log from the tester.
2626
**Hardware/Software info**
2727

2828
List about the OS, hardware, compiler and tester.
29+
30+
**Specifically, if the issue is reported by logic analysis, provide solution if applicable.**
31+
32+
solution to the issue if applicable. If not, please provide the logic analysis data and your interpretation of it.

.github/workflows/clang-format.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ name: clang-format
33
on:
44
pull_request:
55
branches: [ "main" ]
6-
6+
push:
7+
branches-ignore:
8+
- main
79
jobs:
810
format:
911
if: github.actor != 'github-actions[bot]'
@@ -14,6 +16,7 @@ jobs:
1416
steps:
1517
- uses: actions/checkout@v4
1618
with:
19+
ref: ${{ github.head_ref }}
1720
token: ${{ secrets.GITHUB_TOKEN }}
1821

1922
- name: Install clang-format
@@ -30,4 +33,4 @@ jobs:
3033
git config user.name "GitHub Actions"
3134
git commit -am "Apply clang-format"
3235
git push
33-
fi
36+
fi

.github/workflows/test.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: test
2+
3+
on:
4+
pull_request:
5+
branches: [ "main" ]
6+
7+
jobs:
8+
build:
9+
if: ${{ !endsWith(github.event.pull_request.title, 'no functional change') }}
10+
runs-on: ${{ matrix.os }}
11+
12+
strategy:
13+
fail-fast: true
14+
matrix:
15+
os: [ubuntu-latest, windows-latest]
16+
build_type: [Debug, Release]
17+
c_compiler: [gcc, clang, cl]
18+
19+
include:
20+
# Windows
21+
- os: windows-latest
22+
c_compiler: cl
23+
cpp_compiler: cl
24+
- os: windows-latest
25+
c_compiler: clang
26+
cpp_compiler: clang++
27+
- os: windows-latest
28+
c_compiler: gcc
29+
cpp_compiler: g++
30+
31+
# Linux
32+
- os: ubuntu-latest
33+
c_compiler: gcc
34+
cpp_compiler: g++
35+
- os: ubuntu-latest
36+
c_compiler: clang
37+
cpp_compiler: clang++
38+
39+
exclude:
40+
- os: ubuntu-latest
41+
c_compiler: cl
42+
43+
steps:
44+
- uses: actions/checkout@v4
45+
46+
- name: Set build dir
47+
id: vars
48+
shell: bash
49+
run: echo "dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
50+
51+
- name: Configure CMake
52+
shell: bash
53+
run: |
54+
cmake -B "${{ steps.vars.outputs.dir }}" \
55+
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }} \
56+
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} \
57+
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
58+
-DSANITIZERS="address,undefined" \
59+
-DDART_TESTING_TIMEOUT=0 \
60+
-S "${{ github.workspace }}"
61+
62+
- name: Build
63+
run: cmake --build ${{ steps.vars.outputs.dir }} --config ${{ matrix.build_type }}
64+
65+
- name: Test
66+
working-directory: ${{ steps.vars.outputs.dir }}
67+
shell: bash
68+
run: |
69+
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
70+
ctest --build-config ${{ matrix.build_type }} --verbose -j 4 --timeout 0
71+
else
72+
ctest --verbose -j 4 --timeout 0
73+
fi

.github/workflows/cmake-multi-platform.yml renamed to .github/workflows/try_compile.yml

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
name: CMake on multiple platforms
1+
name: Compilation
22

33
on:
4-
pull_request:
5-
branches: [ "main" ]
4+
pull_request:
65

76
jobs:
87
build:
98
runs-on: ${{ matrix.os }}
109

1110
strategy:
12-
fail-fast: false
11+
fail-fast: true
1312
matrix:
1413
os: [ubuntu-latest, windows-latest]
15-
build_type: [Debug, Release]
14+
build_type: [Debug]
1615
c_compiler: [gcc, clang, cl]
1716

1817
include:
@@ -52,10 +51,6 @@ jobs:
5251
run: |
5352
CXX_FLAGS=""
5453
LINK_FLAGS=""
55-
if [[ "${{ matrix.os }}" == "ubuntu-latest" && "${{ matrix.build_type }}" == "Debug" ]]; then
56-
CXX_FLAGS="-fsanitize=address,undefined -fno-omit-frame-pointer -g"
57-
LINK_FLAGS="-fsanitize=address,undefined"
58-
fi
5954
6055
cmake -B "${{ steps.vars.outputs.dir }}" \
6156
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }} \
@@ -67,13 +62,3 @@ jobs:
6762
6863
- name: Build
6964
run: cmake --build ${{ steps.vars.outputs.dir }} --config ${{ matrix.build_type }}
70-
71-
- name: Test
72-
working-directory: ${{ steps.vars.outputs.dir }}
73-
shell: bash
74-
run: |
75-
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
76-
ctest --build-config ${{ matrix.build_type }} --verbose -j 4
77-
else
78-
ctest --verbose -j 4
79-
fi

.gitignore

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1-
out/
2-
build/
3-
.vs/
1+
# Ignore everything
2+
*
3+
4+
# Allow source and essential files
45
!*.cpp
56
!*.h
7+
!CMakeLists.txt
68
!README.md
79
!LICENSE
8-
!CMakeLists.txt
910
!.gitignore
1011
!.gitattributes
11-
CMakePresets.json
12-
CMakeSettings.json
13-
*.s
14-
.vscode
15-
.cache
16-
deps/*
17-
!deps/
18-
*
12+
!.github/**
13+
!.github/
14+
# Ignore build/editor junk
15+
build/
16+
out/
17+
.vs/
18+
.vscode/
19+
.cache/
20+
cmake-*/
21+
# Ignore asm outputs
22+
*.s

.gitmodules

Lines changed: 0 additions & 3 deletions
This file was deleted.

CMakeLists.txt

Lines changed: 27 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ project(chesslib LANGUAGES CXX)
33

44
set(CMAKE_CXX_STANDARD 17)
55
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6-
option(ENABLE_COVERAGE "Enable coverage reporting" OFF)
6+
77
# --- Compiler tuning ---
88
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
99
if (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
@@ -32,10 +32,6 @@ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
3232
add_compile_options(/constexpr:steps2000000000 /constexpr:depth1024 ${ARCH_FLAG})
3333
endif()
3434

35-
if(ENABLE_COVERAGE)
36-
set(CMAKE_BUILD_TYPE Debug CACHE STRING "" FORCE)
37-
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF)
38-
endif()
3935
add_compile_definitions(GENERATE_AT_RUNTIME)
4036
if(CMAKE_BUILD_TYPE MATCHES "Debug")
4137
add_compile_definitions(_DEBUG)
@@ -48,125 +44,32 @@ set(SOURCES
4844
add_library(chesslib STATIC ${SOURCES})
4945
target_include_directories(chesslib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
5046
# --- Enable CTest integration ---
51-
enable_testing()
52-
include(FetchContent)
53-
FetchContent_Declare(
54-
doctest
55-
GIT_REPOSITORY https://github.com/doctest/doctest.git
56-
GIT_TAG v2.4.12
57-
)
58-
FetchContent_MakeAvailable(doctest)
59-
# --- Test executable ---
60-
add_executable(test_chess
61-
tests.cpp
62-
)
63-
add_executable(NonImportantTests
64-
non_core_tests.cpp
65-
)
66-
target_link_libraries(test_chess PRIVATE chesslib)
67-
target_include_directories(test_chess PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${doctest_SOURCE_DIR})
68-
target_link_libraries(NonImportantTests PRIVATE chesslib)
69-
target_include_directories(NonImportantTests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${doctest_SOURCE_DIR})
70-
add_test(NAME test_core COMMAND test_chess)
71-
add_test(NAME api_tests COMMAND NonImportantTests)
72-
if(ENABLE_COVERAGE)
73-
74-
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
75-
foreach(t chesslib test_chess NonImportantTests)
76-
target_compile_options(${t} PRIVATE
77-
--coverage
78-
-O0
79-
)
80-
target_link_options(${t} PRIVATE
81-
--coverage
82-
)
83-
endforeach()
84-
85-
find_program(GCOVR gcovr REQUIRED)
86-
87-
add_custom_target(coverage
88-
COMMAND ${CMAKE_COMMAND} -E make_directory coverage
89-
COMMAND ${CMAKE_CTEST_COMMAND}
90-
COMMAND ${GCOVR}
91-
-r ${CMAKE_SOURCE_DIR}
92-
--html
93-
--html-details
94-
-o coverage/index.html
95-
--exclude-directories tests
96-
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
97-
COMMENT "Generating GCC coverage report"
98-
)
99-
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
100-
foreach(t chesslib test_chess NonImportantTests)
101-
target_compile_options(${t} PRIVATE
102-
-fprofile-instr-generate
103-
-fcoverage-mapping
104-
-O0
105-
)
106-
target_link_options(${t} PRIVATE
107-
-fprofile-instr-generate
108-
)
109-
endforeach()
110-
111-
if(WIN32)
112-
113-
find_program(LLVM_PROFDATA llvm-profdata REQUIRED)
114-
find_program(LLVM_COV llvm-cov REQUIRED)
115-
116-
add_custom_target(coverage
117-
COMMAND ${CMAKE_COMMAND} -E make_directory coverage
118-
119-
COMMAND ${CMAKE_COMMAND} -E env
120-
LLVM_PROFILE_FILE=coverage/coverage.profraw
121-
CTEST_PARALLEL_LEVEL=1
122-
${CMAKE_CTEST_COMMAND}
123-
124-
COMMAND ${LLVM_PROFDATA} merge
125-
-sparse
126-
coverage/coverage.profraw
127-
-o coverage/coverage.profdata
128-
129-
COMMAND ${LLVM_COV} show
130-
$<TARGET_FILE:test_chess>
131-
$<TARGET_FILE:NonImportantTests>
132-
-instr-profile=coverage/coverage.profdata
133-
-format=html
134-
-output-dir=coverage
135-
-ignore-filename-regex="tests|doctest"
136-
-Xdemangler=llvm-cxxfilt
137-
138-
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
139-
COMMENT "Generating Clang coverage report (Windows)"
140-
)
141-
else()
142-
143-
find_program(LLVM_PROFDATA llvm-profdata REQUIRED)
144-
find_program(LLVM_COV llvm-cov REQUIRED)
145-
146-
add_custom_target(coverage
147-
COMMAND ${CMAKE_COMMAND} -E make_directory coverage
148-
149-
COMMAND ${CMAKE_COMMAND} -E env
150-
LLVM_PROFILE_FILE=coverage/%m.profraw
151-
${CMAKE_CTEST_COMMAND}
152-
153-
COMMAND ${LLVM_PROFDATA} merge
154-
-sparse
155-
coverage
156-
-o coverage/coverage.profdata
157-
158-
COMMAND ${LLVM_COV} show
159-
$<TARGET_FILE:test_chess>
160-
$<TARGET_FILE:NonImportantTests>
161-
-instr-profile=coverage/coverage.profdata
162-
-format=html
163-
-output-dir=coverage
164-
-ignore-filename-regex="tests|doctest"
165-
-Xdemangler=c++filt
166-
167-
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
168-
COMMENT "Generating Clang coverage report"
169-
)
47+
include(CTest)
48+
49+
if(BUILD_TESTING)
50+
include(FetchContent)
51+
FetchContent_Declare(
52+
doctest
53+
GIT_REPOSITORY https://github.com/doctest/doctest.git
54+
GIT_TAG v2.4.12
55+
)
56+
FetchContent_MakeAvailable(doctest)
57+
58+
# --- Test executable ---
59+
add_executable(test_chess tests.cpp)
60+
add_executable(NonImportantTests non_core_tests.cpp)
61+
62+
target_link_libraries(test_chess PRIVATE chesslib doctest::doctest)
63+
target_link_libraries(NonImportantTests PRIVATE chesslib doctest::doctest)
64+
65+
add_test(NAME test_core COMMAND test_chess)
66+
add_test(NAME api_tests COMMAND NonImportantTests)
67+
if (UNIX AND CMAKE_BUILD_TYPE MATCHES "Debug")
68+
set(SANITIZERS "" CACHE STRING "sanitizers such as undefined,address")
69+
70+
if (NOT "${SANITIZERS}" STREQUAL "")
71+
add_compile_options(-fsanitize=${SANITIZERS} -fno-omit-frame-pointer)
72+
add_link_options(-fsanitize=${SANITIZERS})
17073
endif()
17174
endif()
17275

attacks.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,7 @@ extern const std::array<Bitboard, 0x1480> BishopAttacks;
144144
* @param b
145145
* @return
146146
*/
147-
template <Direction direction> [[nodiscard]] static constexpr Bitboard shift(const Bitboard b) {
148-
ASSUME(direction == NORTH || direction == EAST || direction == SOUTH || direction == WEST || direction == NORTH_EAST ||
149-
direction == SOUTH_EAST || direction == SOUTH_WEST || direction == NORTH_WEST);
147+
[[nodiscard]] static constexpr Bitboard shift(const Bitboard b, Direction direction) {
150148
switch (direction) {
151149
case Direction::NORTH:
152150
return b << 8;
@@ -166,8 +164,16 @@ template <Direction direction> [[nodiscard]] static constexpr Bitboard shift(con
166164
return (b & ~MASK_FILE[7]) >> 7;
167165
default:
168166
UNREACHABLE();
167+
return 0;
169168
}
170169
}
170+
/**
171+
* @brief Shifts a bitboard in a given direction
172+
* @tparam direction
173+
* @param b
174+
* @return
175+
*/
176+
template <Direction direction> [[nodiscard]] static constexpr Bitboard shift(const Bitboard b) { return shift(b, direction); }
171177

172178
/**
173179
* @brief

0 commit comments

Comments
 (0)