Пример #1
0
func TestTileFinding(t *testing.T) {
	var tilestate *TileState
	var dir env.Direction
	var tile *TileWrapper

	_, tilestate = pathfindEnvironment(false)
	tile = &tilestate.tiles[0][0]

	expect := []env.Direction{
		env.UP, env.UP,
		env.RIGHT, env.RIGHT,
		env.DOWN, env.DOWN,
		env.NONE}

	for i := 0; i < len(expect); i++ {
		var x, y, dx, dy int

		dir = TileFind(tile, TILE_UNKOWN, tilestate)
		x, y = tile.tile.GetIndices()
		dx, dy = env.GetIndices(dir)

		if dir != expect[i] {
			t.Errorf("Expected %d, got %d! ", expect[i], dir)
			return
		}

		if dir != env.NONE {
			// Discover and move to the new tile
			tilestate.AddDiscovery(tile.tile.GetNeighbour(dir))
			tile = &tilestate.tiles[x+dx][y+dy]
		}
	}
}
Пример #2
0
func (t *TileState) GetTileStatus(tile env.ITile, dir env.Direction) Status {
	var x, y int

	x, y = tile.GetIndices()
	dx, dy := env.GetIndices(dir)
	x += dx
	y += dy

	return t.GetTileStatusAtCoord(x, y)
}
Пример #3
0
func (t *TileState) GetTile(tile *TileWrapper,
	dir env.Direction) *TileWrapper {

	dx, dy := env.GetIndices(dir)
	x, y := tile.tile.GetIndices()

	if env.ValidIndex(x+dx, y+dy) {
		return &t.tiles[x+dx][y+dy]
	}

	return nil
}
Пример #4
0
func (a *Agent) moveInDirection(dir env.Direction) bool {
	var itile env.ITile

	itile = a.currentTile.GetITile().GetNeighbour(dir)

	if itile != nil {
		a.tileState.AddDiscovery(itile)
		a.currentTile = a.tileState.GetWrapper(itile)
		return true
	} else {
		x, y := a.currentTile.GetITile().GetIndices()
		dx, dy := env.GetIndices(dir)
		a.tileState.AddDiscoveryNil(x+dx, y+dy)
		return false
	}
}