Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
4f79d6f1ed | |||
346cfe9705 | |||
94af003adc | |||
aec655610a | |||
2423645f3a | |||
6e0a1032d1 | |||
69afaed1bf | |||
908e8c14fb | |||
954d44085c | |||
8a6543cc1e |
19
.github/workflows/automatic-prerelease.yml
vendored
@ -12,10 +12,18 @@ jobs:
|
|||||||
runs-on: "ubuntu-latest"
|
runs-on: "ubuntu-latest"
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
# ...
|
- uses: actions/checkout@v3
|
||||||
- name: "Build & test"
|
|
||||||
run: |
|
- name: Set up Go
|
||||||
echo "done!"
|
uses: actions/setup-go@v4
|
||||||
|
with:
|
||||||
|
go-version: "1.21"
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: go build -v ./...
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: go test -v ./...
|
||||||
|
|
||||||
- uses: "marvinpinto/action-automatic-releases@latest"
|
- uses: "marvinpinto/action-automatic-releases@latest"
|
||||||
with:
|
with:
|
||||||
@ -23,6 +31,3 @@ jobs:
|
|||||||
automatic_release_tag: "latest"
|
automatic_release_tag: "latest"
|
||||||
prerelease: true
|
prerelease: true
|
||||||
title: "Development Build"
|
title: "Development Build"
|
||||||
files: |
|
|
||||||
LICENSE.txt
|
|
||||||
*.jar
|
|
||||||
|
19
.github/workflows/tagged-release.yml
vendored
@ -12,15 +12,20 @@ jobs:
|
|||||||
runs-on: "ubuntu-latest"
|
runs-on: "ubuntu-latest"
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
# ...
|
- uses: actions/checkout@v3
|
||||||
- name: "Build & test"
|
|
||||||
run: |
|
- name: Set up Go
|
||||||
echo "done!"
|
uses: actions/setup-go@v4
|
||||||
|
with:
|
||||||
|
go-version: "1.21"
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: go build -v ./...
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: go test -v ./...
|
||||||
|
|
||||||
- uses: "marvinpinto/action-automatic-releases@latest"
|
- uses: "marvinpinto/action-automatic-releases@latest"
|
||||||
with:
|
with:
|
||||||
repo_token: "${{ secrets.GITHUB_TOKEN }}"
|
repo_token: "${{ secrets.GITHUB_TOKEN }}"
|
||||||
prerelease: false
|
prerelease: false
|
||||||
files: |
|
|
||||||
LICENSE.txt
|
|
||||||
*.jar
|
|
||||||
|
2
.gitignore
vendored
@ -20,3 +20,5 @@
|
|||||||
# Go workspace file
|
# Go workspace file
|
||||||
go.work
|
go.work
|
||||||
/Session.vim
|
/Session.vim
|
||||||
|
/maze.png
|
||||||
|
/maze_sol.png
|
||||||
|
BIN
assets/real.png
Normal file
After Width: | Height: | Size: 151 KiB |
BIN
assets/solved/normal.png
Normal file
After Width: | Height: | Size: 987 B |
BIN
assets/solved/normal2.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
assets/solved/real.png
Normal file
After Width: | Height: | Size: 316 KiB |
BIN
assets/solved/trivial-bigger-staggered.png
Normal file
After Width: | Height: | Size: 424 B |
BIN
assets/solved/trivial-bigger.png
Normal file
After Width: | Height: | Size: 423 B |
BIN
assets/solved/trivial.png
Normal file
After Width: | Height: | Size: 286 B |
@ -1,17 +1,24 @@
|
|||||||
package writer
|
package writer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
"io"
|
||||||
"maze-solver/maze"
|
"maze-solver/maze"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/mazznoer/colorgrad"
|
"github.com/mazznoer/colorgrad"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
OUT_DIR = "./out"
|
||||||
|
EXPECTED_DIR = "../../assets/solved"
|
||||||
|
)
|
||||||
|
|
||||||
func TestImageWriter(t *testing.T) {
|
func TestImageWriter(t *testing.T) {
|
||||||
pathGradient, err := colorgrad.NewGradient().Colors(color.White).Build()
|
if _, err := os.Stat(OUT_DIR); os.IsNotExist(err) {
|
||||||
if err != nil {
|
os.Mkdir(OUT_DIR, 0700)
|
||||||
panic(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
@ -24,33 +31,33 @@ func TestImageWriter(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"Trivial",
|
"Trivial",
|
||||||
"../../out/trivial_sol.png",
|
"trivial.png",
|
||||||
trivial(),
|
trivial(),
|
||||||
40, 40,
|
20, 20,
|
||||||
color.White, color.Black,
|
color.White, color.Black,
|
||||||
colorgrad.Warm(),
|
colorgrad.Warm(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Bigger",
|
"Trivial Bigger",
|
||||||
"../../out/bigger_sol.png",
|
"trivial-bigger.png",
|
||||||
bigger(),
|
bigger(),
|
||||||
40, 40,
|
20, 20,
|
||||||
color.White, color.Black,
|
color.White, color.Black,
|
||||||
colorgrad.Warm(),
|
colorgrad.Warm(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Bigger Staggered",
|
"Trivial Bigger Staggered",
|
||||||
"../../out/bigger_staggered_sol.png",
|
"trivial-bigger-staggered.png",
|
||||||
bigger_staggered(),
|
bigger_staggered(),
|
||||||
40, 40,
|
20, 20,
|
||||||
color.White, color.Black,
|
color.White, color.Black,
|
||||||
pathGradient,
|
colorgrad.Warm(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Normal",
|
"Normal",
|
||||||
"../../out/normal_sol.png",
|
"normal.png",
|
||||||
normal(),
|
normal(),
|
||||||
40, 40,
|
20, 20,
|
||||||
color.White, color.Black,
|
color.White, color.Black,
|
||||||
colorgrad.Warm(),
|
colorgrad.Warm(),
|
||||||
},
|
},
|
||||||
@ -58,7 +65,7 @@ func TestImageWriter(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
writer := ImageWriter{
|
writer := ImageWriter{
|
||||||
Filename: test.filename,
|
Filename: OUT_DIR + "/" + test.filename,
|
||||||
Maze: test.m,
|
Maze: test.m,
|
||||||
CellWidth: test.CellWidth,
|
CellWidth: test.CellWidth,
|
||||||
CellHeight: test.cellHeight,
|
CellHeight: test.cellHeight,
|
||||||
@ -71,5 +78,45 @@ func TestImageWriter(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("%s: couldn't write solution, got following error\n%v", test.name, err)
|
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,7 +1,6 @@
|
|||||||
package writer
|
package writer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"maze-solver/maze"
|
"maze-solver/maze"
|
||||||
"maze-solver/utils"
|
"maze-solver/utils"
|
||||||
"testing"
|
"testing"
|
||||||
@ -69,7 +68,6 @@ 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,
|
||||||
|
@ -5,11 +5,11 @@ import (
|
|||||||
"maze-solver/utils"
|
"maze-solver/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TurnLeftSolver struct {
|
type DFSSolver struct {
|
||||||
visited map[*maze.Node]bool
|
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)()
|
defer utils.Timer("Turn left algorithm", 2)()
|
||||||
|
|
||||||
current, end := m.Nodes[0], m.Nodes[len(m.Nodes)-1]
|
current, end := m.Nodes[0], m.Nodes[len(m.Nodes)-1]
|
||||||
@ -54,7 +54,7 @@ func (s *TurnLeftSolver) Solve(m *maze.Maze) *maze.SolvedMaze {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *TurnLeftSolver) wasVisited(node *maze.Node) bool {
|
func (s *DFSSolver) wasVisited(node *maze.Node) bool {
|
||||||
if node == nil {
|
if node == nil {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
@ -24,7 +24,7 @@ var TYPES = []string{
|
|||||||
func (f *SolverFactory) Get() Solver {
|
func (f *SolverFactory) Get() Solver {
|
||||||
switch *f.Type {
|
switch *f.Type {
|
||||||
case _TURN_LEFT:
|
case _TURN_LEFT:
|
||||||
return &TurnLeftSolver{}
|
return &DFSSolver{}
|
||||||
}
|
}
|
||||||
panic(fmt.Sprintf("Unrecognized solver type %q", *f.Type))
|
panic(fmt.Sprintf("Unrecognized solver type %q", *f.Type))
|
||||||
}
|
}
|
||||||
|