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

127 lines
4.1 KiB

mod config;
mod eval;
mod piece_tables;
mod piece_values;
use chess::Board;
use config::INFO;
use eval::{Board as EvalBoard, Evaluator};
use minimax::{IterativeOptions, ParallelOptions, ParallelSearch, Strategy};
use std::io::{self, BufRead};
use std::process;
use std::str::FromStr;
use vampirc_uci::parse_one;
use vampirc_uci::{UciMessage, UciOptionConfig, UciTimeControl};
use crate::config::DEPTH;
fn main() {
let mut board: Option<Board> = None;
let mut move_history: Vec<Board> = vec![];
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());
move_history = vec![];
}
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.is_empty() {
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 mut strat = ParallelSearch::new(
Evaluator::default(),
IterativeOptions::new().verbose(),
ParallelOptions::new().with_background_pondering(),
);
strat.set_max_depth(DEPTH);
let mov = strat
.choose_move(&EvalBoard {
current_board: board,
board_history: move_history.clone(),
last_move: Default::default(),
})
.unwrap();
println!("bestmove {}", mov);
}
}
UciMessage::Stop => {
// FIXME: impl
}
UciMessage::Quit => {
process::exit(0);
}
_ => {
todo!("{}", msg.to_string())
}
}
}
}