package astar0 import "math" // ManhattanFunc 曼哈顿 func ManhattanFunc(node, end *Node) int32 { x := Abs(node.x - end.x) y := Abs(node.y - end.y) return (x + y) * straightCost } // DiagonalFunc 对角线 func DiagonalFunc(node, end *Node) int32 { x := Abs(node.x - end.x) y := Abs(node.y - end.y) value := Min(x, y) return value*diagonalCost + Abs(x-y)*straightCost } // EuclideanFunc 欧几里得 func EuclideanFunc(node, end *Node) int32 { x := Abs(node.x - end.x) y := Abs(node.y - end.y) v := float64(x)*float64(x) + float64(y)*float64(y) return int32(math.Sqrt(v) * float64(straightCost)) } func IsWalkableFunc() func(x, y, value int32) bool { return func(x, y, value int32) bool { return value == 0 } }