[006] A-Star Pathfinding

[36h] A-Star Pathfinding using Tilemap & draw()

[Aug 21, 2023] 4h
- Tilemap study & review

[Aug 22, 2023] 4h
- AStar pathfinding study & review
- Tilemap static functions & utility
- [VCM] View-Controller-Model pattern

[Aug 23, 2023] 2h
- AStar pathfinding better pseudocode

[Aug 24, 2023] 3h
- AStar Pathfinding futher learning check
- UI and camera controls

[Aug 25, 2023] 2h
- More camera controls

[Aug 26, 2023] 4h
- Camera2D zoom and control finished
- Pathfinding errors (use of opened and closed array)

[Aug 27, 2023] 3h
- Player triangle to follow path

[Aug 28, 2023] 9h
- Debug mode (show index & costs)
- Step by Step mode
- Additional UI for modes
- Fix in distance calculation

[Aug 29, 2023] 5h
- Finalizing UI
- Player Behaviour Fix
- Project Upload & Review


Pseudocode
[en.wikipedia.org/wiki/A*_search_algorithm]

    g_cost          # distance from start_cell  []
    h_cost          # distance to target_cell   [heuristic]
    f_cost          # g_cost + h_cost           [full]

    opened_array    # set of nodes to be evaluated
    closed_array    # set of nodes already evaluated

00      add start_cell to opened_array

01      loop:
02          _current_cell = lowest f_cost in opened_array
03          if tie, _current_cell = lowest h_cost in opened_array
04          if tie, _current_cell = random between lowest

05          remove current_cell from opened_array
06          add current_cell to closed_array

07          if current_cell is target_cell, path found
08              retrace step from start_cell
09              return

10          loop each neighbour of current_cell
11              if neighbour is unpassable OR 
12              if neighbour is in closed_array
13                  skip to next neighbour

				# youtu.be/watch?v=mZfyt03LDH4&t=1004s
14              new_distance = distance of current cell and neighbour
15                  plus current g_cost of current_cell

16              if neighbour is not in OPEN or
17              if new_distance is shorter than g_cost of neighbour

18                  set g_cost of neighbour = new_distance       [distance to start]
19                  set h_cost of neighbour = distance to target
20                  set f_cost of neighbour = g_cost + f_cost

21                  set parent of neighbour to current_cell
22                  if neighbour is not in OPEN, add to open


Note: error in distance calculation
	# if horizontal distance is equal to vertical distance
	# will result in a 0 distance, forgot the "=" operator
	# took me a TON of time to detect this single error
StatusReleased
PlatformsHTML5
AuthorQuietGodot
Made withGodot

Leave a comment

Log in with itch.io to leave a comment.