Added argument parsing to run the solver correctly
This commit is contained in:
@ -1,5 +1,48 @@
|
||||
package reader
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image/color"
|
||||
)
|
||||
|
||||
type Reader interface {
|
||||
Read() (*RawMaze, error)
|
||||
}
|
||||
|
||||
type ReaderFactory struct {
|
||||
Type string
|
||||
Filename *string
|
||||
PathChar, WallChar, SolutionChar *string
|
||||
CellWidth, CellHeight *int
|
||||
WallColor, PathColor color.Color
|
||||
}
|
||||
|
||||
const (
|
||||
_IMAGE = "image"
|
||||
_TEXT = "text"
|
||||
)
|
||||
|
||||
var TYPES = map[string]string{
|
||||
".png": _IMAGE,
|
||||
".txt": _TEXT,
|
||||
}
|
||||
|
||||
func (f *ReaderFactory) Get() Reader {
|
||||
switch f.Type {
|
||||
case _TEXT:
|
||||
return &TextReader{
|
||||
Filename: *f.Filename,
|
||||
PathChar: byte((*f.PathChar)[0]),
|
||||
WallChar: byte((*f.WallChar)[0]),
|
||||
}
|
||||
case _IMAGE:
|
||||
return &ImageReader{
|
||||
Filename: *f.Filename,
|
||||
CellWidth: *f.CellWidth,
|
||||
CellHeight: *f.CellHeight,
|
||||
WallColor: f.WallColor,
|
||||
PathColor: f.PathColor,
|
||||
}
|
||||
}
|
||||
panic(fmt.Sprintf("Unrecognized reader type %q", f.Type))
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ type TextReader struct {
|
||||
PathChar, WallChar byte
|
||||
}
|
||||
|
||||
func (r TextReader) Read() (*RawMaze, error) {
|
||||
func (r *TextReader) Read() (*RawMaze, error) {
|
||||
defer utils.Timer("Text Reader", 3)()
|
||||
lines, err := getLines(r.Filename)
|
||||
if err != nil {
|
||||
|
@ -1,5 +1,46 @@
|
||||
package writer
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image/color"
|
||||
"maze-solver/maze"
|
||||
|
||||
"github.com/mazznoer/colorgrad"
|
||||
)
|
||||
|
||||
type Writer interface {
|
||||
Write() error
|
||||
}
|
||||
|
||||
type WriterFactory struct {
|
||||
Type string
|
||||
Filename *string
|
||||
PathChar, WallChar, SolutionChar *string
|
||||
CellWidth, CellHeight *int
|
||||
WallColor, PathColor color.Color
|
||||
SolutionGradient colorgrad.Gradient
|
||||
}
|
||||
|
||||
const (
|
||||
_IMAGE = "image"
|
||||
)
|
||||
|
||||
var TYPES = map[string]string{
|
||||
".png": _IMAGE,
|
||||
}
|
||||
|
||||
func (f *WriterFactory) Get(m *maze.SolvedMaze) Writer {
|
||||
switch f.Type {
|
||||
case _IMAGE:
|
||||
return &ImageWriter{
|
||||
Filename: *f.Filename,
|
||||
Maze: m,
|
||||
CellWidth: *f.CellWidth,
|
||||
CellHeight: *f.CellHeight,
|
||||
WallColor: f.WallColor,
|
||||
PathColor: f.PathColor,
|
||||
SolutionGradient: f.SolutionGradient,
|
||||
}
|
||||
}
|
||||
panic(fmt.Sprintf("Unrecognized writer type %q", f.Type))
|
||||
}
|
||||
|
Reference in New Issue
Block a user