HooverChessUtils_PgnReader 0.9.0
Loading...
Searching...
No Matches
bitboard-intercepts.h
Go to the documentation of this file.
1// Hoover Chess Utilities / PGN reader
2// Copyright (C) 2025 Sami Kiminki
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <https://www.gnu.org/licenses/>.
16
17#ifndef HOOVER_CHESS_UTILS__PGN_READER__BITBOARD_INTERCEPTS_H_INCLUDED
18#define HOOVER_CHESS_UTILS__PGN_READER__BITBOARD_INTERCEPTS_H_INCLUDED
19
20#include "chessboard-types.h"
22
23#include "bitboard-tables.h"
24
25#include <array>
26#include <cinttypes>
27
29{
30
33
36{
37public:
66 static inline SquareSet getInterceptSquares(Square kingSq, Square checkerSq) noexcept
67 {
68 assert(checkerSq <= Square::NONE);
69 return SquareSet { ctBitBoardTables.rayIntercepts[static_cast<std::size_t>(checkerSq)][getIndexOfSquare(kingSq)] };
70 }
71
82 static inline SquareSet getRay(Square kingSq, Square pinnedSq) noexcept
83 {
84 assert(isValidSquare(kingSq));
85 assert(isValidSquare(pinnedSq));
86
88 assert(ray != SquareSet { });
89 return ray;
90 }
91
92 template <bool pinned>
93 static inline SquareSet getPinRestiction(Square kingSq, Square pinnedSq) noexcept
94 {
95 if constexpr (pinned)
96 return getRay(kingSq, pinnedSq);
97 else
98 return SquareSet::all();
99 }
100};
101
103
104}
105
106#endif
Check interceptions and pin checks.
Definition bitboard-intercepts.h:36
static SquareSet getInterceptSquares(Square kingSq, Square checkerSq) noexcept
Returns the set of squares that intercepts a check.
Definition bitboard-intercepts.h:66
static SquareSet getRay(Square kingSq, Square pinnedSq) noexcept
Returns a ray from king square to the direction of pinned piece square.
Definition bitboard-intercepts.h:82
static SquareSet getPinRestiction(Square kingSq, Square pinnedSq) noexcept
Definition bitboard-intercepts.h:93
Set of squares. Implemented using a bit-mask.
Definition chessboard-types-squareset.h:35
static constexpr SquareSet all() noexcept
Returns a set of all squares.
Definition chessboard-types-squareset.h:460
constexpr bool isValidSquare(Square sq) noexcept
Checks whether a value is a square.
Definition chessboard-types.h:306
constexpr std::size_t getIndexOfSquare(Square sq) noexcept
Returns an index for a square.
Definition chessboard-types.h:372
Square
Named square.
Definition chessboard-types.h:122
Definition chessboard-types-squareset.h:30
const BitBoardTables ctBitBoardTables
Various bitboard attack and other tables.
std::array< std::array< std::uint64_t, 64U >, 65U > rayIntercepts
Ray attack intercept squares from king to checker.
Definition bitboard-tables.h:63
std::array< std::array< std::uint64_t, 64U >, 64U > raysFromKing
Rays from a king square to the direction of a pinned piece square.
Definition bitboard-tables.h:69