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 createController() *env.Controller {
	var controller *env.Controller
	controller = new(env.Controller)

	var tileMap = env.LoadMap(arg.File())

	controller.InitController(tileMap)
	return controller
}
Exemple #3
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 #4
0
func createDummyEnvController() *env.Controller {
	var c *env.Controller = new(env.Controller)

	var tileMap [env.MAX_SIZE][env.MAX_SIZE]bool
	tileMap[0][0] = true
	tileMap[1][0] = true
	tileMap[2][0] = true
	tileMap[0][1] = true
	tileMap[1][1] = true
	tileMap[2][1] = true

	c.InitController(tileMap)
	return c
}
Exemple #5
0
func (t *t_renderer) renderFrame(cont *env.Controller, agent *agent.Agent) {
	var tiles [env.MAX_SIZE][env.MAX_SIZE]env.ITile

	tiles = cont.CHEAT_GetTiles()

	t.renderer.SetDrawColor(0, 0, 0, 255)

	t.renderer.Clear()

	// Draw the tiles
	for x := 0; x < env.MAX_SIZE; x++ {
		for y := 0; y < env.MAX_SIZE; y++ {
			if tiles[x][y] != nil {
				if tiles[x][y].GetState() == env.CLEAN {
					t.drawTile(x, env.MAX_SIZE-y-1, 100, 255, 100, 255)
				} else {
					t.drawTile(x, env.MAX_SIZE-y-1, 100, 100, 100, 255)
				}
			}
		}
	}

	// Draw the undiscovered areas
	for x := 0; x < env.MAX_SIZE; x++ {
		for y := 0; y < env.MAX_SIZE; y++ {
			var status tile.Status
			status = agent.CHEAT_GetTileStatus(x, y)

			if status == tile.TILE_UNKOWN {
				t.drawQuestionMark(x, env.MAX_SIZE-y-1)
			}
		}
	}

	x, y := agent.CHEAT_GetCurrentTile().GetIndices()
	t.drawAgent(x, env.MAX_SIZE-y-1)

	t.renderer.Present()
}
Exemple #6
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
}