Skip to content

Ruk33/astar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

astar / pathfinding
    this is a very simple path finding function. from two points, it will
    calculate the next step to walk that's closer to the end goal.

    this is intended to be extremely simple and easy to follow, no messing
    around with extra steps or trying to be fancy. if you are strugling 
    with path finding as i was a few months ago, this could be your solution.

how to use it?
    first, make sure you implement the functions:
    - pointsareequal: checks if two points are equal.
    - pointiswalkable: checks if a point is walkable (ie, is terrain?)
    - pointhasobstacle: checks if a point, even if walkable, contains
    an obstacle (ie, another unit, a wall, etc.)
    
    after that, the function findpath can be called to get/calculate
    the next step from start to end.
    
    this is, imagine you have the following map/grid:
    [s][x][x][x][x][x][x][e]
    
    where s = start and e = end. upon calling findpath, the result
    would be (r):
    [s][r][x][x][x][x][x][e]
    
    call it again from result to get closer and closer to the
    destination:
    [x][s][x][x][x][x][x][e]
    
    would result in:
    [x][s][r][x][x][x][x][e]

    findpath will return 1 if the path is possible, or 0 if not.

license
    whatever, mit?