-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
75 lines (63 loc) · 1.53 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
package main
import (
"antfarm/antfarm"
"fmt"
"os"
)
func main() {
if len(os.Args) < 2 {
fmt.Println("ERROR: Invalid number of arguments")
return
}
filePath := os.Args[1]
lines, err := antfarm.ReadFile(filePath)
if err != nil {
fmt.Println("ERROR: File not found")
return
}
// Check for multiple start or end points
startCount,endCount := 0, 0
for _,line := range lines{
if line == "##start"{
startCount++
}
if line == "##end"{
endCount++
}
}
if startCount > 1 || endCount > 1{
fmt.Println("Error: You cannot have more than one starting or ending point")
return
}
// Print input
for _, line := range lines {
fmt.Println(line)
}
fmt.Println()
field := antfarm.Field{}
err = antfarm.ResolveInput(lines, &field)
if err != nil {
fmt.Println("ERROR: invalid data format, " + err.Error())
return
}
var shortestPaths [][]string
visited := make(map[string]bool)
antfarm.FindShortestPaths(field, "", []string{}, visited, &shortestPaths)
shortestPaths = antfarm.RemoveTooLongPaths(shortestPaths)
if len(shortestPaths) == 0 {
fmt.Printf("ERROR: invalid data format, farm is unsolvable")
return
}
// Capture the movements
movements := antfarm.StartTurnBasedSolving(&field, shortestPaths)
// Print movements
fmt.Println("Ant movements:")
for _, move := range movements {
fmt.Println(move)
}
// Run visualizer if "visualize" argument is provided
if len(os.Args) > 2 && os.Args[2] == "visualize" {
fmt.Println("\nStarting visualization...")
antfarm.RunVisualizer(&field, movements)
}
}