Example #1
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()
}
Example #2
0
func main() {
	arg.BindArgs()
	rand.Seed(time.Now().UTC().UnixNano())

	var visual bool = arg.Visual()
	var rounds int = arg.NumRounds()
	var delay int = arg.DelayMS()

	var renderer t_renderer
	if visual {
		renderer.createWindow()
	}

	// Initialize the controller and the agent
	controller := createController()

	var perfs []util.SimPerf
	var max = controller.GetMaxPermCount()
	fmt.Printf("Max permutations: %d\n", max)
	perfs = make([]util.SimPerf, controller.GetMaxPermCount())

	var posPerm, dirtPerm uint64 = 0, 0
	for controller.CanPermute(posPerm, dirtPerm) {
		a := new(agent.Agent)
		a.Initialize(controller.GetStartingTile())

		controller.Permute(posPerm, dirtPerm)
		permNo := controller.GetPermNumber(posPerm, dirtPerm)

		// Run the simulation
		for i := 0; i < rounds; i++ {
			if visual {
				renderer.pollEvents()
				if renderer.shouldExit {
					break
				}

				renderer.renderFrame(controller, a)

				if arg.Manual() {
					reader := bufio.NewReader(os.Stdin)
					_, _ = reader.ReadString('\n')
				} else {
					time.Sleep(time.Duration(delay) * time.Millisecond)
				}
			}

			controller.Tick()
			a.Tick(&perfs[permNo])

			perfs[permNo].SetCleanTilesThisTick(controller.GetCleanTilesCount())
		}

		if arg.Verbose() {
			printSimPerf(perfs[permNo])
		}

		// Increment the permutations - if no more permutations
		// are allowed with the incremented dirtPerm, increment
		// posPerm. If posPerm now holds an invalid value, the
		// embracing for-loop will terminate.
		dirtPerm++
		if !controller.CanPermute(posPerm, dirtPerm) {
			dirtPerm = 0
			posPerm++
		}
	}

	printSimPerfs(&perfs)
}