summaryrefslogtreecommitdiff
path: root/vroomba-analysis/src/main.rs
blob: a1145b735b6d5670d517641f67fcf51023f7dc3b (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use pathfinding::prelude::*;
use std::path::PathBuf;
use structopt::StructOpt;
use vroomba::command::Command;
use vroomba::consts::*;
use vroomba::global_json;
use vroomba::state::{GameState, GameStatus};

#[derive(StructOpt, Debug)]
#[structopt(name = "vroomba-analysis")]
struct Opt {
    /// Path to GlobalState.json
    path: PathBuf,
}

fn main() {
    let opt = Opt::from_args();
    let initial_node = Node {
        state: global_json::read_initial_state_from_global_json_file(opt.path.to_str().unwrap())
            .unwrap(),
        //last_command: Command::Nothing,
    };

    let shortest_path = astar(
        &initial_node,
        |node| {
            let player_moves = node.state.valid_moves(0);
            player_moves
                .into_iter()
                .map(|player_move| {
                    let mut state = node.state.clone();
                    state.update([player_move, Command::Decelerate]);
                    (
                        Node {
                            state,
                            //last_command: player_move,
                        },
                        1,
                    )
                })
                .collect::<Vec<_>>()
        },
        |node| (WIDTH - node.state.players[0].position.x) / SPEED_BOOST,
        |node| node.state.status != GameStatus::Continue,
    )
    .unwrap();

    // println!(
    //     "{:?}",
    //     shortest_path
    //         .0
    //         .into_iter()
    //         .map(|node| node.last_command)
    //         .collect::<Vec<_>>()
    // );
    println!("{}", shortest_path.1);
}

#[derive(Debug, Clone, Hash, PartialEq, Eq)]
struct Node {
    state: GameState,
    //last_command: Command,
}