-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (44 loc) · 1.07 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
package main
import (
"fmt"
"os"
"richardscull/lem-in/lib"
)
func main() {
if len(os.Args) != 2 {
fmt.Println("ERROR: Invalid number of arguments")
return
}
// Read file
filePath := os.Args[1]
lines, err := lib.ReadFile(filePath)
if err != nil {
fmt.Println("ERROR: File not found")
return
}
// Print file content
for _, line := range lines {
fmt.Println(line)
}
fmt.Println() // Empty line
// Resolve input and fill field
field := lib.Field{}
err = lib.ResolveInput(lines, &field)
if err != nil {
fmt.Println("ERROR: invalid data format, " + err.Error())
return
}
// Note: used for debugging purposes
// lib.PrintFieldData(&field)
// Find all shortest paths
var shortestPaths [][]string
visited := make(map[string]bool)
lib.FindShortestPaths(field, "", []string{}, visited, &shortestPaths)
shortestPaths = lib.RemoveTooLongPaths(shortestPaths)
if len(shortestPaths) == 0 {
fmt.Printf("ERROR: invalid data format, farm is unsolvable")
return
}
// Start turn-based solving and print result
lib.StartTurnBasedSolving(&field, shortestPaths)
}