Figured out that the implementation of turn left
was actually dfs lol
This commit is contained in:
parent
69afaed1bf
commit
6e0a1032d1
@ -1,17 +1,21 @@
|
|||||||
package solver
|
package solver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"maze-solver/maze"
|
"maze-solver/maze"
|
||||||
"maze-solver/utils"
|
"maze-solver/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TurnLeftSolver struct {
|
type DFSSolver struct {
|
||||||
visited map[*maze.Node]bool
|
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)()
|
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]
|
current, end := m.Nodes[0], m.Nodes[len(m.Nodes)-1]
|
||||||
s.visited = make(map[*maze.Node]bool, len(m.Nodes))
|
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
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *TurnLeftSolver) wasVisited(node *maze.Node) bool {
|
func (s *DFSSolver) wasVisited(node *maze.Node) bool {
|
||||||
if node == nil {
|
if node == nil {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
@ -24,7 +24,7 @@ var TYPES = []string{
|
|||||||
func (f *SolverFactory) Get() Solver {
|
func (f *SolverFactory) Get() Solver {
|
||||||
switch *f.Type {
|
switch *f.Type {
|
||||||
case _TURN_LEFT:
|
case _TURN_LEFT:
|
||||||
return &TurnLeftSolver{}
|
return &DFSSolver{}
|
||||||
}
|
}
|
||||||
panic(fmt.Sprintf("Unrecognized solver type %q", *f.Type))
|
panic(fmt.Sprintf("Unrecognized solver type %q", *f.Type))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user