Skip to main content

thud/
piece.rs

1#[cfg(feature = "serialize")]
2use serde::{Deserialize, Serialize};
3
4/// A piece on the Thud [`Board`](struct.Board.html)
5///
6/// **Note**: Empty squares are modelled as `Piece`s too, to avoid the horror of `Option<Piece>`
7/// everywhere.
8#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
9#[derive(Debug, PartialEq, Copy, Clone)]
10pub enum Piece {
11    Dwarf,
12    Troll,
13    Thudstone,
14    Empty,
15}
16
17impl Default for Piece {
18    fn default() -> Self {
19        Self::Empty
20    }
21}
22
23#[cfg(feature = "ffi")]
24impl Piece {
25    pub fn into_int(&self) -> usize {
26        match self {
27            Piece::Empty => 0,
28            Piece::Dwarf => 1,
29            Piece::Troll => 2,
30            Piece::Thudstone => 3,
31        }
32    }
33}