about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2020-02-23 16:42:23 +0100
committerEmile <hanemile@protonmail.com>2020-02-23 16:42:23 +0100
commit9e6df61b1ef5120f3d10eb80d0892a044a46d166 (patch)
treeb0c49905b69086dd7f1e751994be5278b55463e6
parent3da976cf40d728747489832872445e710b04fb72 (diff)
run game func
-rw-r--r--src/run.go38
1 files changed, 38 insertions, 0 deletions
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))
+	}
+}