You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
inkwell/src/main.rs

96 lines
3.2 KiB

mod config;
use chess::{Board, MoveGen, EMPTY};
use config::INFO;
use rand::seq::IteratorRandom;
use std::io::{self, BufRead};
use std::str::FromStr;
use vampirc_uci::parse_one;
use vampirc_uci::{
MessageList, Serializable, UciMessage, UciOptionConfig, UciSearchControl, UciTimeControl,
};
fn main() {
let mut rng = rand::thread_rng();
let mut board: Option<Board> = None;
for line in io::stdin().lock().lines() {
let msg: UciMessage = parse_one(&line.unwrap());
match msg {
UciMessage::Uci => {
println!(
"{}\n{}\n{}",
UciMessage::Id {
name: Some(INFO.to_name()),
author: Some(INFO.to_author())
},
UciMessage::Option(UciOptionConfig::Check {
name: "EnPassant".to_owned(),
default: Some(false)
}),
UciMessage::UciOk {}
)
}
UciMessage::IsReady => {
println!("{}", UciMessage::ReadyOk)
}
UciMessage::UciNewGame => board = Some(Board::default()),
UciMessage::Position {
startpos: _,
fen,
moves,
} => {
// NOTE: we can ignore startpos because UciNewGame already sets it to the default boardstate
if let Some(fen) = fen {
board = Some(Board::from_str(fen.as_str()).expect("Invalid FEN board"))
}
if moves.len() != 0 {
for chess_move in moves.iter() {
if let Some(goofy_board) = board {
board = Some(goofy_board.make_move_new(*chess_move));
}
}
}
}
UciMessage::Go {
time_control,
search_control,
} => {
if let Some(tc) = time_control {
match tc {
UciTimeControl::TimeLeft {
white_time,
black_time,
white_increment,
black_increment,
moves_to_go,
} => {
// FIXME: impl time-related Things
}
UciTimeControl::Infinite => {
// FIXME: impl
}
UciTimeControl::Ponder => {
// FIXME: impl
}
UciTimeControl::MoveTime(_) => {
// FIXME: impl
}
}
}
if let Some(sc) = search_control {
// FIXME: impl search control things
}
if let Some(board) = board {
let iter = MoveGen::new_legal(&board).into_iter();
println!("bestmove {}", iter.choose(&mut rng).unwrap())
}
}
_ => {
todo!()
}
}
}
}