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 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
} }

View File

@ -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))
} }