A* path finding algorithm. Finds the shortest path between start (green) and goal (blue). Move the start and goal node around with the mouse. Click to draw walls and click on the walls to erase them !!!! NOTE !!!! DO NOT ERASE THE OUTER WALLS. There sometimes is a bug where the code crashes when it tries to search for a path close to the "void". Click the green flag and draw with your mouse. Click where it is empty to draw walls and click on walls to erase them. Then press space to find the shortest path. Use this code in your game/project if you want to, but i would then appreciate if credits were given since it was challenging to make this project. Instructions for using the code: The code will save the shortest path to the list called "totalPath" and will be in the form of list coordinates. Take the "A*" sprite and drop into your backpack. Then take it out into your project. There are some variables and lists that you will need to adjust to make the code work for your game/project: grid_w = Is the width of your arena/map/grid grid_h = Is the height of your arena/map/grid grid = Is the list that should contain integers 0 and 1 where 0 is empty and 1 is a wall/obstacle. The pink "A*" block is what u use to find the shortest path. The two first arguments are the start_x and start_y. The second two are the goal_x and goal_y. The last one is not completed so always keep it at the value 1
Tell me in the comments if you find any bugs or have any questions. Third time's the charm. I previously tried to code this algorithm two times, but failed. I am very happy that I this time managed to get it right. I used the pseudo code in the link below to code this algorithm. There are some comments in the code so you are welcome to study and read the code. https://en.wikipedia.org/wiki/A*_search_algorithm