Wednesday, October 2, 2013

A* is Born

I finished up implementing A* today. There were a lot of bugs I had to work though, but it seems to be working now. There's still a minor bug left. Under certain conditions robots will go through an extra square. It's weird, but predictable and doesn't break anything so I'll look into it later.

For those familiar with A*, I'm using an unusual heuristic that I learned from one of my professes in college. The robots can only move to adjacent squares, diagonals included. The heuristic returns the shortest possible distance obeying those rules. It's cheaper than Euclidean distance, but more accurate than Manhattan or Chebyshev. Incidentally, because the robots can only take those kind of paths, the heuristic is also admissible (it'll never over estimate the distance).

I've also added a travel cost to each tile. This can be used to make tiles more difficult to travel through. For example, rocky terrain would have a higher cost than paved roads. Here's a picture of the pathfinding in action. The black tiles are walls, and the green tiles are the tiles considered by the algorithm. The robot is moving from left to right.

No comments:

Post a Comment