mod bot;
mod evaluation;
mod physical;
mod tui;
use bot::Ocelot;
use physical::*;
use std::env;
fn main() {
let mut depth = 5;
let args: Vec<_> = env::args().collect();
for arg in args.iter() {
match arg.parse::<i32>() {
Ok(num) => {
depth = num;
break;
}
Err(_) => continue,
}
}
if args.contains(&String::from("--help")) {
help();
} else if args.contains(&String::from("--demo")) {
demo(depth);
} else if args.contains(&String::from("--tui")) {
tui::mainloop(depth);
} else {
uci(depth);
}
}
fn uci(depth: i32) {
let b: Board = Default::default();
let mut engine = Ocelot::new(&b, depth, 10.0);
engine.uci_loop();
}
fn demo(depth: i32) {
let b: Board = Default::default();
println!("Depth: {depth}");
let mut white_engine = Ocelot::new(&b, depth, 4.0);
let mut black_engine = Ocelot::new(&b, depth, 4.0);
println!(
"This demo will play a game between equally-strengthed White and Black players until you kill the program. It gets chaotic and a little illegal!"
);
loop {
println!("Round {}", white_engine.board.round);
let white_move = white_engine.safe_best_move();
println!("White plays {white_move}");
white_engine.perform_on_self(white_move.duplicate());
black_engine.perform_on_self(white_move);
println!("White in check: {}", b.is_check(board::Color::White));
let black_move = black_engine.safe_best_move();
println!("Black plays {black_move}");
white_engine.perform_on_self(black_move.duplicate());
black_engine.perform_on_self(black_move);
println!("Black in check: {}", b.is_check(board::Color::Black));
}
}
fn help() {
println!(
"ocelot-chess is a simple chess engine written from scratch with no dependencies. Flags:
--tui - starts the built-in TUI.
--demo - runs a chaotic demo of two Ocelots playing against each other.
--help - prints this message.
If no flags are supplied, the engine starts in UCI mode.
You can supply a number as an argument and that will be the engine's depth.
"
);
}