| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package astar
- import "fmt"
- // Node 节点结构
- type Node struct {
- x, y int32
- isWalkable bool // 是否可行走
- neighbors map[*Node]int32
- }
- // NewNode 创建新节点
- func NewNode(x, y int32, isWalkable bool) *Node {
- return &Node{
- x: x,
- y: y,
- isWalkable: isWalkable,
- neighbors: make(map[*Node]int32),
- }
- }
- func (p *Node) AddNeighbor(node *Node, distance int32) {
- if node != nil && node.isWalkable {
- p.neighbors[node] = distance
- }
- }
- func (p *Node) X() int32 {
- return p.x
- }
- func (p *Node) Y() int32 {
- return p.y
- }
- func (p *Node) IsOdd() bool {
- return (p.x & 0x1) == 0x1
- }
- func (p *Node) IsEven() bool {
- return (p.x & 0x1) == 0x0
- }
- func (p *Node) String() string {
- return fmt.Sprintf("{%d, %d}", p.x, p.y)
- }
|