make move traits/structs/etc

This commit is contained in:
c0repwn3r 2023-02-15 16:37:35 -05:00
parent 7c63ff83d0
commit 701197df3f
Signed by: core
GPG Key ID: FDBF740DADDCEECF
3 changed files with 90 additions and 1 deletions

View File

@ -105,3 +105,18 @@ impl Display for AlgebraicNotationError {
}
}
}
#[derive(Debug)]
/// Represents an error that occured making or unmaking an error.
pub enum MoveApplicationError {
}
impl Error for MoveApplicationError {}
impl Display for MoveApplicationError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
return Ok(());
/*match self {
}*/
}
}

View File

@ -35,3 +35,4 @@ pub mod board;
pub mod utils;
pub mod nn;
pub mod error;
pub mod moves;

73
bamboo/src/moves.rs Normal file
View File

@ -0,0 +1,73 @@
// Bamboo, a NNUE chess engine written in Rust.
// Copyright (C) 2023 c0repwn3r
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Traits and functions to make and unmake moves on a chessboard.
use crate::error::MoveApplicationError;
use crate::piece::{PieceColor, PieceOnBoard, PieceType};
/// Represents a move on a chessboard.
pub enum Move {
/// Represents a linear move, from A to B on the chessboard. No capture.
Linear {
/// The boardloc the piece is coming from.
from: isize,
/// The boardloc the piece is going to.
to: isize,
/// The `PieceOnBoard` struct of the piece BEFORE the move.
piece: PieceOnBoard
},
/// Represents a linear from, move A to B on the chessboard, and capturing a piece.
LinearCapture {
/// The boardloc the piece is coming from.
from: isize,
/// The boardloc the piece is going to.
to: isize,
/// The `PieceOnBoard` struct of the piece BEFORE the move.
piece: PieceOnBoard,
/// The `PieceOnBoard` struct of the piece being captured, BEFORE the move.
capturing: PieceOnBoard
},
/// Represents a castle, either white or black, kingside or queenside.
Castle {
/// The player that is performing the castle
player: PieceColor,
/// Which direction that player is castling, kingside or queenside.
queenside: bool
},
/// Represents a pawn promotion.
Promotion {
/// The pawn that is being promoted, BEFORE the move
piece: PieceOnBoard,
/// The location of the pawn, BEFORE the move
from: isize,
/// The location of the pawn, AFTER the move
to: isize,
/// The type of piece the pawn is promoting to.
becoming: PieceType
}
}
/// A trait to provide the operations of making and unmaking moves.
pub trait MoveApplicator {
/// Perform the given move on the chessboard.
/// # Errors
/// This function will error if any error occurs while applying the move.
fn make_move(&mut self, make: Move) -> Result<(), MoveApplicationError>;
/// Undo the given move on the chessboard. This will probably break if that move wasn't the last move made.
/// # Errors
/// This function will error if any error occurs while unmaking the move.
fn unmake_move(&mut self, unmake: Move) -> Result<(), MoveApplicationError>;
}