-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
79 lines (64 loc) · 2.37 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"flag"
"fmt"
"math/rand"
"os"
"time"
"github.com/hani-q/alien-invasion/structs"
log "github.com/sirupsen/logrus"
)
func main() {
//Parsing input arguments
var alienCount int
var printStdout bool
var numIterations int
flag.IntVar(&alienCount, "aliens", 4, "Count of the Aliens that will descen upon the world. Default is 4")
flag.BoolVar(&printStdout, "stdout", false, "Print output to screen instead of logging. Default is false")
flag.IntVar(&numIterations, "numIterations", 10000, "Number of Iterations of the simulation. Each Alien will move these many Moves. Default is 10000")
inputMapPathStr := flag.String("world_file", "./test/world_tiny.txt", "Text file containing the world. Defaults to ./test/world_tiny.txt")
flag.Parse()
rand.Seed(time.Now().UnixNano())
//InitalizeLogging
if !printStdout {
var file, err = os.OpenFile("build/logs.txt", os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
fmt.Println("Could Not Open Log File : " + err.Error())
}
log.SetOutput(file)
}
log.SetFormatter(&log.TextFormatter{})
//One alien will roam the world endlessly, since no City will be destroyed
if alienCount < 2 {
msg := fmt.Sprintf("too few aliens (%v) for simulation", alienCount)
_ = fmt.Errorf(msg)
panic(msg)
}
//0 iterations ? whats the point
if numIterations == 0 {
msg := fmt.Sprintf("numIterations (%v) cannot be 0", numIterations)
_ = fmt.Errorf(msg)
panic(msg)
}
//Load the map.txt file into the Map pf world
log.Info("Loading world from Map file", *inputMapPathStr)
xWorld := structs.LoadWorldMap(*inputMapPathStr)
//Print Statistics about the cities
log.Infof("%v cities have been loaded from map file", xWorld.GetCityCount())
fmt.Printf("\nWorld in peacefull times\n\n")
fmt.Println(xWorld)
//Bring in the Queen via the inter-dimensional portal
//She will arrive in the xWorlds outer-orbit
queen := structs.Queen{Children: make(map[string]*structs.Alien),
QueenChan: make(chan structs.AlienLanguage)}
//Spew the Queen Mothers Eggs the Entire X-World
queen.LayEggs(alienCount, xWorld)
queen.HatchChildren(numIterations, xWorld)
queen.WaitChildren()
//Log the state of the World after the mayhem
fmt.Printf("\nWhats left after the Mayhem\n\n")
fmt.Println(xWorld)
//Log the state of the battle weary queen and her offspring
fmt.Printf("\nWhats left of the Invading Queen and her kin\n\n")
queen.PrintStatus()
}