mirror of
https://github.com/wisplite/a-star-go.git
synced 2026-06-27 15:37:07 -05:00
visualize explored nodes (closed path)
This commit is contained in:
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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))
|
||||||
|
|||||||
Reference in New Issue
Block a user