aboutsummaryrefslogtreecommitdiff
path: root/planetwars-matchrunner/src/bin/testmatch.rs
blob: 4a9d10e4be13952649e1e62977d37fec8db47c27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use std::{env, path::PathBuf};

use planetwars_matchrunner::{docker_runner::DockerBotSpec, run_match, MatchConfig, MatchPlayer};

#[tokio::main]
async fn main() {
    let args: Vec<String> = env::args().collect();
    assert!(args.len() >= 2);
    let map_path = args[1].clone();
    _run_match(map_path).await;
}

const IMAGE: &str = "python:3.10-slim-buster";

async fn _run_match(map_path: String) {
    run_match(MatchConfig {
        map_path: PathBuf::from(map_path),
        map_name: "hex".to_string(),
        log_path: PathBuf::from("match.log"),
        players: vec![
            MatchPlayer {
                name: "a".to_string(),
                bot_spec: Box::new(DockerBotSpec {
                    image: IMAGE.to_string(),
                    // code_path: PathBuf::from("../simplebot"),
                    code_path: PathBuf::from("./bots/simplebot"),
                    argv: vec!["python".to_string(), "simplebot.py".to_string()],
                }),
            },
            MatchPlayer {
                name: "b".to_string(),
                bot_spec: Box::new(DockerBotSpec {
                    image: IMAGE.to_string(),
                    code_path: PathBuf::from("./bots/broken_bot"),
                    argv: vec!["python".to_string(), "bot.py".to_string()],
                }),
            },
        ],
    })
    .await;

    // TODO: use a joinhandle to wait for the logger to finish
    tokio::time::sleep(std::time::Duration::from_secs(1)).await;
}