summaryrefslogtreecommitdiff
path: root/src/bin/explore-config.rs
blob: 2d880d9e389ee54f9438ab10e3418a80c6a143e6 (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
use std::path::Path;

use time::PreciseTime;

use steam_powered_wyrm::game;
use steam_powered_wyrm::json;
use steam_powered_wyrm::strategy::{choose_move_with_normalized_perf, ScoreConfig};

fn main() {
    let initial_state = game::GameBoard::new(
        json::read_state_from_json_file(&Path::new(&format!("./tests/example-state.json")))
            .unwrap(),
    );
    let depth = 100;

    {
        // TODO: Player 0 seems to be winning here consistently. I
        // probably have a bug. Also, I expected this to give the same
        // result each time and it doesn't.

        let start_time = PreciseTime::now();
        let config1 = ScoreConfig::default();
        let config2 = ScoreConfig::default();
        let mut state = initial_state.clone();

        while state.outcome == game::SimulationOutcome::Continue {
            let commands = [
                choose_move_with_normalized_perf(&state, &config1, 0, depth),
                choose_move_with_normalized_perf(&state, &config2, 1, depth),
            ];
            state.simulate(commands);
        }

        println!("{:?}", state.outcome);
        println!(
            "Runtime: {}ms",
            start_time.to(PreciseTime::now()).num_milliseconds()
        );
        println!("{}", state.players[0].health());
        println!("{}", state.players[1].health());
    }
}