Compare commits
No commits in common. "b6dff509f9341c0acb2f722b844cd7380a702b5d" and "8b0fa4c1f9e0c6b18d24dc443cb482217d2c53cf" have entirely different histories.
b6dff509f9
...
8b0fa4c1f9
@ -30,7 +30,10 @@ func Parse(reader reader.Reader) (*maze.Maze, error) {
|
|||||||
for y = 1; y < raw_maze.Height-1; y++ {
|
for y = 1; y < raw_maze.Height-1; y++ {
|
||||||
for x := 1; x < raw_maze.Width-1; x++ {
|
for x := 1; x < raw_maze.Width-1; x++ {
|
||||||
// Parse middle of the maze
|
// Parse middle of the maze
|
||||||
if isCoordEligibleForNode(x, y, raw_maze) {
|
if raw_maze.IsPath(x, y) &&
|
||||||
|
(raw_maze.IsWall(x-1, y) && raw_maze.IsPath(x+1, y) ||
|
||||||
|
raw_maze.IsPath(x-1, y) && raw_maze.IsWall(x+1, y) ||
|
||||||
|
raw_maze.IsPath(x, y-1) && (raw_maze.IsPath(x-1, y) || raw_maze.IsPath(x+1, y))) {
|
||||||
coords := maze.Coordinates{X: x, Y: y}
|
coords := maze.Coordinates{X: x, Y: y}
|
||||||
node := maze.NewNode(coords)
|
node := maze.NewNode(coords)
|
||||||
|
|
||||||
@ -40,8 +43,7 @@ func Parse(reader reader.Reader) (*maze.Maze, error) {
|
|||||||
nodesByCoord[coords] = node
|
nodesByCoord[coords] = node
|
||||||
|
|
||||||
if raw_maze.IsPath(x-1, y) && raw_maze.IsWall(x+1, y) ||
|
if raw_maze.IsPath(x-1, y) && raw_maze.IsWall(x+1, y) ||
|
||||||
raw_maze.IsPath(x, y-1) &&
|
raw_maze.IsPath(x, y-1) && (raw_maze.IsPath(x-1, y) || raw_maze.IsPath(x+1, y)) {
|
||||||
(raw_maze.IsPath(x-1, y) || raw_maze.IsPath(x+1, y)) {
|
|
||||||
lookupNeighbourLeft(raw_maze, node, &nodesByCoord)
|
lookupNeighbourLeft(raw_maze, node, &nodesByCoord)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -62,14 +64,6 @@ func Parse(reader reader.Reader) (*maze.Maze, error) {
|
|||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func isCoordEligibleForNode(x int, y int, raw_maze *reader.RawMaze) bool {
|
|
||||||
return raw_maze.IsPath(x, y) &&
|
|
||||||
(raw_maze.IsWall(x-1, y) && raw_maze.IsPath(x+1, y) || // wall left, path right
|
|
||||||
raw_maze.IsPath(x-1, y) && raw_maze.IsWall(x+1, y) || // path left, wall right
|
|
||||||
raw_maze.IsPath(x, y-1) && (raw_maze.IsPath(x-1, y) || raw_maze.IsPath(x+1, y)) || // path above and not in vertical corridor
|
|
||||||
raw_maze.IsWall(x-1, y) && raw_maze.IsWall(x+1, y) && raw_maze.IsPath(x, y-1) && raw_maze.IsWall(x, y+1)) // wall to left, below, above and path above
|
|
||||||
}
|
|
||||||
|
|
||||||
func lookupNeighbourAbove(raw_maze *reader.RawMaze, node *maze.Node, nodesByCoord *map[maze.Coordinates]*maze.Node, m *maze.Maze) {
|
func lookupNeighbourAbove(raw_maze *reader.RawMaze, node *maze.Node, nodesByCoord *map[maze.Coordinates]*maze.Node, m *maze.Maze) {
|
||||||
for y := node.Coords.Y - 1; y >= 0; y-- {
|
for y := node.Coords.Y - 1; y >= 0; y-- {
|
||||||
neighbour, ok := (*nodesByCoord)[maze.Coordinates{X: node.Coords.X, Y: y}]
|
neighbour, ok := (*nodesByCoord)[maze.Coordinates{X: node.Coords.X, Y: y}]
|
||||||
@ -103,7 +97,7 @@ 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) {
|
func lookupNeighbourLeft(raw_maze *reader.RawMaze, node *maze.Node, nodesByCoord *map[maze.Coordinates]*maze.Node) {
|
||||||
for x := node.Coords.X - 1; x > 0; x-- {
|
for x := node.Coords.X - 1; x > 0; x-- {
|
||||||
if raw_maze.IsWall(x, node.Coords.Y) && x < node.Coords.X-1 {
|
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))
|
panic(fmt.Sprintf("Found no node before wall while looking to the left at neighbours of node %v", node))
|
||||||
}
|
}
|
||||||
|
|
||||||
neighbour, ok := (*nodesByCoord)[maze.Coordinates{X: x, Y: node.Coords.Y}]
|
neighbour, ok := (*nodesByCoord)[maze.Coordinates{X: x, Y: node.Coords.Y}]
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestTextReadTrivial(t *testing.T) {
|
func TestTextReadTrivial(t *testing.T) {
|
||||||
|
fmt.Println("---------- Trivial ----------")
|
||||||
/* trivial.txt
|
/* trivial.txt
|
||||||
## ##
|
## ##
|
||||||
# #
|
# #
|
||||||
@ -67,6 +68,7 @@ func TestTextReadTrivial(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestTextReadTrivialBigger(t *testing.T) {
|
func TestTextReadTrivialBigger(t *testing.T) {
|
||||||
|
fmt.Println("---------- Trivial Bigger ----------")
|
||||||
/* trivial-bigger.txt
|
/* trivial-bigger.txt
|
||||||
### ###
|
### ###
|
||||||
### ###
|
### ###
|
||||||
@ -117,6 +119,10 @@ func TestTextReadTrivialBigger(t *testing.T) {
|
|||||||
t.Fatalf("Didn't get the same size of nodes: %v, want %v", len(got.Nodes), len(nodes))
|
t.Fatalf("Didn't get the same size of nodes: %v, want %v", len(got.Nodes), len(nodes))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, node := range got.Nodes {
|
||||||
|
fmt.Println(node)
|
||||||
|
}
|
||||||
|
|
||||||
for i, got := range got.Nodes {
|
for i, got := range got.Nodes {
|
||||||
expected := nodes[i]
|
expected := nodes[i]
|
||||||
|
|
||||||
@ -129,6 +135,7 @@ func TestTextReadTrivialBigger(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestTextReadTrivialBiggerStaggered(t *testing.T) {
|
func TestTextReadTrivialBiggerStaggered(t *testing.T) {
|
||||||
|
fmt.Println("---------- Trivial Staggered ----------")
|
||||||
/* trivial-bigger-staggered.txt
|
/* trivial-bigger-staggered.txt
|
||||||
### ###
|
### ###
|
||||||
### ###
|
### ###
|
||||||
@ -184,6 +191,10 @@ func TestTextReadTrivialBiggerStaggered(t *testing.T) {
|
|||||||
t.Fatalf("Didn't get the same size of nodes: %v, want %v", len(got.Nodes), len(nodes))
|
t.Fatalf("Didn't get the same size of nodes: %v, want %v", len(got.Nodes), len(nodes))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, node := range got.Nodes {
|
||||||
|
fmt.Println(node)
|
||||||
|
}
|
||||||
|
|
||||||
for i, got := range got.Nodes {
|
for i, got := range got.Nodes {
|
||||||
expected := nodes[i]
|
expected := nodes[i]
|
||||||
|
|
||||||
@ -196,6 +207,8 @@ func TestTextReadTrivialBiggerStaggered(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestTextReadNormal(t *testing.T) {
|
func TestTextReadNormal(t *testing.T) {
|
||||||
|
return
|
||||||
|
fmt.Println("---------- Normal ----------")
|
||||||
/* trivial-bigger-staggered.txt
|
/* trivial-bigger-staggered.txt
|
||||||
##### #####
|
##### #####
|
||||||
# # #
|
# # #
|
||||||
@ -215,9 +228,9 @@ func TestTextReadNormal(t *testing.T) {
|
|||||||
##### ### #
|
##### ### #
|
||||||
#5 6#7 8#
|
#5 6#7 8#
|
||||||
# # ##### #
|
# # ##### #
|
||||||
#9#A F B#
|
#9#A G B#
|
||||||
### ### # #
|
### ### # #
|
||||||
#C D#E G# #
|
#C D#E F# #
|
||||||
# ####### #
|
# ####### #
|
||||||
#H I#J K#
|
#H I#J K#
|
||||||
#####L#####
|
#####L#####
|
||||||
@ -241,13 +254,13 @@ func TestTextReadNormal(t *testing.T) {
|
|||||||
|
|
||||||
{1, 5}, // 9
|
{1, 5}, // 9
|
||||||
{3, 5}, // A (10)
|
{3, 5}, // A (10)
|
||||||
|
{7, 5}, // G (16)
|
||||||
{9, 5}, // B (11)
|
{9, 5}, // B (11)
|
||||||
|
|
||||||
{1, 7}, // C (12)
|
{1, 7}, // C (12)
|
||||||
{3, 7}, // D (13)
|
{3, 7}, // D (13)
|
||||||
{5, 7}, // E (14)
|
{5, 7}, // E (14)
|
||||||
{7, 5}, // F (15)
|
{7, 7}, // F (15)
|
||||||
{7, 7}, // G (16)
|
|
||||||
|
|
||||||
{1, 9}, // H (17)
|
{1, 9}, // H (17)
|
||||||
{5, 9}, // I (18)
|
{5, 9}, // I (18)
|
||||||
@ -290,27 +303,27 @@ func TestTextReadNormal(t *testing.T) {
|
|||||||
nodes[9].Up = nodes[5]
|
nodes[9].Up = nodes[5]
|
||||||
|
|
||||||
nodes[10].Up = nodes[6]
|
nodes[10].Up = nodes[6]
|
||||||
nodes[10].Right = nodes[15]
|
nodes[10].Right = nodes[16]
|
||||||
nodes[10].Down = nodes[13]
|
nodes[10].Down = nodes[13]
|
||||||
|
|
||||||
nodes[11].Up = nodes[8]
|
nodes[11].Up = nodes[6]
|
||||||
nodes[11].Left = nodes[15]
|
nodes[11].Right = nodes[16]
|
||||||
nodes[11].Down = nodes[20]
|
nodes[11].Down = nodes[20]
|
||||||
|
|
||||||
nodes[12].Right = nodes[13]
|
nodes[12].Right = nodes[13]
|
||||||
nodes[12].Down = nodes[17]
|
nodes[12].Down = nodes[17]
|
||||||
|
|
||||||
nodes[13].Up = nodes[10]
|
nodes[13].Up = nodes[10]
|
||||||
nodes[13].Left = nodes[12]
|
nodes[13].Left = nodes[16]
|
||||||
|
|
||||||
nodes[14].Right = nodes[16]
|
nodes[14].Right = nodes[15]
|
||||||
|
|
||||||
nodes[15].Left = nodes[10]
|
nodes[15].Up = nodes[16]
|
||||||
nodes[15].Right = nodes[11]
|
nodes[15].Left = nodes[14]
|
||||||
nodes[15].Down = nodes[16]
|
|
||||||
|
|
||||||
nodes[16].Up = nodes[15]
|
nodes[16].Left = nodes[10]
|
||||||
nodes[16].Left = nodes[14]
|
nodes[16].Right = nodes[11]
|
||||||
|
nodes[16].Down = nodes[15]
|
||||||
|
|
||||||
nodes[17].Up = nodes[12]
|
nodes[17].Up = nodes[12]
|
||||||
nodes[17].Right = nodes[18]
|
nodes[17].Right = nodes[18]
|
||||||
@ -323,7 +336,7 @@ func TestTextReadNormal(t *testing.T) {
|
|||||||
nodes[20].Up = nodes[11]
|
nodes[20].Up = nodes[11]
|
||||||
nodes[20].Left = nodes[19]
|
nodes[20].Left = nodes[19]
|
||||||
|
|
||||||
nodes[21].Up = nodes[18]
|
nodes[21].Up = nodes[20]
|
||||||
|
|
||||||
reader := reader.TextReader{
|
reader := reader.TextReader{
|
||||||
Filename: "../../assets/normal.txt",
|
Filename: "../../assets/normal.txt",
|
||||||
@ -341,6 +354,10 @@ func TestTextReadNormal(t *testing.T) {
|
|||||||
t.Fatalf("Didn't get the same size of nodes: %v, want %v", len(got.Nodes), len(nodes))
|
t.Fatalf("Didn't get the same size of nodes: %v, want %v", len(got.Nodes), len(nodes))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, node := range got.Nodes {
|
||||||
|
fmt.Println(node)
|
||||||
|
}
|
||||||
|
|
||||||
for i, got := range got.Nodes {
|
for i, got := range got.Nodes {
|
||||||
expected := nodes[i]
|
expected := nodes[i]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user