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.
121 lines
3.9 KiB
121 lines
3.9 KiB
mod config;
|
|
mod eval;
|
|
|
|
use chess::{Board, MoveGen};
|
|
use config::INFO;
|
|
use eval::eval_board;
|
|
use itertools::Itertools;
|
|
use rand::seq::IteratorRandom;
|
|
use std::io::{self, BufRead};
|
|
use std::process;
|
|
use std::str::FromStr;
|
|
use vampirc_uci::parse_one;
|
|
use vampirc_uci::{
|
|
MessageList, Serializable, UciMessage, UciOptionConfig, UciSearchControl, UciTimeControl,
|
|
};
|
|
|
|
use crate::config::depth;
|
|
|
|
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,
|
|
} => {
|
|
if startpos {
|
|
board = Some(Board::default())
|
|
}
|
|
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 color = board.side_to_move();
|
|
let moves = MoveGen::new_legal(&board).into_iter();
|
|
let iter = moves.map(|mov| (mov, board.make_move_new(mov)));
|
|
|
|
println!(
|
|
"bestmove {}",
|
|
iter.sorted_by(|a, b| Ord::cmp(
|
|
&eval_board(b.1, color, depth),
|
|
&eval_board(a.1, color, depth)
|
|
))
|
|
.next()
|
|
.unwrap()
|
|
.0
|
|
);
|
|
}
|
|
}
|
|
UciMessage::Stop => {
|
|
// FIXME: impl
|
|
}
|
|
UciMessage::Quit => {
|
|
process::exit(0);
|
|
}
|
|
_ => {
|
|
todo!("{}", msg.to_string())
|
|
}
|
|
}
|
|
}
|
|
}
|