Compare commits
No commits in common. "4f79d6f1edbdce11924f0b1dd58a19d521d712e0" and "6e0a1032d1d4a90494964203cda78a5cd8f48f24" have entirely different histories.
4f79d6f1ed
...
6e0a1032d1
2
.gitignore
vendored
@ -20,5 +20,3 @@
|
|||||||
# Go workspace file
|
# Go workspace file
|
||||||
go.work
|
go.work
|
||||||
/Session.vim
|
/Session.vim
|
||||||
/maze.png
|
|
||||||
/maze_sol.png
|
|
||||||
|
BIN
assets/real.png
Before Width: | Height: | Size: 151 KiB |
Before Width: | Height: | Size: 987 B |
Before Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 316 KiB |
Before Width: | Height: | Size: 424 B |
Before Width: | Height: | Size: 423 B |
Before Width: | Height: | Size: 286 B |
@ -1,122 +1,71 @@
|
|||||||
package writer
|
package writer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"image/color"
|
|
||||||
"io"
|
|
||||||
"maze-solver/maze"
|
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/mazznoer/colorgrad"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
OUT_DIR = "./out"
|
|
||||||
EXPECTED_DIR = "../../assets/solved"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestImageWriter(t *testing.T) {
|
func TestImageWriter(t *testing.T) {
|
||||||
if _, err := os.Stat(OUT_DIR); os.IsNotExist(err) {
|
// pathGradient, err := colorgrad.NewGradient().Colors(color.White).Build()
|
||||||
os.Mkdir(OUT_DIR, 0700)
|
// if err != nil {
|
||||||
}
|
// panic(err)
|
||||||
|
// }
|
||||||
tests := []struct {
|
//
|
||||||
name string
|
// tests := []struct {
|
||||||
filename string
|
// name string
|
||||||
m *maze.SolvedMaze
|
// filename string
|
||||||
CellWidth, cellHeight int
|
// m *maze.SolvedMaze
|
||||||
pathColor, wallColor color.Color
|
// CellWidth, cellHeight int
|
||||||
gradient colorgrad.Gradient
|
// pathColor, wallColor color.Color
|
||||||
}{
|
// gradient colorgrad.Gradient
|
||||||
{
|
// }{
|
||||||
"Trivial",
|
// {
|
||||||
"trivial.png",
|
// "Trivial",
|
||||||
trivial(),
|
// "../../out/trivial_sol.png",
|
||||||
20, 20,
|
// trivial(),
|
||||||
color.White, color.Black,
|
// 40, 40,
|
||||||
colorgrad.Warm(),
|
// color.White, color.Black,
|
||||||
},
|
// colorgrad.Warm(),
|
||||||
{
|
// },
|
||||||
"Trivial Bigger",
|
// {
|
||||||
"trivial-bigger.png",
|
// "Bigger",
|
||||||
bigger(),
|
// "../../out/bigger_sol.png",
|
||||||
20, 20,
|
// bigger(),
|
||||||
color.White, color.Black,
|
// 40, 40,
|
||||||
colorgrad.Warm(),
|
// color.White, color.Black,
|
||||||
},
|
// colorgrad.Warm(),
|
||||||
{
|
// },
|
||||||
"Trivial Bigger Staggered",
|
// {
|
||||||
"trivial-bigger-staggered.png",
|
// "Bigger Staggered",
|
||||||
bigger_staggered(),
|
// "../../out/bigger_staggered_sol.png",
|
||||||
20, 20,
|
// bigger_staggered(),
|
||||||
color.White, color.Black,
|
// 40, 40,
|
||||||
colorgrad.Warm(),
|
// color.White, color.Black,
|
||||||
},
|
// pathGradient,
|
||||||
{
|
// },
|
||||||
"Normal",
|
// {
|
||||||
"normal.png",
|
// "Normal",
|
||||||
normal(),
|
// "../../out/normal_sol.png",
|
||||||
20, 20,
|
// normal(),
|
||||||
color.White, color.Black,
|
// 40, 40,
|
||||||
colorgrad.Warm(),
|
// color.White, color.Black,
|
||||||
},
|
// colorgrad.Warm(),
|
||||||
}
|
// },
|
||||||
|
// }
|
||||||
for _, test := range tests {
|
//
|
||||||
writer := ImageWriter{
|
// for _, test := range tests {
|
||||||
Filename: OUT_DIR + "/" + test.filename,
|
// writer := ImageWriter{
|
||||||
Maze: test.m,
|
// Filename: test.filename,
|
||||||
CellWidth: test.CellWidth,
|
// Maze: test.m,
|
||||||
CellHeight: test.cellHeight,
|
// CellWidth: test.CellWidth,
|
||||||
WallColor: test.wallColor,
|
// CellHeight: test.cellHeight,
|
||||||
PathColor: test.pathColor,
|
// WallColor: test.wallColor,
|
||||||
SolutionGradient: test.gradient,
|
// PathColor: test.pathColor,
|
||||||
}
|
// SolutionGradient: test.gradient,
|
||||||
|
// }
|
||||||
err := writer.Write()
|
//
|
||||||
if err != nil {
|
// err := writer.Write()
|
||||||
t.Fatalf("%s: couldn't write solution, got following error\n%v", test.name, err)
|
// if err != nil {
|
||||||
}
|
// t.Fatalf("%s: couldn't write solution, got following error\n%v", test.name, err)
|
||||||
|
// }
|
||||||
assertEqualFile(t, EXPECTED_DIR+"/"+test.filename, OUT_DIR+"/"+test.filename, test.name)
|
// }
|
||||||
os.Remove(writer.Filename)
|
|
||||||
}
|
|
||||||
os.Remove(OUT_DIR)
|
|
||||||
}
|
|
||||||
|
|
||||||
const chunkSize = 64000
|
|
||||||
|
|
||||||
func assertEqualFile(t *testing.T, file1, file2, name string) {
|
|
||||||
f1, err := os.Open(file1)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer f1.Close()
|
|
||||||
|
|
||||||
f2, err := os.Open(file2)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer f2.Close()
|
|
||||||
|
|
||||||
for {
|
|
||||||
b1 := make([]byte, chunkSize)
|
|
||||||
_, err1 := f1.Read(b1)
|
|
||||||
|
|
||||||
b2 := make([]byte, chunkSize)
|
|
||||||
_, err2 := f2.Read(b2)
|
|
||||||
|
|
||||||
if err1 != nil || err2 != nil {
|
|
||||||
if err1 == io.EOF && err2 == io.EOF {
|
|
||||||
return
|
|
||||||
} else if err1 == io.EOF || err2 == io.EOF {
|
|
||||||
t.Fatalf("%s: files are not equal. Got %q, wanted %q", name, file1, file2)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !bytes.Equal(b1, b2) {
|
|
||||||
t.Fatalf("%s: files are not equal. Got %q, wanted %q", name, file1, file2)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package writer
|
package writer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"maze-solver/maze"
|
"maze-solver/maze"
|
||||||
"maze-solver/utils"
|
"maze-solver/utils"
|
||||||
"testing"
|
"testing"
|
||||||
@ -68,6 +69,7 @@ func TestStringsWriter(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
fmt.Printf("----------- %s -----------\n", test.name)
|
||||||
writer := StringsWriter{
|
writer := StringsWriter{
|
||||||
PathChar: test.pathChar,
|
PathChar: test.pathChar,
|
||||||
WallChar: test.wallChar,
|
WallChar: test.wallChar,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package solver
|
package solver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"maze-solver/maze"
|
"maze-solver/maze"
|
||||||
"maze-solver/utils"
|
"maze-solver/utils"
|
||||||
)
|
)
|
||||||
@ -12,6 +13,9 @@ type DFSSolver struct {
|
|||||||
func (s *DFSSolver) 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))
|
||||||
|
|
||||||
|