BenBot 1.7.5
A chess engine
Loading...
Searching...
No Matches
Fills.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 starting) noexcept -> Bitboard;
38
40[[nodiscard, gnu::const]] constexpr auto south(Bitboard starting) noexcept -> Bitboard;
41
43[[nodiscard, gnu::const]] constexpr auto east(Bitboard starting) noexcept -> Bitboard;
44
46[[nodiscard, gnu::const]] constexpr auto west(Bitboard starting) noexcept -> Bitboard;
47
49[[nodiscard, gnu::const]] constexpr auto northeast(Bitboard starting) noexcept -> Bitboard;
50
52[[nodiscard, gnu::const]] constexpr auto southeast(Bitboard starting) noexcept -> Bitboard;
53
55[[nodiscard, gnu::const]] constexpr auto northwest(Bitboard starting) noexcept -> Bitboard;
56
58[[nodiscard, gnu::const]] constexpr auto southwest(Bitboard starting) noexcept -> Bitboard;
59
64[[nodiscard, gnu::const]] constexpr auto file(Bitboard starting) noexcept -> Bitboard;
65
70[[nodiscard, gnu::const]] constexpr auto rank(Bitboard starting) noexcept -> Bitboard;
71
76[[nodiscard, gnu::const]] constexpr auto diagonal(Bitboard starting) noexcept -> Bitboard;
77
82[[nodiscard, gnu::const]] constexpr auto antidiagonal(Bitboard starting) noexcept -> Bitboard;
83
85template <Color Side>
86[[nodiscard, gnu::const]] constexpr auto pawn_front(Bitboard starting) noexcept -> Bitboard;
87
89template <Color Side>
90[[nodiscard, gnu::const]] constexpr auto pawn_rear(Bitboard starting) noexcept -> Bitboard;
91
93
94/*
95 ___ ,--,
96 ,---, ,--.'|_ ,--, ,--.'|
97 ,---.'| | | :,' ,--.'| | | :
98 | | : : : ' : | |, : : ' .--.--.
99 | | | ,---. .;__,' / ,--.--. `--'_ | ' | / / '
100 ,--.__| | / \ | | | / \ ,' ,'| ' | | | : /`./
101 / ,' | / / |:__,'| : .--. .-. | ' | | | | : | : ;_
102. ' / |. ' / | ' : |__ \__\/: . . | | : ' : |__ \ \ `.
103' ; |: |' ; /| | | '.'| ," .--.; | ' : |__ | | '.'| `----. \
104| | '/ '' | / | ; : ;/ / ,. | | | '.'|; : ;/ /`--' /__ ___ ___
105| : :|| : | | , /; : .' \; : ;| , /'--'. / .\/ .\/ .\
106 \ \ / \ \ / ---`-' | , .-./| , / ---`-' `--'---'\ ; \ ; \ ; |
107 `----' `----' `--`---' ---`-' `--" `--" `--"
108
109 */
110
111constexpr auto north(Bitboard starting) noexcept -> Bitboard
112{
113 starting |= (starting << 8uz);
114 starting |= (starting << 16uz);
115 starting |= (starting << 32uz);
116
117 return starting;
118}
119
120constexpr auto south(Bitboard starting) noexcept -> Bitboard
121{
122 starting |= (starting >> 8uz);
123 starting |= (starting >> 16uz);
124 starting |= (starting >> 32uz);
125
126 return starting;
127}
128
129constexpr auto east(Bitboard starting) noexcept -> Bitboard
130{
131 constexpr auto notAFile = masks::files::A.inverse();
132
133 constexpr auto mask1 = notAFile & (notAFile << 1uz);
134 constexpr auto mask2 = mask1 & (mask1 << 2uz);
135
136 starting |= notAFile & (starting << 1uz);
137 starting |= mask1 & (starting << 2uz);
138 starting |= mask2 & (starting << 4uz);
139
140 return starting;
141}
142
143constexpr auto west(Bitboard starting) noexcept -> Bitboard
144{
145 constexpr auto notHFile = masks::files::H.inverse();
146
147 constexpr auto mask1 = notHFile & (notHFile >> 1uz);
148 constexpr auto mask2 = mask1 & (mask1 >> 2uz);
149
150 starting |= notHFile & (starting >> 1uz);
151 starting |= mask1 & (starting >> 2uz);
152 starting |= mask2 & (starting >> 4uz);
153
154 return starting;
155}
156
157constexpr auto northeast(Bitboard starting) noexcept -> Bitboard
158{
159 constexpr auto notAFile = masks::files::A.inverse();
160
161 constexpr auto mask1 = notAFile & (notAFile << 9uz);
162 constexpr auto mask2 = mask1 & (mask1 << 18uz);
163
164 starting |= notAFile & (starting << 9uz);
165 starting |= mask1 & (starting << 18uz);
166 starting |= mask2 & (starting << 36uz);
167
168 return starting;
169}
170
171constexpr auto southeast(Bitboard starting) noexcept -> Bitboard
172{
173 constexpr auto notAFile = masks::files::A.inverse();
174
175 constexpr auto mask1 = notAFile & (notAFile >> 7uz);
176 constexpr auto mask2 = mask1 & (mask1 >> 14uz);
177
178 starting |= notAFile & (starting >> 7uz);
179 starting |= mask1 & (starting >> 14uz);
180 starting |= mask2 & (starting >> 28uz);
181
182 return starting;
183}
184
185constexpr auto northwest(Bitboard starting) noexcept -> Bitboard
186{
187 constexpr auto notHFile = masks::files::H.inverse();
188
189 constexpr auto mask1 = notHFile & (notHFile << 7uz);
190 constexpr auto mask2 = mask1 & (mask1 << 14uz);
191
192 starting |= notHFile & (starting << 7uz);
193 starting |= mask1 & (starting << 14uz);
194 starting |= mask2 & (starting << 28uz);
195
196 return starting;
197}
198
199constexpr auto southwest(Bitboard starting) noexcept -> Bitboard
200{
201 constexpr auto notHFile = masks::files::H.inverse();
202
203 constexpr auto mask1 = notHFile & (notHFile >> 9uz);
204 constexpr auto mask2 = mask1 & (mask1 >> 18uz);
205
206 starting |= notHFile & (starting >> 9uz);
207 starting |= mask1 & (starting >> 18uz);
208 starting |= mask2 & (starting >> 36uz);
209
210 return starting;
211}
212
213constexpr auto file(const Bitboard starting) noexcept -> Bitboard
214{
215 return north(starting) | south(starting);
216}
217
218constexpr auto rank(const Bitboard starting) noexcept -> Bitboard
219{
220 return east(starting) | west(starting);
221}
222
223constexpr auto diagonal(const Bitboard starting) noexcept -> Bitboard
224{
225 return northeast(starting) | southwest(starting);
226}
227
228constexpr auto antidiagonal(const Bitboard starting) noexcept -> Bitboard
229{
230 return northwest(starting) | southeast(starting);
231}
232
233template <Color Side>
234constexpr auto pawn_front(const Bitboard starting) noexcept -> Bitboard
235{
236 if constexpr (Side == Color::White)
237 return north(starting);
238 else
239 return south(starting);
240}
241
242template <Color Side>
243constexpr auto pawn_rear(const Bitboard starting) noexcept -> Bitboard
244{
245 if constexpr (Side == Color::White)
246 return south(starting);
247 else
248 return north(starting);
249}
250
251} // namespace chess::board::fills
constexpr auto northeast(Bitboard starting) noexcept -> Bitboard
Definition Fills.hpp:157
constexpr auto pawn_rear(Bitboard starting) noexcept -> Bitboard
Definition Fills.hpp:243
constexpr auto west(Bitboard starting) noexcept -> Bitboard
Definition Fills.hpp:143
constexpr auto southeast(Bitboard starting) noexcept -> Bitboard
Definition Fills.hpp:171
constexpr auto northwest(Bitboard starting) noexcept -> Bitboard
Definition Fills.hpp:185
constexpr auto file(Bitboard starting) noexcept -> Bitboard
Definition Fills.hpp:213
constexpr auto east(Bitboard starting) noexcept -> Bitboard
Definition Fills.hpp:129
constexpr auto south(Bitboard starting) noexcept -> Bitboard
Definition Fills.hpp:120
constexpr auto north(Bitboard starting) noexcept -> Bitboard
Definition Fills.hpp:111
constexpr auto antidiagonal(Bitboard starting) noexcept -> Bitboard
Definition Fills.hpp:228
constexpr auto pawn_front(Bitboard starting) noexcept -> Bitboard
Definition Fills.hpp:234
constexpr auto diagonal(Bitboard starting) noexcept -> Bitboard
Definition Fills.hpp:223
constexpr auto rank(Bitboard starting) noexcept -> Bitboard
Definition Fills.hpp:218
constexpr auto southwest(Bitboard starting) noexcept -> Bitboard
Definition Fills.hpp:199