HooverChessUtils_PgnReader 0.9.0
Loading...
Searching...
No Matches
bitboard-attacks-black-magic.h
Go to the documentation of this file.
1// Hoover Chess Utilities / PGN reader
2// Copyright (C) 2026 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_ATTACKS_BLACK_MAGIC_H_INCLUDED
18#define HOOVER_CHESS_UTILS__PGN_READER__BITBOARD_ATTACKS_BLACK_MAGIC_H_INCLUDED
19
20#include "pgnreader-config.h"
21
22#include "bitboard-tables.h"
24
25#include <array>
26#include <cinttypes>
27
28
30{
31
35{
36public:
38 static inline SquareSet getBishopAttackMask(Square sq, SquareSet occupancyMask) noexcept
39 {
42
43 const std::uint64_t offset {
44 (((static_cast<std::uint64_t>(occupancyMask) | data.mask) * data.hash) >> 55U) };
45
46 return SquareSet { data.attacksBase[offset] };
47 }
48
50 static inline SquareSet getRookAttackMask(Square sq, SquareSet occupancyMask) noexcept
51 {
54
55 const std::uint64_t offset {
56 (((static_cast<std::uint64_t>(occupancyMask) | data.mask) * data.hash) >> 52U) };
57
58 return SquareSet { data.attacksBase[offset] };
59 }
60};
61
62}
63
64#endif
Slider attacks implementation using Elementary Bitboards.
Definition bitboard-attacks-black-magic.h:35
static SquareSet getBishopAttackMask(Square sq, SquareSet occupancyMask) noexcept
See Attacks::getBishopAttackMask() for documentation.
Definition bitboard-attacks-black-magic.h:38
static SquareSet getRookAttackMask(Square sq, SquareSet occupancyMask) noexcept
See Attacks::getRookAttackMask() for documentation.
Definition bitboard-attacks-black-magic.h:50
Set of squares. Implemented using a bit-mask.
Definition chessboard-types-squareset.h:35
std::uint_fast8_t SquareUnderlyingType
Underlying type of Square
Definition chessboard-types.h:38
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< BlackMagicData, 64U > blackMagicRookMagics
Definition bitboard-tables.h:134
std::array< BlackMagicData, 64U > blackMagicBishopMagics
Definition bitboard-tables.h:133