BenBot 1.7.5
A chess engine
Loading...
Searching...
No Matches
Flips.hpp
Go to the documentation of this file.
1/*
2 * ======================================================================================
3 *
4 * ░▒▓███████▓▒░░▒▓████████▓▒░▒▓███████▓▒░ ░▒▓███████▓▒░ ░▒▓██████▓▒░▒▓████████▓▒░
5 * ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
6 * ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
7 * ░▒▓███████▓▒░░▒▓██████▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓███████▓▒░░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
8 * ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
9 * ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
10 * ░▒▓███████▓▒░░▒▓████████▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓███████▓▒░ ░▒▓██████▓▒░ ░▒▓█▓▒░
11 *
12 * ======================================================================================
13 */
14
19
20#pragma once
21
22#include <bit>
24
29
33[[nodiscard, gnu::const]] constexpr auto vertical(Bitboard board) noexcept -> Bitboard;
34
38[[nodiscard, gnu::const]] constexpr auto horizontal(Bitboard board) noexcept -> Bitboard;
39
40/*
41 ___ ,--,
42 ,---, ,--.'|_ ,--, ,--.'|
43 ,---.'| | | :,' ,--.'| | | :
44 | | : : : ' : | |, : : ' .--.--.
45 | | | ,---. .;__,' / ,--.--. `--'_ | ' | / / '
46 ,--.__| | / \ | | | / \ ,' ,'| ' | | | : /`./
47 / ,' | / / |:__,'| : .--. .-. | ' | | | | : | : ;_
48. ' / |. ' / | ' : |__ \__\/: . . | | : ' : |__ \ \ `.
49' ; |: |' ; /| | | '.'| ," .--.; | ' : |__ | | '.'| `----. \
50| | '/ '' | / | ; : ;/ / ,. | | | '.'|; : ;/ /`--' /__ ___ ___
51| : :|| : | | , /; : .' \; : ;| , /'--'. / .\/ .\/ .\
52 \ \ / \ \ / ---`-' | , .-./| , / ---`-' `--'---'\ ; \ ; \ ; |
53 `----' `----' `--`---' ---`-' `--" `--" `--"
54
55 */
56
57constexpr auto vertical(const Bitboard board) noexcept -> Bitboard
58{
59 return Bitboard {
60 std::byteswap(board.to_int())
61 };
62}
63
64constexpr auto horizontal(Bitboard board) noexcept -> Bitboard
65{
66 using namespace literals; // NOLINT(build/namespaces_literals)
67
68 static constexpr auto msk1 = 0x5555555555555555_bb;
69 static constexpr auto msk2 = 0x3333333333333333_bb;
70 static constexpr auto msk4 = 0x0f0f0f0f0f0f0f0f_bb;
71
72 board = ((board >> 1uz) & msk1) | ((board & msk1) << 1uz);
73 board = ((board >> 2uz) & msk2) | ((board & msk2) << 2uz);
74 board = ((board >> 4uz) & msk4) | ((board & msk4) << 4uz);
75
76 return board;
77}
78
79} // namespace chess::board::flips
constexpr auto horizontal(Bitboard board) noexcept -> Bitboard
Definition Flips.hpp:64
constexpr auto vertical(Bitboard board) noexcept -> Bitboard
Definition Flips.hpp:57