From eb1e7a8bc0a76f6337680a42342bb928cd8adea2 Mon Sep 17 00:00:00 2001 From: "Sylvain Rager (regar42)" Date: Thu, 7 Dec 2017 12:24:04 +0100 Subject: [PATCH] Sharpen getCost and improve wallbox handling * Rewrite getCost() from Maze to remove unneeded isWalkable checks on boxes * Return an empty neighbor list for wall boxes (in generateNeighbours() from Maze) --- src/maze/Maze.java | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/maze/Maze.java b/src/maze/Maze.java index 93ce736..34d5cf0 100644 --- a/src/maze/Maze.java +++ b/src/maze/Maze.java @@ -25,17 +25,8 @@ public class Maze Box startBox = (Box) start ; Box endBox = (Box) end ; - - if (startBox.getNeighbourList().contains(endBox)) { - if (startBox.isWalkable() && endBox.isWalkable()) { - return 1 ; - } - else { - return 0 ; - } - } - - return 0 ; + + return startBox.getNeighbourList().contains(endBox) ? 1 : 0 ; } public int getVertexNumber() { @@ -60,7 +51,12 @@ public class Maze int x = box.getX() ; int y = box.getY() ; ArrayList neighbourList = new ArrayList() ; - + + // Always returns an empty list if the departure box is a wall + if (! box.isWalkable()) { + return neighbourList ; + } + if (x > 0 && maze[x-1][y].isWalkable()) { neighbourList.add(maze[x-1][y]) ; } @@ -180,7 +176,6 @@ public class Maze } finally { try { pw.close();} catch(Exception e) {} } - } public int getDimensionX() {