-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
78 lines (70 loc) · 2.65 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
package main
import (
"strconv"
)
func main() {
layout := NewLayout()
layout.AlgorithmList.SetSelectedFunc(func(index int, mainText string, secondaryText string, shortcut rune) {
switch mainText {
case "DFS":
if !layout.matrix.isSolving {
width, height := layout.GetMatrixDimensions()
layout.LogView.SetText(layout.LogView.GetText(true) + "\nGenerating maze using DFS of size " + strconv.Itoa(width) + "x" + strconv.Itoa(height))
layout.MatrixBox.SetText(layout.matrix.GenerateMaze(height, width, DFS))
}
case "Prim's":
if !layout.matrix.isSolving {
width, height := layout.GetMatrixDimensions()
layout.LogView.SetText(layout.LogView.GetText(true) + "\nGenerating maze using Prim's algorithm of size " + strconv.Itoa(width) + "x" + strconv.Itoa(height))
layout.MatrixBox.SetText(layout.matrix.GenerateMaze(height, width, Prims))
}
case "Kruskal's":
if !layout.matrix.isSolving {
width, height := layout.GetMatrixDimensions()
layout.LogView.SetText(layout.LogView.GetText(true) + "\nGenerating maze using Kruskal's algorithm of size " + strconv.Itoa(width) + "x" + strconv.Itoa(height))
layout.MatrixBox.SetText(layout.matrix.GenerateMaze(height, width, Kruskals))
}
case "Solve Maze (DFS)":
if !layout.matrix.isSolving {
layout.matrix.isSolving = true
layout.LogView.SetText(layout.LogView.GetText(true) + "\nSolving maze using DFS...")
currentMaze := layout.MatrixBox.GetText(true)
solver := NewSolver()
go func() {
solution := solver.SolveMaze(layout.matrix, currentMaze, DFSSearchType)
layout.App.QueueUpdateDraw(func() {
layout.MatrixBox.SetText(solution)
layout.matrix.isSolving = false
})
}()
}
case "Solve Maze (BFS)":
if !layout.matrix.isSolving {
layout.matrix.isSolving = true
layout.LogView.SetText(layout.LogView.GetText(true) + "\nSolving maze using BFS...")
currentMaze := layout.MatrixBox.GetText(true)
// Prevent deadlock, basically an async await
go func() {
solver := NewSolver()
solution := solver.SolveMaze(layout.matrix, currentMaze, BFSSearchType)
layout.App.QueueUpdateDraw(func() {
layout.MatrixBox.SetText(solution)
})
}()
}
case "Fast Mode":
if !layout.matrix.isSolving {
layout.matrix.fastMode = !layout.matrix.fastMode
if layout.matrix.fastMode {
layout.AlgorithmList.SetItemText(5, "Fast Mode", "Fast mode is ON")
} else {
layout.AlgorithmList.SetItemText(5, "Fast Mode", "Fast mode is OFF")
}
layout.LogView.SetText("Fast mode is turned " + strconv.FormatBool(layout.matrix.fastMode))
}
}
})
if err := layout.Run(); err != nil {
panic(err)
}
}