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
use crate::Color;
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Debug)]
pub enum Size {
Tiny = 0,
Small = 1,
Medium = 2,
Big = 3,
}
impl Size {
pub const NUM: usize = 4;
pub const ALL: [Self; Self::NUM] = [Self::Tiny, Self::Small, Self::Medium, Self::Big];
}
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Debug)]
pub struct Piece {
pub color: Color,
pub size: Size,
}
impl Piece {
pub const fn new(color: Color, size: Size) -> Self {
Self { color, size }
}
}
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Debug)]
pub struct PieceSet(Vec<Piece>);
impl PieceSet {
pub fn from_vec(vec: Vec<Piece>) -> Self {
Self(vec)
}
pub fn from_slice(slice: &[Piece]) -> Self {
Self(slice.to_vec())
}
pub fn none() -> Self {
Self(Vec::new())
}
pub fn peek(&self) -> Option<&Piece> {
self.0.last()
}
pub fn pop(&mut self) -> Option<Piece> {
self.0.pop()
}
}