Corrected some bugs for when it came to parsing
and writing mazes
This commit is contained in:
parent
3ef61967a5
commit
42cc4f8717
@ -56,17 +56,28 @@ func (w *ImageWriter) Write() error {
|
||||
width, height = w.CellWidth, w.CellHeight
|
||||
for i, from := range w.Maze.Solution[:len(w.Maze.Solution)-1] {
|
||||
to := w.Maze.Solution[i+1]
|
||||
|
||||
if from.Coords.X == to.Coords.X {
|
||||
// Fill verticallly
|
||||
x0 = from.Coords.X * w.CellWidth
|
||||
|
||||
if from.Coords.Y < to.Coords.Y {
|
||||
for y := from.Coords.Y; y < to.Coords.Y; y++ {
|
||||
y0 = y * w.CellHeight
|
||||
w.draw(x0, y0, width, height, colors[c])
|
||||
c++
|
||||
}
|
||||
} else {
|
||||
for y := from.Coords.Y; y > to.Coords.Y; y-- {
|
||||
y0 = y * w.CellHeight
|
||||
w.draw(x0, y0, width, height, colors[c])
|
||||
c++
|
||||
}
|
||||
}
|
||||
y0 = to.Coords.Y * w.CellHeight
|
||||
w.draw(x0, y0, width, height, colors[c])
|
||||
} else {
|
||||
// Fill horizontally
|
||||
y0 = from.Coords.Y * w.CellHeight
|
||||
|
||||
if from.Coords.X < to.Coords.X {
|
||||
|
@ -58,6 +58,9 @@ func (w *StringsWriter) fillHorizontally(from maze.Coordinates, to maze.Coordina
|
||||
|
||||
func (w *StringsWriter) fillVertically(from maze.Coordinates, to maze.Coordinates, char byte) {
|
||||
x := from.X
|
||||
if from.Y > to.Y {
|
||||
from, to = to, from
|
||||
}
|
||||
for y := from.Y; y <= to.Y; y++ {
|
||||
w.lines[y][x] = char
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ func lookupNeighbourAbove(raw_maze *reader.RawMaze, node *maze.Node, nodesByCoor
|
||||
break
|
||||
}
|
||||
|
||||
if y > 0 && raw_maze.IsWall(node.Coords.X, y) {
|
||||
if y >= 0 && raw_maze.IsWall(node.Coords.X, y) {
|
||||
y++
|
||||
if y == node.Coords.Y {
|
||||
break
|
||||
@ -107,6 +107,10 @@ func lookupNeighbourAbove(raw_maze *reader.RawMaze, node *maze.Node, nodesByCoor
|
||||
|
||||
func lookupNeighbourLeft(raw_maze *reader.RawMaze, node *maze.Node, nodesByCoord *map[maze.Coordinates]*maze.Node) {
|
||||
for x := node.Coords.X - 1; x > 0; x-- {
|
||||
if raw_maze.IsWall(x, node.Coords.Y) && x == node.Coords.X-1 {
|
||||
return
|
||||
}
|
||||
|
||||
if raw_maze.IsWall(x, node.Coords.Y) && x < node.Coords.X-1 {
|
||||
panic(fmt.Sprintf("Found no node before wall while looking to the left at neighbours of node %v (arrived at x=%v before hitting a wall)", node, x))
|
||||
}
|
||||
@ -122,7 +126,11 @@ func lookupNeighbourLeft(raw_maze *reader.RawMaze, node *maze.Node, nodesByCoord
|
||||
|
||||
func lookupNeighbourRight(raw_maze *reader.RawMaze, node *maze.Node, nodesByCoord *map[maze.Coordinates]*maze.Node) {
|
||||
for x := node.Coords.X + 1; x < raw_maze.Width; x++ {
|
||||
if raw_maze.IsWall(x, node.Coords.Y) {
|
||||
if raw_maze.IsWall(x, node.Coords.Y) && x == node.Coords.X+1 {
|
||||
return
|
||||
}
|
||||
|
||||
if raw_maze.IsWall(x, node.Coords.Y) && x > node.Coords.X+1 {
|
||||
panic(fmt.Sprintf("Found no node before wall while looking to the right at neighbours of node %v", node))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user