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
use thiserror::Error;

/// The error type for SFEN serialize/deserialize operations.
#[derive(Error, Debug, PartialEq, Eq)]
pub enum SfenError {
    #[error("data fields are missing")]
    MissingDataFields,

    #[error("an illegal piece notation is found")]
    IllegalPieceType,

    #[error("the side to move needs to be black or white")]
    IllegalSideToMove,

    #[error("an illegal move count notation is found")]
    IllegalMoveCount(#[from] std::num::ParseIntError),

    #[error("an illegal move notation is found")]
    IllegalMove,

    #[error("an illegal board state notation is found")]
    IllegalBoardState,
}

/// Represents an error occurred during making a move.
#[derive(Error, Debug, PartialEq, Eq)]
pub enum MoveError {
    #[error("the king is in check")]
    InCheck,

    #[error("nifu detected")]
    Nifu,

    #[error("uchifuzume detected")]
    Uchifuzume,

    #[error("perpetual check detected")]
    PerpetualCheckWin,

    #[error("perpetual check detected")]
    PerpetualCheckLose,

    #[error("not your turn")]
    EnemysTurn,

    #[error("the piece can not move anymor")]
    NonMovablePiece,

    #[error("the move is inconsistent with the current position: {0}")]
    Inconsistent(&'static str),

    #[error("repetition detected")]
    Repetition,
}