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 = 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!() } } } }