Files
zeal/src/game.rs

101 lines
2.1 KiB
Rust

use crate::{
board::{Board, Color},
fen::from_fen,
};
use String as FenError;
#[derive(Debug, PartialEq, Eq)]
pub struct Game {
pub board: Board,
}
impl Game {
pub const fn new() -> Self {
Self {
board: Board::new(),
}
}
pub fn new_from_fen(fen: &str) -> Result<Self, FenError> {
from_fen(fen)
}
pub const fn run(&self) {
Board::new();
}
}
impl Default for Game {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub struct State {
side_to_move: Color,
castling_ability: u8,
en_passant_target_square: Option<u8>,
halfmove_clock: u8,
fullmove_counter: u8,
}
impl State {
pub const fn new() -> Self {
Self {
side_to_move: Color::White,
castling_ability: 0b1111,
en_passant_target_square: None,
halfmove_clock: 0,
fullmove_counter: 1,
}
}
pub const fn load_state(
side_to_move: Color,
castling_ability: u8,
en_passant_target_square: Option<u8>,
halfmove_clock: u8,
fullmove_counter: u8,
) -> Self {
Self {
side_to_move,
castling_ability,
en_passant_target_square,
halfmove_clock,
fullmove_counter,
}
}
pub const fn get_en_passant_target_square(&self) -> Option<u8> {
self.en_passant_target_square
}
pub const fn get_castling_ability(&self) -> u8 {
self.castling_ability
}
}
use std::fmt;
impl fmt::Display for State {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f,
"side_to_move: {:?}\ncastling_ability: {:b}\nen_passant_target_square: {:b}\nhalfmove_clock: {}\nfullmove_counter: {}\n",
self.side_to_move, self.castling_ability, 1_u64 << self.en_passant_target_square.unwrap_or(0), self.halfmove_clock, self.fullmove_counter)
}
}
impl Default for State {
fn default() -> Self {
Self::new()
}
}
pub enum CastlingRights {
Short,
Long,
Both,
None,
}