Exemple #1
0
func _TestAddTile(t *testing.T) {
	var cont *env.Controller
	var state TileState
	var tile env.ITile
	var neigh env.ITile
	var x, y int

	cont = createDummyEnvController()
	tile = cont.GetStartingTile()
	state.AddDiscovery(tile)
	x, y = tile.GetIndices()

	if state.tiles[x][y].tile != tile {
		t.Error("Non-matching tile-state")
	}

	if !state.tiles[x][y].explored {
		t.Error("Discovered tile is not flagged as explored")
	}

	neigh = tile.GetNeighbour(env.RIGHT)
	state.AddDiscovery(neigh)

	if state.tiles[x+1][y].tile != neigh {
		t.Error("Non-matching tile-state")
	}
}
Exemple #2
0
func TestTileStatus(t *testing.T) {
	var cont *env.Controller
	var state TileState
	var base env.ITile
	var result Status

	// base is positioned at [0,0]
	cont = createDummyEnvController()
	base = cont.GetStartingTile()
	state.AddDiscovery(base)

	// Left is an invalid index [-1, 0]
	result = state.GetTileStatus(base, env.LEFT)
	if result != TILE_INVALID {
		t.Errorf("Expected %d, received %d\n", TILE_INVALID, result)
	}

	// Down is an invalid index [0, -1]
	result = state.GetTileStatus(base, env.DOWN)
	if result != TILE_INVALID {
		t.Errorf("Expected %d, received %d\n", TILE_INVALID, result)
	}

	// Right is an undiscovered tile
	result = state.GetTileStatus(base, env.RIGHT)
	if result != TILE_UNKOWN {
		t.Errorf("Expected %d, received %d\n", TILE_UNKOWN, result)
	}

	// Up is an undiscovered tile
	result = state.GetTileStatus(base, env.UP)
	if result != TILE_UNKOWN {
		t.Errorf("Expected %d, received %d\n", TILE_UNKOWN, result)
	}

	// Discover tile to the right
	base = base.GetNeighbour(env.RIGHT)
	state.AddDiscovery(base)

	result = state.GetTileStatus(base, env.LEFT)
	if result != TILE_DISCOVERED {
		t.Errorf("Expected %d, received %d\n", TILE_DISCOVERED, result)
	}

	// Move to the tile above the original base
	base = base.GetNeighbour(env.UP)
	state.AddDiscovery(base)
	base = base.GetNeighbour(env.LEFT)
	state.AddDiscovery(base)

	result = state.GetTileStatus(base, env.DOWN)
	if result != TILE_DISCOVERED {
		t.Errorf("Expected %d, received %d\n", TILE_DISCOVERED, result)
	}
}
Exemple #3
0
func pathfindEnvironment(discoverAll bool) (*env.Controller,
	*TileState) {
	var cont *env.Controller
	var tile *TileState
	var tileMap [env.MAX_SIZE][env.MAX_SIZE]bool

	tileMap[0][0] = true
	tileMap[0][1] = true
	tileMap[0][2] = true
	tileMap[1][2] = true
	tileMap[2][2] = true
	tileMap[2][1] = true
	tileMap[2][0] = true

	cont = new(env.Controller)
	cont.InitController(tileMap)

	tile = new(TileState)
	tile.AddDiscovery(cont.GetStartingTile())

	// Mark all walls where there are no tiles
	for x := 0; x < env.MAX_SIZE; x++ {
		for y := 0; y < env.MAX_SIZE; y++ {
			if !tileMap[x][y] {
				tile.tiles[x][y].explored = true
			}
		}
	}

	if discoverAll {
		t := cont.GetStartingTile()

		t = t.GetNeighbour(env.UP) // 0 1
		tile.AddDiscovery(t)

		t = t.GetNeighbour(env.UP) // 0 2
		tile.AddDiscovery(t)

		t = t.GetNeighbour(env.RIGHT) // 1 2
		tile.AddDiscovery(t)

		t = t.GetNeighbour(env.RIGHT) // 2 2
		tile.AddDiscovery(t)

		t = t.GetNeighbour(env.DOWN) // 2 1
		tile.AddDiscovery(t)

		t = t.GetNeighbour(env.DOWN)
		tile.AddDiscovery(t) // 2 0
	}

	return cont, tile
}