3.6 AOI模块单元测试

  1. package core
  2. import (
  3. "fmt"
  4. "testing"
  5. )
  6. func TestNewAOIManager(t *testing.T) {
  7. aoiMgr := NewAOIManager(100,300, 4, 200,450, 5)
  8. fmt.Println(aoiMgr)
  9. }
  10. func TestAOIManagerSuroundGridsByGid(t *testing.T) {
  11. aoiMgr := NewAOIManager(0,250, 5, 0,250, 5)
  12. for k, _ := range aoiMgr.grids {
  13. //得到当前格子周边的九宫格
  14. grids := aoiMgr.GetSurroundGridsByGid(k)
  15. //得到九宫格所有的IDs
  16. fmt.Println("gid : ", k, " grids len = ", len(grids))
  17. gIDs := make([]int, 0, len(grids))
  18. for _, grid := range grids {
  19. gIDs = append(gIDs, grid.GID)
  20. }
  21. fmt.Printf("grid ID: %d, surrounding grid IDs are %v\n", k, gIDs)
  22. }
  23. }

结果

  1. AOIManagr:
  2. minX:100, maxX:300, cntsX:4, minY:200, maxY:450, cntsY:5
  3. Grids in AOI Manager:
  4. Grid id: 1, minX:150, maxX:200, minY:200, maxY:250, playerIDs:map[]
  5. Grid id: 5, minX:150, maxX:200, minY:250, maxY:300, playerIDs:map[]
  6. Grid id: 6, minX:200, maxX:250, minY:250, maxY:300, playerIDs:map[]
  7. Grid id: 12, minX:100, maxX:150, minY:350, maxY:400, playerIDs:map[]
  8. Grid id: 19, minX:250, maxX:300, minY:400, maxY:450, playerIDs:map[]
  9. Grid id: 7, minX:250, maxX:300, minY:250, maxY:300, playerIDs:map[]
  10. Grid id: 8, minX:100, maxX:150, minY:300, maxY:350, playerIDs:map[]
  11. Grid id: 10, minX:200, maxX:250, minY:300, maxY:350, playerIDs:map[]
  12. Grid id: 11, minX:250, maxX:300, minY:300, maxY:350, playerIDs:map[]
  13. Grid id: 15, minX:250, maxX:300, minY:350, maxY:400, playerIDs:map[]
  14. Grid id: 18, minX:200, maxX:250, minY:400, maxY:450, playerIDs:map[]
  15. Grid id: 0, minX:100, maxX:150, minY:200, maxY:250, playerIDs:map[]
  16. Grid id: 3, minX:250, maxX:300, minY:200, maxY:250, playerIDs:map[]
  17. Grid id: 4, minX:100, maxX:150, minY:250, maxY:300, playerIDs:map[]
  18. Grid id: 14, minX:200, maxX:250, minY:350, maxY:400, playerIDs:map[]
  19. Grid id: 16, minX:100, maxX:150, minY:400, maxY:450, playerIDs:map[]
  20. Grid id: 2, minX:200, maxX:250, minY:200, maxY:250, playerIDs:map[]
  21. Grid id: 9, minX:150, maxX:200, minY:300, maxY:350, playerIDs:map[]
  22. Grid id: 13, minX:150, maxX:200, minY:350, maxY:400, playerIDs:map[]
  23. Grid id: 17, minX:150, maxX:200, minY:400, maxY:450, playerIDs:map[]
  24. gid : 3 grids len = 6
  25. grid ID: 3, surrounding grid IDs are [3 2 4 8 7 9]
  26. gid : 5 grids len = 6
  27. grid ID: 5, surrounding grid IDs are [5 6 0 10 1 11]
  28. gid : 6 grids len = 9
  29. grid ID: 6, surrounding grid IDs are [6 5 7 1 11 0 10 2 12]
  30. gid : 11 grids len = 9
  31. grid ID: 11, surrounding grid IDs are [11 10 12 6 16 5 15 7 17]
  32. gid : 18 grids len = 9
  33. grid ID: 18, surrounding grid IDs are [18 17 19 13 23 12 22 14 24]
  34. gid : 2 grids len = 6
  35. grid ID: 2, surrounding grid IDs are [2 1 3 7 6 8]
  36. gid : 4 grids len = 4
  37. grid ID: 4, surrounding grid IDs are [4 3 9 8]
  38. gid : 7 grids len = 9
  39. grid ID: 7, surrounding grid IDs are [7 6 8 2 12 1 11 3 13]
  40. gid : 8 grids len = 9
  41. grid ID: 8, surrounding grid IDs are [8 7 9 3 13 2 12 4 14]
  42. gid : 19 grids len = 6
  43. grid ID: 19, surrounding grid IDs are [19 18 14 24 13 23]
  44. gid : 22 grids len = 6
  45. grid ID: 22, surrounding grid IDs are [22 21 23 17 16 18]
  46. gid : 0 grids len = 4
  47. grid ID: 0, surrounding grid IDs are [0 1 5 6]
  48. gid : 1 grids len = 6
  49. grid ID: 1, surrounding grid IDs are [1 0 2 6 5 7]
  50. gid : 13 grids len = 9
  51. grid ID: 13, surrounding grid IDs are [13 12 14 8 18 7 17 9 19]
  52. gid : 14 grids len = 6
  53. grid ID: 14, surrounding grid IDs are [14 13 9 19 8 18]
  54. gid : 16 grids len = 9
  55. grid ID: 16, surrounding grid IDs are [16 15 17 11 21 10 20 12 22]
  56. gid : 17 grids len = 9
  57. grid ID: 17, surrounding grid IDs are [17 16 18 12 22 11 21 13 23]
  58. gid : 23 grids len = 6
  59. grid ID: 23, surrounding grid IDs are [23 22 24 18 17 19]
  60. gid : 24 grids len = 4
  61. grid ID: 24, surrounding grid IDs are [24 23 19 18]
  62. gid : 9 grids len = 6
  63. grid ID: 9, surrounding grid IDs are [9 8 4 14 3 13]
  64. gid : 10 grids len = 6
  65. grid ID: 10, surrounding grid IDs are [10 11 5 15 6 16]
  66. gid : 12 grids len = 9
  67. grid ID: 12, surrounding grid IDs are [12 11 13 7 17 6 16 8 18]
  68. gid : 15 grids len = 6
  69. grid ID: 15, surrounding grid IDs are [15 16 10 20 11 21]
  70. gid : 20 grids len = 4
  71. grid ID: 20, surrounding grid IDs are [20 21 15 16]
  72. gid : 21 grids len = 6
  73. grid ID: 21, surrounding grid IDs are [21 20 22 16 15 17]
  74. PASS
  75. ok zinx/zinx_app_demo/mmo_game/core 0.002s

我们可以用我们的AOI地图验证一下,是一致的。