/
game.go
103 lines (95 loc) · 1.8 KB
/
game.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
96
97
98
99
100
101
102
103
package main
import (
"fmt"
"os"
"github.com/g3force/Go_Sokoban/ai"
"github.com/g3force/Go_Sokoban/engine"
"github.com/g3force/Go_Sokoban/log"
"strconv"
)
func main() {
log.DebugLevel = 4
runmode := false
single := true
level := "alevel"
straightAhead := false
outputFreq := int32(50000)
printSurface := false
threads := 1
e := engine.NewEngine()
if len(os.Args) > 1 {
for i, _ := range os.Args {
switch os.Args[i] {
case "-r":
runmode = true
case "-l":
if len(os.Args) > i+1 {
level = os.Args[i+1]
}
case "-i":
engine.PrintInfo()
case "-m":
single = false
case "-d":
if len(os.Args) > i+1 {
debuglevel, err := strconv.Atoi(os.Args[i+1])
if err == nil {
log.DebugLevel = debuglevel
}
}
case "-s":
straightAhead = true
case "-f":
if len(os.Args) > i+1 {
of, err := strconv.Atoi(os.Args[i+1])
if err == nil {
outputFreq = int32(of)
}
}
case "-p":
printSurface = true
case "-t":
if len(os.Args) > i+1 {
t, err := strconv.Atoi(os.Args[i+1])
if err != nil {
panic(err)
} else {
threads = t
}
}
}
}
}
e.LoadLevel(level)
log.I(e.Id, "Level: " + level)
if runmode {
ai.Run(e, single, outputFreq, printSurface, straightAhead, threads)
return
}
// surface
e.Print()
var choice string
for {
choice = ""
log.A("Press m for manual or r for run: ")
fmt.Scanf("%s", &choice)
if choice == "r" {
ai.Run(e, single, outputFreq, printSurface, straightAhead, threads)
break
} else if choice == "m" {
log.A("Manual mode\n")
var input int
for {
fmt.Scanf("%d", &input)
if input >= 0 && input <= 3 {
e.Move(engine.Direction(input))
e.Print()
} else {
e.UndoStep()
e.Print()
}
}
break
}
}
}