summaryrefslogtreecommitdiff
path: root/vroomba-analysis/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vroomba-analysis/src/main.rs')
-rw-r--r--vroomba-analysis/src/main.rs37
1 files changed, 29 insertions, 8 deletions
diff --git a/vroomba-analysis/src/main.rs b/vroomba-analysis/src/main.rs
index ca22abf..721064a 100644
--- a/vroomba-analysis/src/main.rs
+++ b/vroomba-analysis/src/main.rs
@@ -13,6 +13,9 @@ struct Opt {
/// Find out if there's a shorter path that uses the decelerate move
#[structopt(long)]
decelerate_experiment: bool,
+ /// Find out if there's a shorter path that uses the nothing move (instead of accelerate)
+ #[structopt(long)]
+ nothing_experiment: bool,
/// Path to GlobalState.json
path: PathBuf,
}
@@ -23,8 +26,9 @@ fn main() {
global_json::read_initial_state_from_global_json_file(opt.path.to_str().unwrap()).unwrap();
if opt.decelerate_experiment {
- let shortest_path_with_decelerate = shortest_path(&initial_state, false);
- let shortest_path_without_decelerate = shortest_path(&initial_state, true);
+ let shortest_path_with_decelerate = shortest_path(&initial_state, &[]);
+ let shortest_path_without_decelerate =
+ shortest_path(&initial_state, &[Command::Decelerate]);
println!("With Decelerate");
log_shortest_path(&initial_state, &shortest_path_with_decelerate);
println!("Without Decelerate");
@@ -34,24 +38,38 @@ fn main() {
} else {
println!("Same length!");
}
+ }
+ if opt.nothing_experiment {
+ let shortest_path_with = shortest_path(&initial_state, &[]);
+ let shortest_path_without = shortest_path(&initial_state, &[Command::Nothing]);
+ println!("With Nothing");
+ log_shortest_path(&initial_state, &shortest_path_with);
+ println!("Without Nothing");
+ log_shortest_path(&initial_state, &shortest_path_without);
+ if shortest_path_with.len() < shortest_path_without.len() {
+ println!("With nothing is faster!");
+ } else {
+ println!("Same length!");
+ }
} else {
- let shortest_path_actions = shortest_path(&initial_state, false);
+ let shortest_path_actions = shortest_path(&initial_state, &[]);
log_shortest_path(&initial_state, &shortest_path_actions);
}
}
fn shortest_path(
initial_state: &GameState,
- exclude_decelerate: bool,
+ blacklist: &[Command],
) -> Vec<(Position, Position, GameState, GameState, Command)> {
let shortest_path_states = astar(
initial_state,
|state| {
- let player_moves = state.valid_moves(0);
- player_moves
+ state
+ .valid_moves(0)
.into_iter()
- .filter(|player_move| *player_move != Command::UseOil)
- .filter(|player_move| !exclude_decelerate || *player_move != Command::Decelerate)
+ .filter(|player_move| {
+ *player_move != Command::UseOil && !blacklist.contains(player_move)
+ })
.map(|player_move| {
let mut state = state.clone();
state.update([player_move, Command::Decelerate]);
@@ -73,6 +91,9 @@ fn shortest_path(
let player_move = state
.valid_moves(0)
.into_iter()
+ .filter(|player_move| {
+ *player_move != Command::UseOil && !blacklist.contains(player_move)
+ })
.find(|player_move| {
let mut state = state.clone();
state.update([*player_move, Command::Decelerate]);