Example #1
0
func (a *Agent) onPhaseMaintenanceBegin() {
	if arg.Verbose() {
		print("[Phase MAINTENANCE]\n")
	}

	a.history.onNewRound()
}
Example #2
0
func (n *t_noopstate) onRoundComplete(history *t_history, totalTiles int) int {
	var p float64 = history.getActionPercent(SUCK, totalTiles)

	// See "alg_outline" for details here
	if p < MIN_SUCK {
		if n.inc != n.min/2 {
			if n.inc == 0 {
				n.max = n.min
				n.min /= 2
				n.inc = n.min / 2
				n.cur = n.max
			} else {
				n.cur += n.inc
				n.inc /= 2
			}
		} else {
			n.min = n.max
			n.max *= 2
			n.inc = n.min / 2
			n.cur = n.max
		}
	} else if p > MAX_SUCK {
		if n.inc == 0 {
			n.min = n.max
			n.max *= 2
			n.inc = n.min / 2
			n.cur = n.max
		} else {
			n.cur -= n.inc
			n.inc /= 2
		}
	}

	if arg.Verbose() {
		fmt.Printf("[noopcalc]: P:%f min:%d  max:%d  inc:%d  cur:%d\n",
			p, n.min, n.max, n.inc, n.cur)
	}

	return n.cur
}
Example #3
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")
}
Example #4
0
func (a *Agent) Tick(perf *util.SimPerf) {
	if a.phase == MAINTENANCE {
		totalTiles := a.tileQueue.GetTileCount()

		if a.history.hasCompletedRound(totalTiles) {
			a.noopsRemaining = a.noopstate.onRoundComplete(&a.history, totalTiles)
			a.history.onNewRound()

			if arg.Verbose() {
				fmt.Printf("ROUND COMPLETE: %d noops\n", a.noopsRemaining)
			}
		}
	}

	action := a.getAction()
	a.performAction(action, perf)

	if a.phase == MAINTENANCE {
		a.history.addHistory(action, a.currentTile.GetITile())
	}

	a.tileQueue.MoveToBack(a.currentTile)
	a.printAction(action)
}
Example #5
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)
}