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