-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgoUno.go
95 lines (74 loc) · 2.01 KB
/
goUno.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"log"
"math/rand"
"os"
"time"
gouno "github.com/pfedan/goUno/goUno"
flag "github.com/spf13/pflag"
)
func check(e error) {
if e != nil {
panic(e)
}
}
type unoGameParameters struct {
playerNames []string
humanFlags []bool
roundCount int
muteLog bool
}
var gameParams unoGameParameters
func init() {
playersDefault := []string{"A", "B"}
humanFlagDefault := []bool{false, false}
roundCountDefault := 1
muteLogDefault := false
flag.StringSliceVarP(&(gameParams.playerNames), "players", "p", playersDefault, "")
flag.BoolSliceVarP(&(gameParams.humanFlags), "human", "h", humanFlagDefault, "")
flag.IntVarP(&(gameParams.roundCount), "roundcount", "r", roundCountDefault, "")
flag.BoolVarP(&(gameParams.muteLog), "mute", "m", muteLogDefault, "")
}
func main() {
flag.Parse()
if len(gameParams.humanFlags) > len(gameParams.playerNames) {
os.Exit(-100)
}
rand.Seed(time.Now().UnixNano())
log.SetFlags(0)
var g gouno.UnoGame
players := gameParams.playerNames
cnt := map[string]int{}
pointSum := map[string]int{}
pointsPerGame := map[int]int{}
turns := map[int]int{}
for round := 0; round < gameParams.roundCount; round++ {
g.Muted = gameParams.muteLog
g.Initialize(players)
for i, humanFlag := range gameParams.humanFlags {
g.Players[i].Human = humanFlag
// g.Players[i].Strategy = gouno.StrategyAggressive
}
stopGame := false
for i := 1; !stopGame; i++ {
g.Printf("Turn %d:\n", i)
stopGame = g.PlayOneTurn()
if stopGame {
turns[g.Turns]++
break
}
}
cnt[g.GetActivePlayerName()]++
points := 0
for _, p := range g.Players {
points += p.GetPoints()
}
pointsPerGame[points]++
pointSum[g.GetActivePlayerName()] += points
g.Printf("Game over, Player %s has won with %d points.\n\n", g.GetActivePlayerName(), points)
}
log.Printf("Wins per Player: %+v\n", cnt)
log.Printf("Total points per Player: %+v\n", pointSum)
log.Printf("Count of turns per game: %+v\n", turns)
log.Printf("Count of points per game: %+v\n", pointsPerGame)
}