BenBot 1.7.5
A chess engine
Loading...
Searching...
No Matches
Shifts.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
25
30
31using pieces::Color;
32
35
37[[nodiscard, gnu::const]] constexpr auto north(Bitboard board) noexcept -> Bitboard;
38
40[[nodiscard, gnu::const]] constexpr auto south(Bitboard board) noexcept -> Bitboard;
41
43[[nodiscard, gnu::const]] constexpr auto east(Bitboard board) noexcept -> Bitboard;
44
46[[nodiscard, gnu::const]] constexpr auto west(Bitboard board) noexcept -> Bitboard;
47
49[[nodiscard, gnu::const]] constexpr auto northeast(Bitboard board) noexcept -> Bitboard;
50
52[[nodiscard, gnu::const]] constexpr auto northwest(Bitboard board) noexcept -> Bitboard;
53
55[[nodiscard, gnu::const]] constexpr auto southeast(Bitboard board) noexcept -> Bitboard;
56
58[[nodiscard, gnu::const]] constexpr auto southwest(Bitboard board) noexcept -> Bitboard;
59
61template <Color Side>
62[[nodiscard, gnu::const]] constexpr auto pawn_forward(Bitboard board) noexcept -> Bitboard;
63
65template <Color Side>
66[[nodiscard, gnu::const]] constexpr auto pawn_backward(Bitboard board) noexcept -> Bitboard;
67
69template <Color Side>
70[[nodiscard, gnu::const]] constexpr auto pawn_capture_east(Bitboard board) noexcept -> Bitboard;
71
73template <Color Side>
74[[nodiscard, gnu::const]] constexpr auto pawn_capture_west(Bitboard board) noexcept -> Bitboard;
75
80template <Color Side>
81[[nodiscard, gnu::const]] constexpr auto pawn_inv_capture_east(Bitboard board) noexcept -> Bitboard;
82
87template <Color Side>
88[[nodiscard, gnu::const]] constexpr auto pawn_inv_capture_west(Bitboard board) noexcept -> Bitboard;
89
91
92/*
93 ___ ,--,
94 ,---, ,--.'|_ ,--, ,--.'|
95 ,---.'| | | :,' ,--.'| | | :
96 | | : : : ' : | |, : : ' .--.--.
97 | | | ,---. .;__,' / ,--.--. `--'_ | ' | / / '
98 ,--.__| | / \ | | | / \ ,' ,'| ' | | | : /`./
99 / ,' | / / |:__,'| : .--. .-. | ' | | | | : | : ;_
100. ' / |. ' / | ' : |__ \__\/: . . | | : ' : |__ \ \ `.
101' ; |: |' ; /| | | '.'| ," .--.; | ' : |__ | | '.'| `----. \
102| | '/ '' | / | ; : ;/ / ,. | | | '.'|; : ;/ /`--' /__ ___ ___
103| : :|| : | | , /; : .' \; : ;| , /'--'. / .\/ .\/ .\
104 \ \ / \ \ / ---`-' | , .-./| , / ---`-' `--'---'\ ; \ ; \ ; |
105 `----' `----' `--`---' ---`-' `--" `--" `--"
106
107 */
108
109constexpr auto north(const Bitboard board) noexcept -> Bitboard
110{
111 return board << 8uz;
112}
113
114constexpr auto south(const Bitboard board) noexcept -> Bitboard
115{
116 return board >> 8uz;
117}
118
119constexpr auto east(const Bitboard board) noexcept -> Bitboard
120{
121 constexpr auto notHFile = masks::files::H.inverse();
122
123 return (board & notHFile) << 1uz;
124}
125
126constexpr auto west(const Bitboard board) noexcept -> Bitboard
127{
128 constexpr auto notAFile = masks::files::A.inverse();
129
130 return (board & notAFile) >> 1uz;
131}
132
133constexpr auto northeast(const Bitboard board) noexcept -> Bitboard
134{
135 constexpr auto notHFile = masks::files::H.inverse();
136
137 return (board & notHFile) << 9uz;
138}
139
140constexpr auto northwest(const Bitboard board) noexcept -> Bitboard
141{
142 constexpr auto notAFile = masks::files::A.inverse();
143
144 return (board & notAFile) << 7uz;
145}
146
147constexpr auto southeast(const Bitboard board) noexcept -> Bitboard
148{
149 constexpr auto notHFile = masks::files::H.inverse();
150
151 return (board & notHFile) >> 7uz;
152}
153
154constexpr auto southwest(const Bitboard board) noexcept -> Bitboard
155{
156 constexpr auto notAFile = masks::files::A.inverse();
157
158 return (board & notAFile) >> 9uz;
159}
160
161template <Color Side>
162constexpr auto pawn_forward(const Bitboard board) noexcept -> Bitboard
163{
164 if constexpr (Side == Color::White)
165 return north(board);
166 else
167 return south(board);
168}
169
170template <Color Side>
171constexpr auto pawn_backward(const Bitboard board) noexcept -> Bitboard
172{
173 if constexpr (Side == Color::White)
174 return south(board);
175 else
176 return north(board);
177}
178
179template <Color Side>
180constexpr auto pawn_capture_east(const Bitboard board) noexcept -> Bitboard
181{
182 if constexpr (Side == Color::White)
183 return northeast(board);
184 else
185 return southeast(board);
186}
187
188template <Color Side>
189constexpr auto pawn_inv_capture_east(const Bitboard board) noexcept -> Bitboard
190{
191 if constexpr (Side == Color::White)
192 return southwest(board);
193 else
194 return northwest(board);
195}
196
197template <Color Side>
198constexpr auto pawn_capture_west(const Bitboard board) noexcept -> Bitboard
199{
200 if constexpr (Side == Color::White)
201 return northwest(board);
202 else
203 return southwest(board);
204}
205
206template <Color Side>
207constexpr auto pawn_inv_capture_west(const Bitboard board) noexcept -> Bitboard
208{
209 if constexpr (Side == Color::White)
210 return southeast(board);
211 else
212 return northeast(board);
213}
214
215} // namespace chess::board::shifts
constexpr auto northeast(Bitboard board) noexcept -> Bitboard
Definition Shifts.hpp:133
constexpr auto northwest(Bitboard board) noexcept -> Bitboard
Definition Shifts.hpp:140
constexpr auto west(Bitboard board) noexcept -> Bitboard
Definition Shifts.hpp:126
constexpr auto pawn_backward(Bitboard board) noexcept -> Bitboard
Definition Shifts.hpp:171
constexpr auto pawn_inv_capture_east(Bitboard board) noexcept -> Bitboard
Definition Shifts.hpp:189
constexpr auto north(Bitboard board) noexcept -> Bitboard
Definition Shifts.hpp:109
constexpr auto southwest(Bitboard board) noexcept -> Bitboard
Definition Shifts.hpp:154
constexpr auto pawn_capture_west(Bitboard board) noexcept -> Bitboard
Definition Shifts.hpp:198
constexpr auto east(Bitboard board) noexcept -> Bitboard
Definition Shifts.hpp:119
constexpr auto pawn_forward(Bitboard board) noexcept -> Bitboard
Definition Shifts.hpp:162
constexpr auto pawn_capture_east(Bitboard board) noexcept -> Bitboard
Definition Shifts.hpp:180
constexpr auto southeast(Bitboard board) noexcept -> Bitboard
Definition Shifts.hpp:147
constexpr auto south(Bitboard board) noexcept -> Bitboard
Definition Shifts.hpp:114
constexpr auto pawn_inv_capture_west(Bitboard board) noexcept -> Bitboard
Definition Shifts.hpp:207