38 uint8_t
const df_pinned_horizontally = 0 << 3;
39 uint8_t
const df_pinned_vertically = 1 << 3;
40 uint8_t
const df_pinned_slashy = 2 << 3;
41 uint8_t
const df_pinned_backslashy = 3 << 3;
42 uint8_t
const df_pinned_mask = 3 << 3;
52 bool is_horizontal(
void)
const {
return shift == 1; }
53 bool matches(
Type const& type)
const {
return (type() & flags) == (
type_mask & flags); }
56 BitBoard from(
Index const& index)
const {
return direction_table[((
static_cast<int>(index())) << 3) + this->index]; }
58 friend Index operator+(
Index const& index,
Direction const& direction) {
Index result(index); result += direction.offset;
return result; }
59 friend Index operator+(
Direction const& direction,
Index const& index) {
Index result(index); result += direction.offset;
return result; }
60 friend Index operator-(
Index const& index,
Direction const& direction) {
Index result(index); result -= direction.offset;
return result; }
61 friend Index operator-(
Direction const& direction,
Index const& index) {
Index result(index); result -= direction.offset;
return result; }
67 Direction const south_west = { 9, -9, 0, df_bishop_mover | df_pinned_slashy };
68 Direction const south = { 8, -8, 1, df_rook_mover | df_pinned_vertically };
69 Direction const south_east = { 7, -7, 2, df_bishop_mover | df_pinned_backslashy };
70 Direction const west = { 1, -1, 3, df_rook_mover | df_pinned_horizontally };
71 Direction const east = { 1, 1, 4, df_rook_mover | df_pinned_horizontally };
72 Direction const north_west = { 7, 7, 5, df_bishop_mover | df_pinned_backslashy };
73 Direction const north = { 8, 8, 6, df_rook_mover | df_pinned_vertically };
74 Direction const north_east = { 9, 9, 7, df_bishop_mover | df_pinned_slashy };
80 return from_to_table[(
from() << 6) | to()];
83 extern uint8_t
const direction_index_table[256];
87 uint8_t from_bits(
from());
88 uint8_t to_bits(to());
89 uint8_t from_col_bits = from_bits & 0x07;
91 uint8_t from_row_bits = from_bits & 0x70;
92 uint8_t to_col_bits = to_bits & 0x07;
94 uint8_t to_row_bits = to_bits & 0x70;
95 uint8_t row_diff = to_row_bits - from_row_bits;
96 uint8_t col_diff = (to_col_bits - from_col_bits) & 0x0f;
97 static Direction const directions[9] = { south_west, south, south_east, west, east, north_west, north, north_east, {0,0,0,0} };
98 return directions[direction_index_table[row_diff | col_diff]];
103 #endif // DIRECTION_H A namespace for all chess related objects that are not related to the GUI.
This file contains the declaration of class Type.
The POD base type of class Flags.
The POD base type of class BitBoard.
uint8_t const bishop_bits
The underlaying integral value of type& #39;bishop'.
uint8_t M_bits
0TKNQ000, T=can move two squares, K=can take king side, N=is not blocked, Q=can take queen side...
A one-boolean-per-square chessboard.
The index of a chess square.
This file contains the declaration of class BitBoard.
BitBoard from(Index const& index) const
Return a BitBoard with all squares in this direction.
uint8_t const type_mask
A mask for the bits used for the type of a piece.
This file contains the declaration of class Flags.
uint8_t const rook_bits
The underlaying integral value of type& #39;rook'.