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
78
79
80
81
82
83
84
85
86
extern crate wasm_bindgen;
use wasm_bindgen::prelude::*;

use std::fmt::{Display};

/// Move/Jump, for use in Move
#[wasm_bindgen]
#[repr(u8)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum MoveType {
    Move = 0,
    Jump = 1,
}

/// Black/White
#[wasm_bindgen]
#[repr(u8)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Team {
    Black = 0,
    White = 1,
}

impl Team {
    /// Get opposing team
    pub fn opponent(&self) -> Team{
        match self {
            Team::White => Team::Black,
            Team::Black => Team::White,
        }
    }
}

impl Display for Team {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        match self {
            Team::White => write!(f, "{}", 'W'),
            Team::Black => write!(f, "{}", 'B'),
        }
    }
}

/// Man/King
#[wasm_bindgen]
#[repr(u8)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Strength {
    Man = 0,
    King = 1
}

/// Model board square as Empty/Occupied/Unplayable
#[wasm_bindgen]
#[repr(u8)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum SquareState {
    Empty = 0,
    Occupied = 1,
    Unplayable = 2
}

impl Display for SquareState {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        match self {
            SquareState::Empty => write!(f, "{}", 'E'),
            SquareState::Occupied => write!(f, "{}", 'O'),
            SquareState::Unplayable => write!(f, "{}", 'U'),
        }
    }
}

/// Possible outcomes of trying to move
#[wasm_bindgen]
#[repr(u8)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Moveable {
    Allowed = 0,
    UnoccupiedSrc = 1,
    OccupiedDest = 2,
    OutOfBounds = 3,
    Unplayable = 4,
    WrongTeamSrc = 5,
    IllegalTrajectory = 6,
    NoJumpablePiece = 7,
    JumpingSameTeam = 8,
}