From 60a28cea88e04de1d75b7f19915d06285cec7d76 Mon Sep 17 00:00:00 2001 From: wisplite Date: Thu, 14 May 2026 09:43:49 -0500 Subject: [PATCH] visualize explored nodes (closed path) --- astar.go | 4 ++++ main.go | 12 ++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/astar.go b/astar.go index eea8eaf..22c0267 100644 --- a/astar.go +++ b/astar.go @@ -128,6 +128,10 @@ func (a *AStar) GetGridTypes() []byte { return a.gridTypes } +func (a *AStar) GetClosedSet() []bool { + return a.closedSet +} + func (a *AStar) SetGScores(x int, y int, gScore float32) { a.gScores[y*a.width+x] = gScore } diff --git a/main.go b/main.go index c11adb4..5697fb1 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "image/color" "strconv" "strings" @@ -537,7 +536,16 @@ func main() { } } 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 { 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))