1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use shakmaty::{self, File, Rank, Role, Square};
#[derive(Debug)]
pub struct PieceInBoard {
    pub square: Square,
    pub role: Role,
    pub color: shakmaty::Color,
}
impl PieceInBoard {
    
    pub fn new_king(square: shakmaty::Square, color: shakmaty::Color) -> Self {
        PieceInBoard {
            square,
            color,
            role: Role::King,
        }
    }
    
    pub fn flip_anti_diagonal(&mut self) {
        self.square = self.square.flip_anti_diagonal();
    }
    
    pub fn flip_both(&mut self) {
        self.square = self.square.flip_vertical().flip_horizontal();
    }
}
pub fn has_coordinate(s: &Square, flip: bool) -> bool {
    if (s.rank() == Rank::First || s.file() == File::A) && flip == false {
        true
    } else if (s.rank() == Rank::Eighth || s.file() == File::H) && flip == true {
        true
    } else {
        false
    }
}
#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_piece_in_board_new_king() {
        let piece = PieceInBoard::new_king(Square::new(0), shakmaty::Color::Black);
        assert_eq!(piece.role, Role::King);
    }
    #[test]
    fn test_has_coordinate() {
        let square = Square::new(0); 
        assert!(has_coordinate(&square, false));
        let square = Square::new(9); 
        assert!(!has_coordinate(&square, false));
        let square = Square::new(56); 
        assert!(has_coordinate(&square, false));
    }
    #[test]
    fn test_has_coordinate_flip() {
        let square = Square::new(0); 
        assert!(!has_coordinate(&square, true));
        let square = Square::new(7); 
        assert!(has_coordinate(&square, true));
        let square = Square::new(63); 
        assert!(has_coordinate(&square, true));
    }
}