Skip to content

Commit

Permalink
patch path on timeout instead of recalculating everything
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-1 committed Dec 26, 2024
1 parent 344834c commit 33e1a13
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 90 deletions.
6 changes: 5 additions & 1 deletion azalea/benches/pathfinder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,16 @@ fn run_pathfinder_benchmark(
azalea::pathfinder::call_successors_fn(&cached_world, &mining_cache, successors_fn, pos)
};

let astar::Path { movements, partial } = a_star(
let astar::Path {
movements,
is_partial: partial,
} = a_star(
RelBlockPos::get_origin(origin),
|n| goal.heuristic(n.apply(origin)),
successors,
|n| goal.success(n.apply(origin)),
PathfinderTimeout::Time(Duration::MAX),
PathfinderTimeout::Time(Duration::MAX),
);

assert!(!partial);
Expand Down
31 changes: 31 additions & 0 deletions azalea/examples/testbot/commands/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use azalea::{
brigadier::prelude::*,
entity::{LookDirection, Position},
interact::HitResultComponent,
pathfinder::{ExecutingPath, Pathfinder},
world::MinecraftEntityId,
BlockPos,
};
Expand Down Expand Up @@ -117,4 +118,34 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
1
})),
)));

commands.register(literal("pathfinderstate").executes(|ctx: &Ctx| {
let source = ctx.source.lock();
let pathfinder = source.bot.get_component::<Pathfinder>();
let Some(pathfinder) = pathfinder else {
source.reply("I don't have the Pathfinder ocmponent");
return 1;
};
source.reply(&format!(
"pathfinder.is_calculating: {}",
pathfinder.is_calculating
));

let executing_path = source.bot.get_component::<ExecutingPath>();
let Some(executing_path) = executing_path else {
source.reply("I'm not executing a path");
return 1;
};
source.reply(&format!(
"is_path_partial: {}, path.len: {}, queued_path.len: {}",
executing_path.is_path_partial,
executing_path.path.len(),
if let Some(queued) = executing_path.queued_path {
queued.len().to_string()
} else {
"n/a".to_string()
},
));
1
}));
}
6 changes: 3 additions & 3 deletions azalea/src/pathfinder/astar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ where
P: Eq + Hash + Copy + Debug,
{
pub movements: Vec<Movement<P, M>>,
pub partial: bool,
pub is_partial: bool,
}

// used for better results when timing out
Expand Down Expand Up @@ -90,7 +90,7 @@ where

return Path {
movements: reconstruct_path(nodes, index),
partial: false,
is_partial: false,
};
}

Expand Down Expand Up @@ -190,7 +190,7 @@ where

Path {
movements: reconstruct_path(nodes, best_path),
partial: true,
is_partial: true,
}
}

Expand Down
Loading

0 comments on commit 33e1a13

Please sign in to comment.