Skip to main content

hexo_engine/
types.rs

1use std::fmt;
2
3/// Axial coordinate (q, r) on the hex grid.
4pub type Coord = (i32, i32);
5
6/// The 6 neighbor directions in axial coordinates.
7pub const HEX_DIRS: [Coord; 6] = [
8    (1, 0),
9    (-1, 0),
10    (0, 1),
11    (0, -1),
12    (1, -1),
13    (-1, 1),
14];
15
16/// The 3 win-detection axes (one direction per axis).
17pub const WIN_AXES: [Coord; 3] = [
18    (1, 0),
19    (0, 1),
20    (1, -1),
21];
22
23/// A player in the game.
24#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
25pub enum Player {
26    P1,
27    P2,
28}
29
30impl Player {
31    /// Returns the opposing player.
32    pub fn opponent(self) -> Self {
33        match self {
34            Player::P1 => Player::P2,
35            Player::P2 => Player::P1,
36        }
37    }
38}
39
40impl fmt::Display for Player {
41    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42        match self {
43            Player::P1 => write!(f, "P1"),
44            Player::P2 => write!(f, "P2"),
45        }
46    }
47}