-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (49 loc) · 962 Bytes
/
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
package main
import (
"fmt"
"log"
"os"
)
func main() {
log.Println("Start program...")
if len(os.Args) != 2 {
panic("Please specify an input path")
}
input, err := readFile(os.Args[1])
if err != nil {
log.Fatal(err)
}
grid := newGrid(input.Dimensions, input.Moves, input.Zombie, input.Creatures)
res := runProgram(&grid)
log.Printf("Result: %v", res)
if err := writeFile(res, "data/response.json"); err != nil {
fmt.Println("Error:", err)
}
}
func runProgram(grid *Grid) outputData {
position := 0
for {
grid.moveZombie(position)
position++
if position > grid.Scores {
break
}
}
return outputData{
Scores: grid.Scores,
Zombies: grid.Zombies,
}
}
func convertMoveToCoordinates(move string) (x, y int, err error) {
switch move {
case "U":
return 0, -1, nil
case "D":
return 0, 1, nil
case "L":
return -1, 0, nil
case "R":
return 1, 0, nil
}
return 0, 0, fmt.Errorf("unknown move '%s'", move)
}