maze-solver-go/solver/solver.go

47 lines
666 B
Go
Raw Permalink Normal View History

package solver
import (
"fmt"
"maze-solver/maze"
)
type Solver interface {
Solve(*maze.Maze) *maze.SolvedMaze
}
type SolverFactory struct {
Type *string
}
const (
2023-08-15 17:22:10 +02:00
_DFS = "dfs"
_BFS = "bfs"
_Dijkstra = "dijkstra"
2023-08-15 18:43:18 +02:00
_AStar = "a-star"
)
var TYPES = []string{
_DFS,
_BFS,
2023-08-15 17:22:10 +02:00
_Dijkstra,
2023-08-15 18:43:18 +02:00
_AStar,
}
func (f *SolverFactory) Get() Solver {
switch *f.Type {
case _DFS:
return &DFSSolver{}
case _BFS:
return &BFSSolver{}
2023-08-15 18:43:18 +02:00
case _AStar:
return &AStarSolver{}
2023-08-15 17:22:10 +02:00
case _Dijkstra:
return &DijkstraSolver{}
}
panic(fmt.Sprintf("Unrecognized solver type %q", *f.Type))
}
2023-08-15 15:42:53 +02:00
func visited(node *maze.Node) bool {
return node == nil || node.Visited
}