use std::{str::Chars, fmt::Display}; use crate::{square::Square, bitboard::BitboardFns, board::piece::Piece}; #[derive(Debug, Clone, PartialEq, Eq, Copy)] pub enum MoveKind { Quiet, Capture, Castle, EnPassant, DoublePush, Promotion(Piece), } #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct Move { pub source: Square, pub target: Square, pub kind: MoveKind, } impl Move { pub fn print(&self) { let bb = self.source.to_bitboard() | self.target.to_bitboard(); bb.print(format!("{:?}", self).as_str()); } /// Tactical move is a move that changes material score pub fn is_tactical(&self) -> bool { matches!(self.kind, MoveKind::Capture | MoveKind::EnPassant) } pub fn from_notation(mut notation: Chars) -> Self { let source = Square::from_notation(&mut notation).unwrap(); let target = Square::from_notation(&mut notation).unwrap(); Move { source, target, kind: MoveKind::Quiet } } } impl Display for Move { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}{}", self.source, self.target) } }