From 6e0a1032d1d4a90494964203cda78a5cd8f48f24 Mon Sep 17 00:00:00 2001 From: Karma Riuk Date: Sun, 13 Aug 2023 21:31:47 +0200 Subject: [PATCH] Figured out that the implementation of turn left was actually dfs lol --- solver/{turn_left.go => dfs.go} | 10 +++++++--- solver/solver.go | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) rename solver/{turn_left.go => dfs.go} (84%) diff --git a/solver/turn_left.go b/solver/dfs.go similarity index 84% rename from solver/turn_left.go rename to solver/dfs.go index b9f9677..e0bd8ab 100644 --- a/solver/turn_left.go +++ b/solver/dfs.go @@ -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 } diff --git a/solver/solver.go b/solver/solver.go index cc59d30..0d34ae6 100644 --- a/solver/solver.go +++ b/solver/solver.go @@ -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)) }