3.6 AOI模块单元测试
package core
import (
"fmt"
"testing"
)
func TestNewAOIManager(t *testing.T) {
aoiMgr := NewAOIManager(100,300, 4, 200,450, 5)
fmt.Println(aoiMgr)
}
func TestAOIManagerSuroundGridsByGid(t *testing.T) {
aoiMgr := NewAOIManager(0,250, 5, 0,250, 5)
for k, _ := range aoiMgr.grids {
//得到当前格子周边的九宫格
grids := aoiMgr.GetSurroundGridsByGid(k)
//得到九宫格所有的IDs
fmt.Println("gid : ", k, " grids len = ", len(grids))
gIDs := make([]int, 0, len(grids))
for _, grid := range grids {
gIDs = append(gIDs, grid.GID)
}
fmt.Printf("grid ID: %d, surrounding grid IDs are %v\n", k, gIDs)
}
}
结果
AOIManagr:
minX:100, maxX:300, cntsX:4, minY:200, maxY:450, cntsY:5
Grids in AOI Manager:
Grid id: 1, minX:150, maxX:200, minY:200, maxY:250, playerIDs:map[]
Grid id: 5, minX:150, maxX:200, minY:250, maxY:300, playerIDs:map[]
Grid id: 6, minX:200, maxX:250, minY:250, maxY:300, playerIDs:map[]
Grid id: 12, minX:100, maxX:150, minY:350, maxY:400, playerIDs:map[]
Grid id: 19, minX:250, maxX:300, minY:400, maxY:450, playerIDs:map[]
Grid id: 7, minX:250, maxX:300, minY:250, maxY:300, playerIDs:map[]
Grid id: 8, minX:100, maxX:150, minY:300, maxY:350, playerIDs:map[]
Grid id: 10, minX:200, maxX:250, minY:300, maxY:350, playerIDs:map[]
Grid id: 11, minX:250, maxX:300, minY:300, maxY:350, playerIDs:map[]
Grid id: 15, minX:250, maxX:300, minY:350, maxY:400, playerIDs:map[]
Grid id: 18, minX:200, maxX:250, minY:400, maxY:450, playerIDs:map[]
Grid id: 0, minX:100, maxX:150, minY:200, maxY:250, playerIDs:map[]
Grid id: 3, minX:250, maxX:300, minY:200, maxY:250, playerIDs:map[]
Grid id: 4, minX:100, maxX:150, minY:250, maxY:300, playerIDs:map[]
Grid id: 14, minX:200, maxX:250, minY:350, maxY:400, playerIDs:map[]
Grid id: 16, minX:100, maxX:150, minY:400, maxY:450, playerIDs:map[]
Grid id: 2, minX:200, maxX:250, minY:200, maxY:250, playerIDs:map[]
Grid id: 9, minX:150, maxX:200, minY:300, maxY:350, playerIDs:map[]
Grid id: 13, minX:150, maxX:200, minY:350, maxY:400, playerIDs:map[]
Grid id: 17, minX:150, maxX:200, minY:400, maxY:450, playerIDs:map[]
gid : 3 grids len = 6
grid ID: 3, surrounding grid IDs are [3 2 4 8 7 9]
gid : 5 grids len = 6
grid ID: 5, surrounding grid IDs are [5 6 0 10 1 11]
gid : 6 grids len = 9
grid ID: 6, surrounding grid IDs are [6 5 7 1 11 0 10 2 12]
gid : 11 grids len = 9
grid ID: 11, surrounding grid IDs are [11 10 12 6 16 5 15 7 17]
gid : 18 grids len = 9
grid ID: 18, surrounding grid IDs are [18 17 19 13 23 12 22 14 24]
gid : 2 grids len = 6
grid ID: 2, surrounding grid IDs are [2 1 3 7 6 8]
gid : 4 grids len = 4
grid ID: 4, surrounding grid IDs are [4 3 9 8]
gid : 7 grids len = 9
grid ID: 7, surrounding grid IDs are [7 6 8 2 12 1 11 3 13]
gid : 8 grids len = 9
grid ID: 8, surrounding grid IDs are [8 7 9 3 13 2 12 4 14]
gid : 19 grids len = 6
grid ID: 19, surrounding grid IDs are [19 18 14 24 13 23]
gid : 22 grids len = 6
grid ID: 22, surrounding grid IDs are [22 21 23 17 16 18]
gid : 0 grids len = 4
grid ID: 0, surrounding grid IDs are [0 1 5 6]
gid : 1 grids len = 6
grid ID: 1, surrounding grid IDs are [1 0 2 6 5 7]
gid : 13 grids len = 9
grid ID: 13, surrounding grid IDs are [13 12 14 8 18 7 17 9 19]
gid : 14 grids len = 6
grid ID: 14, surrounding grid IDs are [14 13 9 19 8 18]
gid : 16 grids len = 9
grid ID: 16, surrounding grid IDs are [16 15 17 11 21 10 20 12 22]
gid : 17 grids len = 9
grid ID: 17, surrounding grid IDs are [17 16 18 12 22 11 21 13 23]
gid : 23 grids len = 6
grid ID: 23, surrounding grid IDs are [23 22 24 18 17 19]
gid : 24 grids len = 4
grid ID: 24, surrounding grid IDs are [24 23 19 18]
gid : 9 grids len = 6
grid ID: 9, surrounding grid IDs are [9 8 4 14 3 13]
gid : 10 grids len = 6
grid ID: 10, surrounding grid IDs are [10 11 5 15 6 16]
gid : 12 grids len = 9
grid ID: 12, surrounding grid IDs are [12 11 13 7 17 6 16 8 18]
gid : 15 grids len = 6
grid ID: 15, surrounding grid IDs are [15 16 10 20 11 21]
gid : 20 grids len = 4
grid ID: 20, surrounding grid IDs are [20 21 15 16]
gid : 21 grids len = 6
grid ID: 21, surrounding grid IDs are [21 20 22 16 15 17]
PASS
ok zinx/zinx_app_demo/mmo_game/core 0.002s
我们可以用我们的AOI地图验证一下,是一致的。