node.go 866 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package astar0
  2. import "fmt"
  3. const (
  4. statusClose int32 = -1
  5. statusNormal int32 = 0
  6. statusOpen int32 = 1
  7. )
  8. type Node struct {
  9. parent *Node
  10. x int32
  11. y int32
  12. f int32
  13. g int32
  14. h int32
  15. value int32
  16. status int32
  17. }
  18. func (p *Node) X() int32 {
  19. return p.x
  20. }
  21. func (p *Node) Y() int32 {
  22. return p.y
  23. }
  24. func (p *Node) Value() int32 {
  25. return p.value
  26. }
  27. func (p *Node) Status() int32 {
  28. return p.status
  29. }
  30. func (p *Node) String() string {
  31. return fmt.Sprintf("(%d,%d)", p.x, p.y)
  32. }
  33. func (p *Node) Clean() {
  34. p.parent = nil
  35. p.f = 0
  36. p.g = 0
  37. p.h = 0
  38. p.status = statusNormal
  39. }
  40. func (p *Node) IsClose() bool {
  41. return p.status == statusClose
  42. }
  43. func (p *Node) IsOpen() bool {
  44. return p.status == statusOpen
  45. }
  46. func newNode(x, y, value int32) *Node {
  47. return &Node{
  48. x: x,
  49. y: y,
  50. value: value,
  51. status: statusNormal,
  52. }
  53. }