-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathquasilyte_pathing_bfs_test.go
51 lines (43 loc) · 1.25 KB
/
quasilyte_pathing_bfs_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package bench
import (
"github.com/quasilyte/pathing"
)
var pathingLayer = pathing.MakeGridLayer([4]uint8{1, 0, 0, 0})
type quasilytePathingBFSTester struct {
tc *testCase
grid *pathing.Grid
bfs *pathing.GreedyBFS
}
func newQuasilytePathingBFSTester() *quasilytePathingBFSTester {
return &quasilytePathingBFSTester{}
}
func (t *quasilytePathingBFSTester) Init(tc *testCase) {
t.tc = tc
t.bfs = pathing.NewGreedyBFS(pathing.GreedyBFSConfig{
NumCols: uint(tc.numCols),
NumRows: uint(tc.numRows),
})
width := tc.cellWidth * tc.numCols
height := tc.cellHeight * tc.numRows
t.grid = pathing.NewGrid(pathing.GridConfig{
WorldWidth: uint(width),
WorldHeight: uint(height),
})
fillPathingGrid(t.grid, tc)
}
func (t *quasilytePathingBFSTester) BuildPath() (pathing.GridPath, gridCoord) {
from := pathing.GridCoord{X: t.tc.start.X, Y: t.tc.start.Y}
to := pathing.GridCoord{X: t.tc.finish.X, Y: t.tc.finish.Y}
result := t.bfs.BuildPath(t.grid, from, to, pathingLayer)
return result.Steps, gridCoord{X: result.Finish.X, Y: result.Finish.Y}
}
func fillPathingGrid(g *pathing.Grid, tc *testCase) {
for y, row := range tc.layout {
for x, col := range row {
if col != 'x' {
continue
}
g.SetCellTile(pathing.GridCoord{X: x, Y: y}, 1)
}
}
}