diff --git a/sauce/astar.go b/sauce/astar.go index 5e6755c..fdb9208 100644 --- a/sauce/astar.go +++ b/sauce/astar.go @@ -49,7 +49,8 @@ func FindPath(w *World, fromX, fromY int, toX, toY int) ([]Node, bool) { // Get neighbors. var neighbors []*Node - for x := -1; x <= 1; x++ { + // diagonal + /*for x := -1; x <= 1; x++ { for y := -1; y <= 1; y++ { if x == 0 && y == 0 { continue @@ -60,6 +61,28 @@ func FindPath(w *World, fromX, fromY int, toX, toY int) ([]Node, bool) { } neighbors = append(neighbors, &Node{Coord: coord, parent: current, g: math.MaxUint16, f: math.MaxUint16}) } + }*/ + // non-diagonal + for x := -1; x <= 1; x++ { + if x == 0 { + continue + } + coord := Coord{current.X + int16(x), current.Y} + if cell := w.At(int(coord.X), int(coord.Y)); cell == nil || cell.Hueristic == 255 { + continue + } + neighbors = append(neighbors, &Node{Coord: coord, parent: current, g: math.MaxUint16, f: math.MaxUint16}) + + } + for y := -1; y <= 1; y++ { + if y == 0 { + continue + } + coord := Coord{current.X, current.Y + int16(y)} + if cell := w.At(int(coord.X), int(coord.Y)); cell == nil || cell.Hueristic == 255 { + continue + } + neighbors = append(neighbors, &Node{Coord: coord, parent: current, g: math.MaxUint16, f: math.MaxUint16}) } // Iterate over neighbors.