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::>() }, |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::>() // ); println!("{}", shortest_path.1); } #[derive(Debug, Clone, Hash, PartialEq, Eq)] struct Node { state: GameState, //last_command: Command, }