direction.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package astar0
  2. var (
  3. Direction4 = [][]int32{
  4. {0, -1}, // 上
  5. {-1, 0}, // 左
  6. {1, 0}, // 右
  7. {0, 1}, // 下
  8. }
  9. Direction6Left = [][]int32{
  10. {0, -1}, // 上(优先)
  11. {0, 1}, // 下(优先)
  12. {1, 0}, // 右(优先)
  13. {-1, 0}, // 左(优先)
  14. {-1, -1}, // 左上
  15. {-1, 1}, // 左下
  16. }
  17. Direction6Right = [][]int32{
  18. {0, -1}, // 上(优先)
  19. {0, 1}, // 下(优先)
  20. {1, 0}, // 右(优先)
  21. {-1, 0}, // 左(优先)
  22. {1, -1}, // 右上
  23. {1, 1}, // 右下
  24. }
  25. // Column Staggered Grid (Even-q)
  26. // y 为偶数列 (Even X) (e.g. 58) -> Shifted DOWN (+0.5)
  27. // Neighbors: 4(Up), 1(Down), 5(LU), 6(LD), 3(RU), 2(RD)
  28. // Deltas from (x,y):
  29. // Up: {0, -1}
  30. // Down: {0, 1}
  31. // Left (LU): {-1, 0}
  32. // Left-Down (LD): {-1, 1}
  33. // Right (RU): {1, 0}
  34. // Right-Down (RD): {1, 1}
  35. Direction6EvenX = [][]int32{
  36. {0, -1}, // Up
  37. {0, 1}, // Down
  38. {-1, 0}, // Left-Up
  39. {-1, 1}, // Left-Down
  40. {1, 0}, // Right-Up
  41. {1, 1}, // Right-Down
  42. }
  43. // Odd X columns (e.g. 57, 59) -> Shifted UP relative to Even
  44. // Neighbors relative to Odd center:
  45. // Up: {0, -1}
  46. // Down: {0, 1}
  47. // Left-Up (Top-Left): {-1, -1}
  48. // Left-Down (Bot-Left): {-1, 0}
  49. // Right-Up (Top-Right): {1, -1}
  50. // Right-Down (Bot-Right): {1, 0}
  51. Direction6OddX = [][]int32{
  52. {0, -1}, // Up
  53. {0, 1}, // Down
  54. {-1, -1}, // Left-Up
  55. {-1, 0}, // Left-Down
  56. {1, -1}, // Right-Up
  57. {1, 0}, // Right-Down
  58. }
  59. Direction8 = [][]int32{
  60. {0, -1}, // 上
  61. {1, -1}, // 右上
  62. {-1, 0}, // 左
  63. {-1, -1}, // 左上
  64. {1, 0}, // 右
  65. {1, 1}, // 右下
  66. {0, 1}, // 下
  67. {-1, 1}, // 左下
  68. }
  69. )
  70. func Direction4Func(_ *Node) [][]int32 {
  71. return Direction4
  72. }
  73. func Direction6Func(node *Node) [][]int32 {
  74. if node.x%2 == 0 {
  75. return Direction6Left
  76. }
  77. return Direction6Right
  78. }
  79. // Direction6ColFunc implements Column Stagger logic
  80. func Direction6ColFunc(node *Node) [][]int32 {
  81. if node.x%2 == 0 {
  82. return Direction6EvenX
  83. }
  84. return Direction6OddX
  85. }
  86. func Direction8Func(_ *Node) [][]int32 {
  87. return Direction8
  88. }