From 345d9267ad2f745244b3f40f9d91a099ec50ffc0 Mon Sep 17 00:00:00 2001 From: Karma Riuk Date: Sat, 5 Aug 2023 09:38:12 +0200 Subject: [PATCH] moved instructions around to make it more consistent and fixed tiny bug --- io/reader/text.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/io/reader/text.go b/io/reader/text.go index 5b71a91..fe245da 100644 --- a/io/reader/text.go +++ b/io/reader/text.go @@ -64,10 +64,12 @@ func (r *TextReader) Read(filename string) (*maze.Maze, error) { above_char == r.PathChar && (left_char == r.PathChar || right_char == r.PathChar)) { coords := maze.Coordinates{X: x, Y: y} node := maze.NewNode(coords) + + r.lookupNeighbourAbove(&lines, node, &nodesByCoord, ret) + ret.Nodes = append(ret.Nodes, node) nodesByCoord[coords] = node - r.lookupNeighbourAbove(&lines, node, &nodesByCoord, ret) if left_char == r.PathChar && right_char == r.WallChar || above_char == r.PathChar && (left_char == r.PathChar || right_char == r.PathChar) { r.lookupNeighbourLeft(&line, node, &nodesByCoord) @@ -125,7 +127,7 @@ func (r *TextReader) lookupNeighbourAbove(lines *[]string, node *maze.Node, node func (r *TextReader) lookupNeighbourLeft(line *string, node *maze.Node, nodesByCoord *map[maze.Coordinates]*maze.Node) { for x := node.Coords.X - 1; x > 0; x-- { - if (*line)[x] == r.WallChar { + if (*line)[x] == r.WallChar && x < node.Coords.X-1 { panic(fmt.Sprintf("Found no node before wall while looking to the left at neighbours of node %v", node)) }