fast_tak/
game_result.rs

1use takparse::{Color, WinReason};
2
3#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
4pub enum GameResult {
5    Winner {
6        color: Color,
7        reason: Reason,
8    },
9    Draw {
10        reason: Reason,
11    },
12    #[default]
13    Ongoing,
14}
15
16#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
17pub enum Reason {
18    Road,
19    ReservesDepleted,
20    BoardFill,
21    ReversiblePlies,
22}
23
24impl From<Reason> for WinReason {
25    fn from(reason: Reason) -> Self {
26        match reason {
27            Reason::Road => Self::Road,
28            Reason::BoardFill | Reason::ReservesDepleted => Self::Flat,
29            Reason::ReversiblePlies => Self::Other,
30        }
31    }
32}
33
34pub struct Ongoing;
35
36impl TryFrom<GameResult> for takparse::GameResult {
37    type Error = Ongoing;
38
39    fn try_from(result: GameResult) -> Result<Self, Self::Error> {
40        Ok(match result {
41            GameResult::Ongoing => return Err(Ongoing),
42            GameResult::Draw { .. } => Self::Draw,
43            GameResult::Winner {
44                color: Color::White,
45                reason,
46            } => Self::White(reason.into()),
47            GameResult::Winner {
48                color: Color::Black,
49                reason,
50            } => Self::Black(reason.into()),
51        })
52    }
53}