-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVisualizer.go
More file actions
45 lines (38 loc) · 737 Bytes
/
Visualizer.go
File metadata and controls
45 lines (38 loc) · 737 Bytes
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
package main
import (
"fmt"
)
const (
Cyan = "\033[36m"
)
func VisualizeMaze(maze Maze, visited map[Point]bool, path []Point) {
fmt.Print("\033[2J\033[H")
for y, row := range maze.Grid {
for x, char := range row {
point := Point{y, x}
if containsPoint(path, point) {
fmt.Print(Red, ".", Reset)
} else if visited[point] {
fmt.Print(Cyan, ".", Reset)
} else {
switch char {
case 'S':
fmt.Print(Green, string(char), Reset)
case 'E':
fmt.Print(Red, string(char), Reset)
default:
fmt.Print(string(char))
}
}
}
fmt.Println()
}
}
func containsPoint(path []Point, p Point) bool {
for _, point := range path {
if point == p {
return true
}
}
return false
}