Figured out that the implementation of turn left

was actually dfs lol
This commit is contained in:
Karma Riuk 2023-08-13 21:31:47 +02:00
parent 64f99f28ce
commit 5d340f0805
2 changed files with 8 additions and 4 deletions

View File

@ -1,17 +1,21 @@
package solver
import (
"log"
"maze-solver/maze"
"maze-solver/utils"
)
type TurnLeftSolver struct {
type DFSSolver struct {
visited map[*maze.Node]bool
}
func (s *TurnLeftSolver) Solve(m *maze.Maze) *maze.SolvedMaze {
func (s *DFSSolver) Solve(m *maze.Maze) *maze.SolvedMaze {
defer utils.Timer("Turn left algorithm", 2)()
log.Println("Starting dfs")
log.Printf("m.Nodes: %v\n", len(m.Nodes))
current, end := m.Nodes[0], m.Nodes[len(m.Nodes)-1]
s.visited = make(map[*maze.Node]bool, len(m.Nodes))
@ -54,7 +58,7 @@ func (s *TurnLeftSolver) Solve(m *maze.Maze) *maze.SolvedMaze {
return ret
}
func (s *TurnLeftSolver) wasVisited(node *maze.Node) bool {
func (s *DFSSolver) wasVisited(node *maze.Node) bool {
if node == nil {
return true
}

View File

@ -24,7 +24,7 @@ var TYPES = []string{
func (f *SolverFactory) Get() Solver {
switch *f.Type {
case _TURN_LEFT:
return &TurnLeftSolver{}
return &DFSSolver{}
}
panic(fmt.Sprintf("Unrecognized solver type %q", *f.Type))
}