From 9e6df61b1ef5120f3d10eb80d0892a044a46d166 Mon Sep 17 00:00:00 2001 From: Emile Date: Sun, 23 Feb 2020 16:42:23 +0100 Subject: run game func --- src/run.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src') diff --git a/src/run.go b/src/run.go index 9ea73ed..fb3c249 100644 --- a/src/run.go +++ b/src/run.go @@ -44,3 +44,41 @@ func arena(r2p *r2pipe.Pipe, config *Config, id, gen int) string { return res } + +// runGame actually runs the game (surprise!) +func runGame(r2p *r2pipe.Pipe, config *Config) { + + // start the competition + var botid int = 0 + var round int = 0 + for true { + + // load the registers + r2cmd(r2p, config.Bots[botid].Regs) + + // Step + stepIn(r2p) + + // store the regisers + registers := r2cmd(r2p, "aerR") + registersStripped := strings.Replace(registers, "\n", ";", -1) + config.Bots[botid].Regs = registersStripped + + logrus.Info(arena(r2p, config, botid, round)) + + if dead(r2p, botid) == true { + logrus.Warnf("DEAD (round %d)", round) + os.Exit(1) + } + + // switch players, if the new botid is 0, a new round has begun + botid = switchPlayer(r2p, botid, config) + if botid == 0 { + round++ + } + + // sleep only a partial of the total round time, as a round is made up of + // the movements of multiple bots + time.Sleep(config.GameRoundDuration / time.Duration(config.AmountOfBots)) + } +} -- cgit 1.4.1