Use a Direction enum for Square deltas

Currently the NORTH/WEST/SOUTH/EAST values are of type Square, but conceptually they are not squares but directions. This patch separates these values into a Direction enum and overloads addition and subtraction to allow adding a Square to a Direction (to get a new Square).

I have also slightly trimmed the possible overloadings to improve type safety. For example, it would normally not make sense to add a Color to a Color or a Piece to a Piece, or to multiply or divide them by an integer. It would also normally not make sense to add a Square to a Square.

This is a non-functional change.
This commit is contained in:
syzygy1
2017-12-04 17:52:31 +01:00
committed by Marco Costalba
parent 2acda1fde3
commit 822695d4d3
10 changed files with 81 additions and 63 deletions

View File

@@ -152,7 +152,7 @@ inline Bitboard file_bb(Square s) {
/// shift() moves a bitboard one step along direction D. Mainly for pawns
template<Square D>
template<Direction D>
constexpr Bitboard shift(Bitboard b) {
return D == NORTH ? b << 8 : D == SOUTH ? b >> 8
: D == NORTH_EAST ? (b & ~FileHBB) << 9 : D == SOUTH_EAST ? (b & ~FileHBB) >> 7