Today we added a function that optimizes the path the robot takes to get home.
Our previous method was not very efficient, so we chose to implement a small pathfinding algorithm in order to determine the quickest way back.
How it works:
- Analyze surrounding tiles
- If some tiles are not safe, ignore those tiles
- For the remaining tiles, calculate distance from (0, 0) using Pythagorean Theorem
- Get lowest distance
- Get tile whose distance is the lowest distance
- Move to tile
- Repeat until robot is at (0, 0)
This guarantees that our robot will always take the shortest path back to (0, 0) that is also 100% safe.
A problem:
The fact that the robot would get stuck sometimes because the closest safe space was the safe space that it was just on.
How we fixed it:
We adjusted our algorithm so that the tiles the robot could choose from did not include any tiles it had already been to after finding gold.
Comments