visualize explored nodes (closed path)

This commit is contained in:
2026-05-14 09:43:49 -05:00
parent 589663d3d0
commit 60a28cea88
2 changed files with 14 additions and 2 deletions
+4
View File
@@ -128,6 +128,10 @@ func (a *AStar) GetGridTypes() []byte {
return a.gridTypes return a.gridTypes
} }
func (a *AStar) GetClosedSet() []bool {
return a.closedSet
}
func (a *AStar) SetGScores(x int, y int, gScore float32) { func (a *AStar) SetGScores(x int, y int, gScore float32) {
a.gScores[y*a.width+x] = gScore a.gScores[y*a.width+x] = gScore
} }
+10 -2
View File
@@ -1,7 +1,6 @@
package main package main
import ( import (
"fmt"
"image/color" "image/color"
"strconv" "strconv"
"strings" "strings"
@@ -537,7 +536,16 @@ func main() {
} }
} }
path := astar.CalculatePath(int(startPos.X), int(startPos.Y), int(endPos.X), int(endPos.Y)) path := astar.CalculatePath(int(startPos.X), int(startPos.Y), int(endPos.X), int(endPos.Y))
fmt.Println(path) closedSet := astar.GetClosedSet()
for i, closed := range closedSet {
if closed {
x := i % width
y := i / width
if x != int(startPos.X) || y != int(startPos.Y) {
rl.ImageDrawPixel(mapImage, int32(x), int32(y), rl.NewColor(0, 0, 255, 255))
}
}
}
for _, p := range path { for _, p := range path {
if p[0] != int(startPos.X) || p[1] != int(startPos.Y) { // we want to keep the start position green if p[0] != int(startPos.X) || p[1] != int(startPos.Y) { // we want to keep the start position green
rl.ImageDrawPixel(mapImage, int32(p[0]), int32(p[1]), rl.NewColor(255, 255, 0, 255)) rl.ImageDrawPixel(mapImage, int32(p[0]), int32(p[1]), rl.NewColor(255, 255, 0, 255))