check_buddy_core/moves/
position_move.rs

1#[derive(Default, Clone, Copy, Debug)]
2pub struct PositionMove {
3    pub from: Position,
4    pub to: Position,
5    pub en_passant: bool,
6    pub promotion: bool,
7}
8
9impl PositionMove {
10    pub fn new(from: Position, to: Position) -> Self {
11        Self {
12            from,
13            to,
14            ..Default::default()
15        }
16    }
17}
18
19pub type Position = [usize; 2];
20
21pub enum Direction {
22    North,
23    East,
24    South,
25    West,
26    NorthEast,
27    SouthEast,
28    SouthWest,
29    NorthWest,
30}
31
32pub const DIRECTION_OFFSETS: [i32; 8] = [8, 1, -8, -1, 9, -7, -9, 7];
33pub const KNIGHT_DIRECTION_OFFSETS: [[i32; 2]; 8] = [
34    //[Y,X]
35    [1, -2],
36    [2, -1],
37    [2, 1],
38    [1, 2],
39    [-1, 2],
40    [-2, 1],
41    [-2, -1],
42    [-1, -2],
43];
44
45impl Direction {
46    pub fn from(index: usize) -> Self {
47        match index {
48            0 => Direction::North,     // 8
49            1 => Direction::East,      // 1
50            2 => Direction::South,     // -8
51            3 => Direction::West,      //-1
52            4 => Direction::NorthEast, // 9
53            5 => Direction::SouthEast, // -7
54            6 => Direction::SouthWest, // -9
55            7 => Direction::NorthWest, //7
56            _ => unreachable!(),
57        }
58    }
59}