From 91c144969f6dd2daa7d9fb2e5d59059ecd556b79 Mon Sep 17 00:00:00 2001 From: Justin Wernick Date: Sat, 18 Apr 2020 23:25:16 +0200 Subject: Optimimze to have a shortest path that actually completes --- vroomba-analysis/src/main.rs | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'vroomba-analysis') diff --git a/vroomba-analysis/src/main.rs b/vroomba-analysis/src/main.rs index e1d244b..3abcfc6 100644 --- a/vroomba-analysis/src/main.rs +++ b/vroomba-analysis/src/main.rs @@ -1,4 +1,4 @@ -use pathfinding::directed::astar; +use pathfinding::prelude::*; use std::path::PathBuf; use structopt::StructOpt; use vroomba::command::Command; @@ -18,10 +18,10 @@ fn main() { let initial_node = Node { state: global_json::read_initial_state_from_global_json_file(opt.path.to_str().unwrap()) .unwrap(), - last_command: Command::Nothing, + //last_command: Command::Nothing, }; - let shortest_path = astar::astar( + let shortest_path = astar( &initial_node, |node| { let player_moves = node.state.valid_moves(0); @@ -29,11 +29,11 @@ fn main() { .into_iter() .map(|player_move| { let mut state = node.state.clone(); - state.update([player_move, Command::Accelerate]); + state.update([player_move, Command::Decelerate]); ( Node { state, - last_command: player_move, + //last_command: player_move, }, 1, ) @@ -45,19 +45,20 @@ fn main() { ) .unwrap(); - println!( - "{:?}", - shortest_path - .0 - .into_iter() - .map(|node| node.last_command) - .collect::>() - ); + // println!( + // "{:?}", + // shortest_path + // .0 + // .into_iter() + // .map(|node| node.last_command) + // .collect::>() + // ); + println!("{:?}", shortest_path.0); println!("{}", shortest_path.1); } #[derive(Debug, Clone, Hash, PartialEq, Eq)] struct Node { state: GameState, - last_command: Command, + //last_command: Command, } -- cgit v1.2.3