-
Notifications
You must be signed in to change notification settings - Fork 1
Directions
Non-sliding pieces are pieces such as the king, knights, and pawns. The moves of these pieces are usually the easiest to calculate because other pieces around them do not affect how far each piece can move. Such as a queen, that can only move from A1 to A8 if there are no blocking pieces in between.
One can utilize a set of directions or a specified number to bitshift to quickly and effectively calculate the moves of non-sliding pieces. To simulate a white-pawn move straight forward one can bitshift the pawn bitboard by 8 to the left. The same goes for both the king and the knight
A pawn can move in four different directions.
2
3 1 4
P
A king can move in 8 directions
1 2 3
8 K 4
7 6 5
And a knight can also move in 8 directions:
2 3
1 4
N
8 5
7 6
Because these moves are not affected by blocking pieces the same as a sliding piece, we can find these moves every time using the exact same bit-shifting numbers.
Here are the directions or amount to bitshift to simulate a given position for a king and pawns
northwest north northeast
+9 +8 +7
\ | /
west 1 <- 0 -> -1 east
/ | \
-7 -8 -9
southwest south southeast
Here are the directions for a knight: The naming represents a move in each direction -> North north east, would be two spaces up and one to the right
noNoWe noNoEa
+17 +15
| |
noWeWe +10__| |__+6 noEaEa
\ /
>0<
__ / \ __
soWeWe -6 | | -10 soEaEa
| |
-15 -17
soSoWe soSoEa
Bit shifting to the left using any of these directions will give us the new position given the current position.