From c0ff3a9794ab313448dc6fa52740a15a377f3155 Mon Sep 17 00:00:00 2001 From: dece Date: Thu, 18 Jun 2020 13:14:01 +0200 Subject: [PATCH] docker: add build/run Dockerfile The image builds Vatu and can run it on Lichess. --- .gitmodules | 3 ++ README.md | 76 ++++++++++++++++++++++++++++++++++++++++--- external/lichess-bot | 1 + res/docker/Dockerfile | 14 ++++++++ src/main.rs | 29 +++++------------ 5 files changed, 98 insertions(+), 25 deletions(-) create mode 100644 .gitmodules create mode 160000 external/lichess-bot create mode 100644 res/docker/Dockerfile diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..a78cc67 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "external/lichess-bot"] + path = external/lichess-bot + url = https://github.com/ShailChoksi/lichess-bot.git diff --git a/README.md b/README.md index ab1c788..04ec1df 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,81 @@ Vatu ==== -Dumb chess engine written in Rust for fun. Supports UCI. +Dumb chess engine written in Rust for fun. + + + +Features +-------- + +- [UCI][cpw-uci] +- Barely optimized board, position and moves representations +- Simple [negamax][cpw-negamax] for node evaluation +- [Alpha-beta][cpw-ab] search tree pruning for speeding searches + +[cpw-uci]: https://www.chessprogramming.org/UCI +[cpw-negamax]: https://www.chessprogramming.org/Negamax +[cpw-ab]: https://www.chessprogramming.org/Alpha-Beta + +Last time I checked it ran approximately at 10000 nps. + +Thanks to UCI the bot can run with most compatible software; [Cutechess][cc] has +been used for testing. + +[cc]: https://github.com/cutechess/cutechess + + + +Usage +----- + +### Build + +With Cargo: + +```bash +cargo build --release +``` + +With Docker, to avoid setting up a Rust toolchain: + +```bash +docker build -f res/docker/Dockerfile -t vatu-builder --target builder . +docker create vatu-builder # Returns a container ID. +docker cp :/src/target/release/vatu . +docker rm +docker rmi vatu-builder +``` + +### Run + +If you built it with Cargo, the binary is in `target/release`. + +```bash +./vatu +``` + +To run your own instance of the bot on Lichess (why would you do that?), create +a bot account and get an OAuth token. Then using the full Docker image: + +```bash +# Fetch the lichess-bot submodule. +git submodule update --init --recursive +# Copy the config.yml template to your own copy and modify it. +cp external/lichess-bot/config.yml.example /tmp/vatu-config/config.yml +# Build the image. Make sure config.yml is not there to not embed it! +docker build -f res/docker/Dockerfile -t vatu . +# Run with the config folder mounted at /config. +docker run -v /tmp/vatu-config:/config -ti vatu +``` TODO ---- -- Support time constraints on "go" commands. -- Precompute knight and maybe other pieces moves. -- Some Alpha-beta in terribly slow best move calculation. +- Support time constraints +- Proper unmake mechanism instead of allocating boards like there is no tomorrow +- Precompute knight some pieces moves, maybe +- Transposition table that does not actually slows search down +- Multithreading (never) diff --git a/external/lichess-bot b/external/lichess-bot new file mode 160000 index 0000000..72d5eb1 --- /dev/null +++ b/external/lichess-bot @@ -0,0 +1 @@ +Subproject commit 72d5eb1431e24935aad4cf12b86ca7af27d0491a diff --git a/res/docker/Dockerfile b/res/docker/Dockerfile new file mode 100644 index 0000000..7042241 --- /dev/null +++ b/res/docker/Dockerfile @@ -0,0 +1,14 @@ +# Build engine. +FROM rust:1 AS builder +COPY . /src +WORKDIR /src +RUN cargo build --release + +# Run on a Lichess account. +FROM python:3 +COPY . /vatu +WORKDIR /vatu/external/lichess-bot +RUN ls -l +RUN pip install -r requirements.txt +COPY --from=builder /src/target/release/vatu engines/ +ENTRYPOINT ["bash"] diff --git a/src/main.rs b/src/main.rs index d746026..0cba92e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,4 @@ -use std::process; - -use clap::{App, AppSettings, Arg, ArgMatches, SubCommand}; +use clap::{App, Arg}; pub mod analysis; pub mod board; @@ -14,27 +12,16 @@ pub mod stats; pub mod uci; fn main() { - let matches = App::new("Vatu") - .setting(AppSettings::ArgRequiredElseHelp) - .subcommand(SubCommand::with_name("uci") - .about("Start engine in UCI mode") - .arg(Arg::with_name("debug") - .help("Enable debug mode") - .short("d").long("debug").takes_value(false).required(false)) - .arg(Arg::with_name("log_file") - .help("Log file path (default is stderr)") - .long("log-file").takes_value(true).required(false))) + let args = App::new("Vatu") + .arg(Arg::with_name("debug") + .help("Enable debug mode") + .short("d").long("debug").takes_value(false).required(false)) + .arg(Arg::with_name("log_file") + .help("Log file path (default is stderr)") + .long("log-file").takes_value(true).required(false)) .get_matches(); - process::exit(match matches.subcommand() { - ("uci", Some(a)) => cmd_uci(a), - _ => 0, - }) -} - -fn cmd_uci(args: &ArgMatches) -> i32 { let debug = args.is_present("debug"); let output = args.value_of("log_file"); uci::Uci::start(debug, output); - 0 }