Das Programm ermittelt den kürzesten Weg von einem Startpunkt (grün) zum Zielpunkt (rot) in einem Raster aus 54 × 33 Zellen. Die Hindernisse (blau) werden bei der Suche umgangen und dürfen nicht diagonal geschnitten werden. Grundlage ist der A*-Algorithmus („A-Stern“), wie ihn Patrick Lester in „A* Pfadfindung für Anfänger“ erklärt.
Jede untersuchte Zelle erhält die Kosten F = G + H: G sind die Kosten des Weges vom Start, 10 je waagerechtem oder senkrechtem und 14 je diagonalem Schritt; H schätzt die Reststrecke als Manhattan-Distanz H = 10 · (|Δx| + |Δy|). In jedem Schritt wird die Zelle mit dem kleinsten F aus der offenen Liste genommen und geschlossen, und ihre acht Nachbarn werden geprüft: Neue Nachbarn kommen mit ihrem Vorgänger in die offene Liste; bei schon offenen wird der Vorgänger getauscht, wenn der neue Weg nicht länger ist. Sobald das Ziel in die offene Liste kommt, führt die Kette der Vorgänger zurück zum Start.
Ein diagonaler Schritt gilt als Schnitt durch die Wand, wenn eine der vier direkt angrenzenden Zellen des Feldes, auf das er führt, eine Wand ist – das Original prüft streng und hält deshalb auch diagonal Abstand zu Hindernissen. Weil die Manhattan-Schätzung diagonale Abkürzungen überschätzt, ist der gefundene Weg nicht immer der kürzeste: Die Kennzahl „Umweg“ vergleicht ihn mit dem kürzesten Pfad nach denselben Zugregeln. Zeichnen Sie Wände, versetzen Sie Start und Ziel und sehen Sie zu, wie sich offene Liste (Akzentfarbe) und geschlossene Liste (grau) ausbreiten.
Die App ist eine Neuumsetzung von 13_Pathfinding von Reinhard König. Was geändert wurde, steht in QUELLE.md.
The program finds the shortest path from a start point (green) to a target point (red) on a grid of 54 × 33 cells. The search goes around the obstacles (blue) and may not cut them diagonally. It is based on the A* algorithm (“A star”) as explained by Patrick Lester in “A* Pathfinding for Beginners”.
Every cell examined is given the cost F = G + H: G is the cost of the way from the start, 10 per horizontal or vertical step and 14 per diagonal step; H estimates the remaining distance as the Manhattan distance H = 10 · (|Δx| + |Δy|). In each step the cell with the lowest F is taken from the open list and closed, and its eight neighbours are checked: new neighbours enter the open list together with their parent; for neighbours already open the parent is replaced if the new way is not longer. As soon as the target enters the open list, the chain of parents leads back to the start.
A diagonal step counts as cutting the wall if any of the four cells directly adjacent to the cell it leads to is a wall – the original checks strictly and therefore keeps a distance from obstacles even diagonally. Because the Manhattan estimate overrates diagonal shortcuts, the path found is not always the shortest one: the measure “detour” compares it with the shortest path under the same move rules. Draw walls, move start and target, and watch the open list (accent colour) and the closed list (grey) spread.
The app re-implements 13_Pathfinding by Reinhard König. Changes are listed in QUELLE.md.