io-chess
UCI chess engine
Loading...
Searching...
No Matches
FactorizedFeatureExtractor.cpp File Reference

Implementation of factorized feature extraction. More...

#include "FactorizedFeatureExtractor.hpp"
#include <algorithm>
#include <array>
#include <cstring>
Include dependency graph for FactorizedFeatureExtractor.cpp:

Classes

struct  ChebTableF
struct  FrontSpanTable
struct  SliderRayTable

Functions

template<chess::PieceType::underlying PT>
constexpr int piece_offset ()
static void fill_factorized_impl (const chess::Board &board, FactorizedInput &out)
static void fill_factorized_rich_impl (const chess::Board &board, FactorizedInput &out)

Variables

static const auto CHEBYSHEV_F
static const auto FRONT_SPAN
static const auto BETWEEN_EXCLUSIVE
static const auto ROOK_XRAY_RAYS
static const auto BISHOP_XRAY_RAYS
static const auto QUEEN_XRAY_RAYS

Detailed Description

Implementation of factorized feature extraction.

Function Documentation

◆ fill_factorized_impl()

void fill_factorized_impl ( const chess::Board & board,
FactorizedInput & out )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fill_factorized_rich_impl()

void fill_factorized_rich_impl ( const chess::Board & board,
FactorizedInput & out )
static
Here is the caller graph for this function:

◆ piece_offset()

template<chess::PieceType::underlying PT>
int piece_offset ( )
constexpr
Here is the caller graph for this function:

Variable Documentation

◆ BETWEEN_EXCLUSIVE

const auto BETWEEN_EXCLUSIVE
static
Initial value:
= []() {
std::array<std::array<chess::Bitboard, 64>, 64> t{};
for (int sq1 = 0; sq1 < 64; ++sq1) {
const int r1 = sq1 / 8;
const int f1 = sq1 % 8;
for (int sq2 = 0; sq2 < 64; ++sq2) {
const int r2 = sq2 / 8;
const int f2 = sq2 % 8;
const int dr = r2 - r1;
const int df = f2 - f1;
const bool aligned = (dr == 0) || (df == 0) || (std::abs(dr) == std::abs(df));
if (!aligned || (sq1 == sq2)) {
continue;
}
const int step_r = (dr > 0) - (dr < 0);
const int step_f = (df > 0) - (df < 0);
int rr = r1 + step_r;
int ff = f1 + step_f;
while (rr != r2 || ff != f2) {
t[(size_t)sq1][(size_t)sq2].set(rr * 8 + ff);
rr += step_r;
ff += step_f;
}
}
}
return t;
}()

◆ BISHOP_XRAY_RAYS

const auto BISHOP_XRAY_RAYS
static
Initial value:
= []() {
for (int sq = 0; sq < 64; ++sq) {
const int r = sq / 8;
const int f = sq % 8;
chess::Bitboard rays = 0;
for (int rr = r + 1, ff = f + 1; rr < 8 && ff < 8; ++rr, ++ff)
rays.set(rr * 8 + ff);
for (int rr = r + 1, ff = f - 1; rr < 8 && ff >= 0; ++rr, --ff)
rays.set(rr * 8 + ff);
for (int rr = r - 1, ff = f + 1; rr >= 0 && ff < 8; --rr, ++ff)
rays.set(rr * 8 + ff);
for (int rr = r - 1, ff = f - 1; rr >= 0 && ff >= 0; --rr, --ff)
rays.set(rr * 8 + ff);
t.data[sq] = rays;
}
return t;
}()
Definition FactorizedFeatureExtractor.cpp:115
chess::Bitboard data[64]
Definition FactorizedFeatureExtractor.cpp:116

◆ CHEBYSHEV_F

const auto CHEBYSHEV_F
static
Initial value:
= []() {
for (int sq1 = 0; sq1 < 64; ++sq1) {
int r1 = sq1 / 8, c1 = sq1 % 8;
for (int sq2 = 0; sq2 < 64; ++sq2) {
int r2 = sq2 / 8, c2 = sq2 % 8;
int dist = std::max(std::abs(r1 - r2), std::abs(c1 - c2));
t.data[0][sq1][sq2] = static_cast<float>(dist) / 7.0f;
}
for (int out_sq = 0; out_sq < 64; ++out_sq) {
int out_r = out_sq / 8, out_c = out_sq % 8;
int sq2 = (7 - out_r) * 8 + out_c;
int r2 = sq2 / 8, c2 = sq2 % 8;
int dist = std::max(std::abs(r1 - r2), std::abs(c1 - c2));
t.data[1][sq1][out_sq] = static_cast<float>(dist) / 7.0f;
}
}
return t;
}()
Definition FactorizedFeatureExtractor.cpp:17
float data[2][64][64]
Definition FactorizedFeatureExtractor.cpp:18

◆ FRONT_SPAN

const auto FRONT_SPAN
static
Initial value:
= []() {
for (int sq = 0; sq < 64; ++sq) {
const int r = sq / 8;
const int f = sq % 8;
chess::Bitboard white_span = 0;
for (int rr = r + 1; rr < 8; ++rr) {
white_span.set(rr * 8 + f);
if (f > 0)
white_span.set(rr * 8 + f - 1);
if (f < 7)
white_span.set(rr * 8 + f + 1);
}
chess::Bitboard black_span = 0;
for (int rr = r - 1; rr >= 0; --rr) {
black_span.set(rr * 8 + f);
if (f > 0)
black_span.set(rr * 8 + f - 1);
if (f < 7)
black_span.set(rr * 8 + f + 1);
}
t.data[0][sq] = white_span;
t.data[1][sq] = black_span;
}
return t;
}()
Definition FactorizedFeatureExtractor.cpp:47
chess::Bitboard data[2][64]
Definition FactorizedFeatureExtractor.cpp:48

◆ QUEEN_XRAY_RAYS

const auto QUEEN_XRAY_RAYS
static
Initial value:
= []() {
for (int sq = 0; sq < 64; ++sq) {
t.data[sq] = ROOK_XRAY_RAYS.data[sq] | BISHOP_XRAY_RAYS.data[sq];
}
return t;
}()
static const auto BISHOP_XRAY_RAYS
Definition FactorizedFeatureExtractor.cpp:140
static const auto ROOK_XRAY_RAYS
Definition FactorizedFeatureExtractor.cpp:119

◆ ROOK_XRAY_RAYS

const auto ROOK_XRAY_RAYS
static
Initial value:
= []() {
for (int sq = 0; sq < 64; ++sq) {
const int r = sq / 8;
const int f = sq % 8;
chess::Bitboard rays = 0;
for (int rr = r + 1; rr < 8; ++rr)
rays.set(rr * 8 + f);
for (int rr = r - 1; rr >= 0; --rr)
rays.set(rr * 8 + f);
for (int ff = f + 1; ff < 8; ++ff)
rays.set(r * 8 + ff);
for (int ff = f - 1; ff >= 0; --ff)
rays.set(r * 8 + ff);
t.data[sq] = rays;
}
return t;
}()