utilities.pathfinding module

Module containing pathfinding utilities.

class utilities.pathfinding.Pathfinding

Bases: object

static find_path(world, start, goal, tolerance=0)

Implements the A* algorithm to find a path from the start to the goal.

Parameters:
  • world – The world
  • start – The starting position
  • goal – The goal position
  • tolerance – The heuristic tolerance distance (e.g., at a tolerance of 0 the path should go to the exact goal. At a tolerance of 1 the path should end within 1 cell distance to the goal)
static get_neighbours(world, position)

Get all neighbours of a given position (cell).

Parameters:
  • world – The world
  • position – The given position (cell)
static heuristic(start, goal)

Calculate the heuristic cost to get from start to the goal.

Parameters:
  • start – The starting position
  • goal – The goal position
static reconstruct_path(backtrack, goal)

Reconstruct the path from the start to the goal, based on the backtrack path created by the find_path method.

Parameters:
  • backtrack – The backtrack path (a list of positions)
  • goal – The goal position
Returns:

The path