-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
90 lines (87 loc) · 2.01 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
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"fmt"
"github.com/msmp-core/maze-generator-cli/CLI"
"github.com/msmp-core/maze-generator-cli/Generators"
"os"
)
func main() {
cli := ""
for i, a := range os.Args {
if i == 0 {
continue
}
cli += a + " "
}
options := []*CLI.Option{
{
ID: "s", Help: "Size of one side of the maze", ArgsRegex: `[0-9]+`, Required: true, IsInt: true, Disabled: false,
},
{
ID: "w", Help: "Width of the maze", ArgsRegex: `[0-9]+`, Required: true, IsInt: true, Disabled: true,
},
{
ID: "h", Help: "Height of the maze", ArgsRegex: `[0-9]+`, Required: true, IsInt: true, Disabled: true,
},
{
ID: "o", Help: "Output file", ArgsRegex: `[0-9a-zA-Z/.\-_]+`, Required: false, IsInt: false, Disabled: false,
},
{
ID: "d", Help: "Difficulty of the maze", ArgsRegex: `[0-9]+`, Required: false, IsInt: true, Disabled: false,
},
{
ID: "g", Help: "Number of random gates", ArgsRegex: `[0-9]+`, Required: false, IsInt: true, Disabled: false,
},
{
ID: "help", Help: "Show this help", ArgsRegex: ``, Required: false, IsInt: false, Disabled: false,
},
{
ID: "i", Help: "Add \"a hole\" in the center when generating the maze", ArgsRegex: `[0-9]+`, Required: false, IsInt: true, Disabled: false,
},
}
app := CLI.CLI{Options: options}
if len(os.Args) == 1 {
app.Help()
return
}
got, err := app.Parse(cli)
if err != nil {
println(err.Error())
app.Help()
return
}
var s int
var out string
d := 0
g := 0
inner := 0
for _, gt := range got {
switch gt.ID {
case "s":
s = gt.Value.(int)
case "d":
d = gt.Value.(int)
case "o":
out = gt.Value.(string)
case "g":
g = gt.Value.(int)
case "i":
inner = gt.Value.(int)
case "help":
app.Help()
return
}
}
m, err := Generators.GenerateNewMaze(uint(s), uint(s), uint(d), uint(g), uint(inner), Generators.NewRandomisedKruskal)
if err != nil {
panic(err)
}
m.RenderWalls()
if out != "" {
err = m.Output(out)
if err != nil {
panic(err)
}
fmt.Printf("Successfully outputted at %s\n", out)
}
}