about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2020-02-23 16:37:12 +0100
committerEmile <hanemile@protonmail.com>2020-02-23 16:37:12 +0100
commit8706b19ea15e99a9de46f8aefb55fbcdcad0f063 (patch)
tree5307b9892f87ac0201bcee21328bebe2a954badd /src
parent907194495157817b365d739b08ea3e9a365c2367 (diff)
parse config + logrus
Diffstat (limited to 'src')
-rw-r--r--src/config.go53
1 files changed, 47 insertions, 6 deletions
diff --git a/src/config.go b/src/config.go
index 15ac082..44e9f21 100644
--- a/src/config.go
+++ b/src/config.go
@@ -1,16 +1,57 @@
 package main
 
-import "flag"
+import (
+	"flag"
 
+	"github.com/sirupsen/logrus"
+)
+
+// parseConfig parses the config needed to start the game
 func parseConfig() Config {
-	verbose = flag.Bool("v", false, "verbose output")
+
+	// bot configs
+	arch := flag.String("arch", "x86", "bot architecture (mips|arm|x86)")
+	bits := flag.Int("bits", 32, "bot bitness (8|16|32|64)")
+	maxProgSize := flag.Int("maxProgSize", 64, "the maximum bot size")
+	memPerBot := flag.Int("memPerBot", 512, "the amount of memory each bot should add to the arena")
+	gameRoundDuration := flag.Duration("t", 250, "The duration of a round")
+
+	v := flag.Bool("v", false, "info")
+	vv := flag.Bool("vv", false, "debug")
+	vvv := flag.Bool("vvv", false, "trace")
+
+	// parse the flags
 	flag.Parse()
 
+	if *v == true {
+		logrus.SetLevel(logrus.InfoLevel)
+	} else if *vv == true {
+		logrus.SetLevel(logrus.DebugLevel)
+	} else if *vvv == true {
+		logrus.SetLevel(logrus.TraceLevel)
+	} else {
+		logrus.SetLevel(logrus.WarnLevel)
+	}
+
+	// parse all trailing command line arguments as path to bot sourcecode
+	amountOfBots := flag.NArg()
+
+	memsize := amountOfBots * *memPerBot
+
+	logrus.WithFields(logrus.Fields{
+		"mem per bot":  *memPerBot,
+		"amountOfBots": amountOfBots,
+		"memsize":      memsize,
+	}).Infof("Loaded config")
+
+	// define a config to return
 	config := Config{
-		Arch:        "x86",
-		Bits:        32,
-		Memsize:     1024,
-		MaxProgSize: 64,
+		Arch:              *arch,
+		Bits:              *bits,
+		Memsize:           memsize,
+		MaxProgSize:       *maxProgSize,
+		AmountOfBots:      amountOfBots,
+		GameRoundDuration: *gameRoundDuration,
 	}
 
 	return config