backgammon_engine 0.1.0

Backgammon engine in Rust: state representation, legal move generation, and deterministic afterstate transitions for agent/RL development.
Documentation
use std::fmt;

#[derive(PartialEq, Copy, Clone, Debug)]
pub enum Player {
    White,
    Black,
}
/// Black moves from left ro right and white moves from right to left on the board array.
/// Hence for black moves the invariant holds: from < to and for white moves to < from.
/// And for all white moves the invariant holds: to < from.
#[derive(Copy, Clone, Debug)]
pub struct BackgammonMove {
    pub player: Player,
    pub from: i32,
    pub to: i32,
}

impl BackgammonMove {
    pub fn new(player: Player, from: i32, to: i32) -> BackgammonMove {
        BackgammonMove { player, from, to }
    }
}

impl PartialEq for BackgammonMove {
    fn eq(&self, other: &Self) -> bool {
        self.from == other.from && self.to == other.to && self.player == other.player
    }
}

impl fmt::Display for BackgammonMove {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(
            f,
            "{}: from {} to {}",
            match self.player {
                Player::White => "White",
                Player::Black => "Black",
            },
            self.from,
            self.to
        )
    }
}