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)
This commit is contained in:
regar42 committed 2017-12-10 00:02:15 +01:00
1 parent d7368f7cda
commit eb1e7a8bc0
1 file changed
+6 -11
+6 -11
View File
@@ -26,16 +26,7 @@ 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() {
@@ -61,6 +52,11 @@ public class Maze
int y = box.getY() ;
ArrayList<VertexInterface> neighbourList = new ArrayList<VertexInterface>() ;
// 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() {