Skip to content

Commit

Permalink
Figured out that the implementation of turn left
Browse files Browse the repository at this point in the history
was actually dfs lol
  • Loading branch information
karma-riuk committed Aug 13, 2023
1 parent 69afaed commit 6e0a103
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions solver/turn_left.go → solver/dfs.go
Original file line number Diff line number Diff line change
@@ -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))

Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion solver/solver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

0 comments on commit 6e0a103

Please sign in to comment.