HooverChessUtils_PgnReader 0.9.0
Loading...
Searching...
No Matches
bitboard-attacks-elementary.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_ELEMENTARY_H_INCLUDED
18#define HOOVER_CHESS_UTILS__PGN_READER__BITBOARD_ATTACKS_ELEMENTARY_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 {
40 const std::uint32_t offset { ctBitBoardTables.elementaryBishopOffsets[static_cast<SquareUnderlyingType>(sq)] };
41 const std::uint64_t occupMask { static_cast<std::uint64_t>(occupancyMask) };
42
43 const BitBoardTables::MasksAndMultipliers &masksAndMults { ctBitBoardTables.elementaryBishopMaskMults[static_cast<std::uint8_t>(sq)] };
44 std::uint64_t product { };
45 for (std::size_t i { }; i < 3U; ++i)
46 product |= (occupMask & masksAndMults.masks[i]) * masksAndMults.multipliers[i];
47
48 std::uint64_t baseOccupancy { product >> masksAndMults.shift };
49 return SquareSet { ctBitBoardTables.elementaryBishopRookAttackData[offset + baseOccupancy] };
50 }
51
53 static inline SquareSet getRookAttackMask(Square sq, SquareSet occupancyMask) noexcept
54 {
55 const std::uint32_t offset { ctBitBoardTables.elementaryRookOffsets[static_cast<SquareUnderlyingType>(sq)] };
56 const std::uint64_t occupMask { static_cast<std::uint64_t>(occupancyMask) };
57
58 const BitBoardTables::MasksAndMultipliers &masksAndMults { ctBitBoardTables.elementaryRookMaskMults[static_cast<std::uint8_t>(sq)] };
59 std::uint64_t product { };
60 for (std::size_t i { }; i < 3U; ++i)
61 product |= (occupMask & masksAndMults.masks[i]) * masksAndMults.multipliers[i];
62
63 std::uint64_t baseOccupancy { product >> masksAndMults.shift };
64 return SquareSet { ctBitBoardTables.elementaryBishopRookAttackData[offset + baseOccupancy] };
65 }
66};
67
68}
69
70#endif
Slider attacks implementation using Elementary Bitboards.
Definition bitboard-attacks-elementary.h:35
static SquareSet getBishopAttackMask(Square sq, SquareSet occupancyMask) noexcept
See Attacks::getBishopAttackMask() for documentation.
Definition bitboard-attacks-elementary.h:38
static SquareSet getRookAttackMask(Square sq, SquareSet occupancyMask) noexcept
See Attacks::getRookAttackMask() for documentation.
Definition bitboard-attacks-elementary.h:53
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.