pub mod local;
pub mod random_bot;
pub mod mate_in_one_bot;
pub mod bong_master_bot;
pub mod eval_bot;
pub mod search_bot;
use chess::*;
pub trait Player {
fn get_move(board: Board, num_moves: usize, bot_wait_ms: u64) -> Result<ChessMove, ()>;
}
fn get_move_from_input(input: String) -> Result<ChessMove, ()> {
let input = input.trim().to_uppercase();
if input.len() < 4 { return Err(()); }
let rank = match &input[1..=1] {
"1" => Rank::First,
"2" => Rank::Second,
"3" => Rank::Third,
"4" => Rank::Fourth,
"5" => Rank::Fifth,
"6" => Rank::Sixth,
"7" => Rank::Seventh,
"8" => Rank::Eighth,
_ => return Err(())
};
let file = match &input[0..=0] {
"A" => File::A,
"B" => File::B,
"C" => File::C,
"D" => File::D,
"E" => File::E,
"F" => File::F,
"G" => File::G,
"H" => File::H,
_ => return Err(())
};
let source = Square::make_square(rank, file);
let rank = match &input[3..=3] {
"1" => Rank::First,
"2" => Rank::Second,
"3" => Rank::Third,
"4" => Rank::Fourth,
"5" => Rank::Fifth,
"6" => Rank::Sixth,
"7" => Rank::Seventh,
"8" => Rank::Eighth,
_ => return Err(())
};
let file = match &input[2..=2] {
"A" => File::A,
"B" => File::B,
"C" => File::C,
"D" => File::D,
"E" => File::E,
"F" => File::F,
"G" => File::G,
"H" => File::H,
_ => return Err(())
};
let dest = Square::make_square(rank, file);
let promotion: Option<Piece>;
if input.len() == 5 {
promotion = match &input[4..5] {
"Q" => Some(Piece::Queen),
"N" => Some(Piece::Knight),
"R" => Some(Piece::Rook),
"B" => Some(Piece::Bishop),
_ => return Err(())
};
}
else {
promotion = None;
}
Ok(ChessMove::new(
source,
dest,
promotion
))
}