Esempio n. 1
0
func (a *Agent) printAction(action int) {
	if !arg.Verbose() || !arg.Visual() {
		return
	}

	fmt.Print("Selected action:\t")

	switch action {
	case 0:
		fmt.Print("UP")
	case 1:
		fmt.Print("RIGHT")
	case 2:
		fmt.Print("DOWN")
	case 3:
		fmt.Print("LEFT")
	case 4:
		fmt.Print("SUCK")
	case 5:
		fmt.Print("NoOP")
	}

	fmt.Print("\n")
}
Esempio n. 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)
}