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
30 changes: 0 additions & 30 deletions .github/workflows/clang-format.yml

This file was deleted.

24 changes: 24 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,31 @@ on:
- '**.hpp'

jobs:
format:
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
commit_sha: ${{ steps.auto-commit.outputs.commit_hash }}

steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- 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')

- name: Commit and push changes
id: auto-commit
if: github.actor != 'github-actions[bot]' && github.event.pull_request.head.repo.full_name == github.repository
uses: stefanzweifel/git-auto-commit-action@v7

build:
needs: format
Comment thread
winapiadmin marked this conversation as resolved.
runs-on: ${{ matrix.os }}

strategy:
Expand Down
27 changes: 23 additions & 4 deletions attacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ namespace chess::attacks {
#ifndef GENERATE_AT_RUNTIME
#define _POSSIBLY_CONSTEXPR constexpr
#else
#define _POSSIBLY_CONSTEXPR const
#define _POSSIBLY_CONSTEXPR
#endif
// clang-format off
_POSSIBLY_CONSTEXPR std::array<uint64_t, 64> RookMagics = {
Expand Down Expand Up @@ -140,7 +140,6 @@ _POSSIBLY_CONSTEXPR std::pair<std::array<Magic, 64>, std::array<Bitboard, TableS
std::array<Bitboard, TableSize> attacks{};

size_t offset = 0;

for (Square sq = SQ_A1; sq < SQ_NONE; ++sq) {
Bitboard occ = 0;
Bitboard edges = ((attacks::MASK_RANK[0] | attacks::MASK_RANK[7]) & ~attacks::MASK_RANK[rank_of(sq)]) |
Expand All @@ -165,6 +164,7 @@ _POSSIBLY_CONSTEXPR std::pair<std::array<Magic, 64>, std::array<Bitboard, TableS

// Carry-rippler loop over all blocker subsets
occ = 0;

do {
size_t idx = entry(occ);
attacks[offset + idx] = AttackFunc(static_cast<Square>(sq), occ);
Expand All @@ -173,7 +173,6 @@ _POSSIBLY_CONSTEXPR std::pair<std::array<Magic, 64>, std::array<Bitboard, TableS

offset += (1ULL << bits);
}

return std::pair{ table, attacks };
}
_POSSIBLY_CONSTEXPR std::pair<std::array<Magic, 64>, std::array<Bitboard, 0x1480>> bishopData =
Expand All @@ -185,6 +184,26 @@ _POSSIBLY_CONSTEXPR std::pair<std::array<Magic, 64>, std::array<Bitboard, 0x1900
generate_magic_table<_chess::_HyperbolaRookAttacks, 0x19000, false>();
_POSSIBLY_CONSTEXPR std::array<Magic, 64> RookTable = rookData.first;
_POSSIBLY_CONSTEXPR std::array<Bitboard, 0x19000> RookAttacks = rookData.second;
/**
* @brief Returns the bishop attacks for a given square
* @param sq
* @param occupied
* @return
*/
[[nodiscard]] Bitboard bishop(Square sq, Bitboard occupied) {
return BishopAttacks[BishopTable[(int)sq].index + BishopTable[(int)sq](occupied)];
}

/**
* @brief Returns the rook attacks for a given square
* @param sq
* @param occupied
* @return
*/
[[nodiscard]] Bitboard rook(Square sq, Bitboard occupied) {
return RookAttacks[RookTable[(int)sq].index + RookTable[(int)sq](occupied)];
}

} // namespace chess::attacks
namespace chess::movegen {
inline static Bitboard att(PieceType pt, Square sq, Bitboard occ) {
Expand All @@ -208,4 +227,4 @@ inline static std::array<std::array<Bitboard, SQ_NONE + 1>, SQ_NONE + 1> generat
return squares_between_bb;
}
std::array<std::array<Bitboard, SQ_NONE + 1>, SQ_NONE + 1> SQUARES_BETWEEN_BB = generate_between();
} // namespace chess::movegen
} // namespace chess::movegen
23 changes: 5 additions & 18 deletions attacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "types.h"
#include <array>
#include <immintrin.h>
#include <vector>
namespace chess::attacks {
// clang-format off
// pre-calculated lookup table for pawn attacks
Expand Down Expand Up @@ -110,13 +111,9 @@ namespace chess::attacks {
0x101010101010101, 0x202020202020202, 0x404040404040404, 0x808080808080808,
0x1010101010101010, 0x2020202020202020, 0x4040404040404040, 0x8080808080808080,
};
extern const std::array<uint64_t, 64> BishopMagics;
extern const std::array<uint64_t, 64> RookMagics;
// clang-format on
#ifdef __BMI2__
constexpr uint64_t software_pext_u64(uint64_t val, uint64_t mask) {
if (!is_constant_evaluated())
return ~0ULL;
uint64_t result = 0;
uint64_t bit_position = 0;

Expand Down Expand Up @@ -153,10 +150,6 @@ struct Magic {

} // namespace chess::attacks
namespace chess::attacks {
extern const std::array<Magic, 64> RookTable;
extern const std::array<Bitboard, 0x19000> RookAttacks;
extern const std::array<Magic, 64> BishopTable;
extern const std::array<Bitboard, 0x1480> BishopAttacks;
/**
* @brief Shifts a bitboard in a given direction
* @tparam direction
Expand Down Expand Up @@ -293,34 +286,28 @@ template <Color c> [[nodiscard]] constexpr Bitboard pawn(const Bitboard pawns) {
Bitboard h2 = l2 | r2; // 2-square horizontal shifts
return (h1 << 16) | (h1 >> 16) | (h2 << 8) | (h2 >> 8); // vertical shifts: +2,+1,-2,-1
}

/**
* @brief Returns the bishop attacks for a given square
* @param sq
* @param occupied
* @return
*/
[[nodiscard]] constexpr Bitboard bishop(Square sq, Bitboard occupied) {
return BishopAttacks[BishopTable[(int)sq].index + BishopTable[(int)sq](occupied)];
}
[[nodiscard]] Bitboard bishop(Square sq, Bitboard occupied);

/**
* @brief Returns the rook attacks for a given square
* @param sq
* @param occupied
* @return
*/
[[nodiscard]] constexpr Bitboard rook(Square sq, Bitboard occupied) {
return RookAttacks[RookTable[(int)sq].index + RookTable[(int)sq](occupied)];
}

[[nodiscard]] Bitboard rook(Square sq, Bitboard occupied);
/**
* @brief Returns the queen attacks for a given square
* @param sq
* @param occupied
* @return
*/
[[nodiscard]] constexpr Bitboard queen(Square sq, Bitboard occupied) { return bishop(sq, occupied) | rook(sq, occupied); }
[[nodiscard]] inline Bitboard queen(Square sq, Bitboard occupied) { return bishop(sq, occupied) | rook(sq, occupied); }

/**
* @brief Returns the king attacks for a given square
Expand All @@ -336,7 +323,7 @@ template <Color c> [[nodiscard]] constexpr Bitboard pawn(const Bitboard pawns) {
* @tparam pt
* @return
*/
template <PieceType pt> [[nodiscard]] constexpr Bitboard slider(Square sq, Bitboard occupied) {
template <PieceType pt> [[nodiscard]] inline Bitboard slider(Square sq, Bitboard occupied) {
static_assert(pt == PieceType::BISHOP || pt == PieceType::ROOK || pt == PieceType::QUEEN, "PieceType must be a slider!");

if constexpr (pt == PieceType::BISHOP)
Expand Down
23 changes: 13 additions & 10 deletions chess960_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,22 @@ auto split_testcases(std::vector<TestEntry<std::string, perft_t>> &entries) {
bucket3.push_back(e);
}

size_t n1 = std::min(bucket1.size(), size_t(2000));
size_t n1 = std::min(bucket1.size(), size_t(1000));
optimized.insert(optimized.end(), bucket1.begin(), bucket1.begin() + n1);
#if defined(_WIN32)
size_t size = 5;
#else
size_t size = 15;
#endif
size_t n2 = std::min(bucket2.size(), size); // GitHub Actions having slowdown on Windows runners

size_t n2 = std::min(bucket2.size(), size_t(30));
optimized.insert(optimized.end(), bucket2.begin(), bucket2.begin() + n2);

size_t n3 = std::min(bucket3.size(), size_t(5));
#if defined(_WIN32)
size = 0;
#else
size = 1;
#endif
size_t n3 = std::min(bucket3.size(), size);
if (n3 > 0) {
optimized.insert(optimized.end(), bucket3.end() - n3, bucket3.end());
}
Expand All @@ -137,12 +146,6 @@ void check_perfts(std::vector<TestEntry<std::string, perft_t>> &entries) {
auto start_time = high_resolution_clock::now();
for (auto &entry : entries) {
std::cerr << entry.input << " (chess960=true) " << entry.info.depth;
#if !IS_RELEASE
if (entry.info.nodes > 1e6) {
std::cerr << "(skipped)\n";
continue;
}
#endif
std::cerr << '\n';
{
_Position<PolyglotPiece> pos(entry.input, true);
Expand Down
Loading
Loading