Skip to content

Commit 0c59751

Browse files
authored
modernize a bit and add material_key (#27)
* intial commit (and later commits not merged for impl-specifics) * implemented material-only key calculation * debug for ASan on linux * escape paths for workflow (windows-specific)
1 parent 3015775 commit 0c59751

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

.github/workflows/cmake-multi-platform.yml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,22 @@ jobs:
5050
run: echo "dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
5151

5252
- name: Configure CMake
53-
run: >
54-
cmake -B ${{ steps.vars.outputs.dir }}
55-
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
56-
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
57-
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
58-
-S ${{ github.workspace }}
53+
shell: bash
54+
run: |
55+
CXX_FLAGS=""
56+
LINK_FLAGS=""
57+
if [[ "${{ matrix.os }}" == "ubuntu-latest" && "${{ matrix.build_type }}" == "Debug" ]]; then
58+
CXX_FLAGS="-fsanitize=address,undefined -fno-omit-frame-pointer -g"
59+
LINK_FLAGS="-fsanitize=address,undefined"
60+
fi
61+
62+
cmake -B "${{ steps.vars.outputs.dir }}" \
63+
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }} \
64+
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} \
65+
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
66+
-DCMAKE_CXX_FLAGS_DEBUG="$CXX_FLAGS" \
67+
-DCMAKE_EXE_LINKER_FLAGS="$LINK_FLAGS" \
68+
-S "${{ github.workspace }}"
5969
6070
- name: Build
6171
run: cmake --build ${{ steps.vars.outputs.dir }} --config ${{ matrix.build_type }}
@@ -68,4 +78,4 @@ jobs:
6878
ctest --build-config ${{ matrix.build_type }} --verbose
6979
else
7080
ctest --verbose
71-
fi
81+
fi

position.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ template <typename T, std::size_t MaxSize> class HeapAllocatedValueList {
149149
};
150150

151151
enum class MoveGenType : uint8_t { ALL, PAWN, KNIGHT, BISHOP, ROOK, QUEEN, KING, CAPTURE };
152-
template <typename PieceC = EnginePiece, typename = std::enable_if_t<std::is_same_v<PieceC, EnginePiece> || std::is_same_v<PieceC, PolyglotPiece> || std::is_same_v<PieceC, ContiguousMappingPiece>>> class _Position {
152+
template <typename PieceC = EnginePiece, typename = std::enable_if_t<is_piece_enum<PieceC>::value>> class _Position {
153153
private:
154154
HistoryEntry<PieceC> current_state;
155155

@@ -524,6 +524,8 @@ template <typename PieceC = EnginePiece, typename = std::enable_if_t<std::is_sam
524524
}
525525
return b != 0;
526526
}
527+
// Material-only key (note: Zobrist=Zpieces^Zep^Zcastling^Zturn, we just XORs the remaining, it's trivial)
528+
__FORCEINLINE Key material_key() const { return hash() ^ (zobrist::RandomTurn * ~sideToMove()) ^ (zobrist::RandomCastle[castlingRights()]) ^ (zobrist::RandomEP[ep_square() == SQ_NONE ? file_of(ep_square()) : FILE_NB]); }
527529
template <bool Strict = false> bool is_valid() const;
528530

529531
private:

0 commit comments

Comments
 (0)