Merge branch 'fixUnneededCode' into lastDijsktraClasses

This commit was merged in pull request #5.
This commit is contained in:
regar42 committed 2017-12-10 17:48:34 +01:00
commit b59a8436dd
10 files changed
+41 -98

No files matched your search

+1 -1
View File
@@ -3,7 +3,7 @@ package maze;
/**
* <code>ABox</code> is an arrival <code>Box</code>. It's the last <code>Box</code> to be walked through and it's an exit to the <code>Maze</code>.
*/
public class ABox extends Box{
public class ABox extends EBox{
public ABox (String label, int x, int y, Maze maze) {
+4 -36
View File
@@ -1,6 +1,5 @@
package maze;
import java.util.ArrayList;
import java.util.List;
import dijkstra.VertexInterface;
@@ -23,7 +22,7 @@ public abstract class Box
private int y ;
private String label = null ;
private Maze maze ;
private List<Box> neighbourList = new ArrayList<Box>() ;
private ArrayList<Box> neighbourList = new ArrayList<Box>() ;
public Box (String label, int x, int y, Maze maze) {
@@ -34,18 +33,11 @@ public abstract class Box
}
public List<VertexInterface> generateNeighbors() {
public ArrayList<VertexInterface> generateNeighbors() {
return maze.generateNeighbours(this) ;
}
public boolean compareTo(VertexInterface vertex) {
if (this.getLabel() == vertex.getLabel()) {
return true ;
}
return false ;
}
public boolean isWalkable() {
return true ;
}
@@ -58,48 +50,24 @@ public abstract class Box
return false ;
}
public List<Box> getNeighbourList() {
public ArrayList<Box> getNeighbourList() {
return neighbourList;
}
public void setNeighbourList(List<Box> neighbourList) {
this.neighbourList = neighbourList;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public Maze getMaze() {
return maze;
}
public void setMaze(Maze maze) {
this.maze = maze;
}
public String toString() {
return label;
return "Label: " + label + ", x: " + x + ", y: " + y;
}
}
+1 -1
View File
@@ -4,7 +4,7 @@ package maze;
* A <code>DBox</code> is the <code>Box</code> on which the user is first in the <code>Maze</code>.
*/
public class DBox extends Box{
public class DBox extends EBox{
public DBox (String label, int x, int y, Maze maze) {
+15 -30
View File
@@ -29,24 +29,18 @@ public class Maze
}
/**
*
*/
// public Maze(Box[][] maze){
// //Replacement for setMaze()
// //Todo : check if the given array is a proper maze
// //and then set dimensionX and dimensionX
// }
public int getCost(VertexInterface start, VertexInterface end) {
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() {
@@ -71,7 +65,12 @@ public class Maze
int x = box.getX() ;
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]) ;
}
@@ -97,7 +96,7 @@ public class Maze
* The path to the file containing the representation of the maze.
*/
public final void initFromTextFile(String filename) {
private final void initFromTextFile(String filename) {
FileReader fr = null ;
BufferedReader br = null ;
@@ -193,32 +192,18 @@ public class Maze
} finally {
try { pw.close();} catch(Exception e) {}
}
}
public int getDimensionX() {
return dimensionX;
}
public void setDimensionX(int dimensionX) {
this.dimensionX = dimensionX;
}
public int getDimensionY() {
return dimensionY;
}
public void setDimensionY(int dimensionY) {
this.dimensionY = dimensionY;
}
public Box[][] getMaze() {
return maze;
}
public void setMaze(Box[][] maze) {
this.maze = maze;
}
}
+1 -6
View File
@@ -10,17 +10,12 @@ package maze;
public class MazeReadingException
extends Exception {
private String filename ;
private static final long serialVersionUID = 1L;
public MazeReadingException (String filename) {
super("Invalid maze format : " + filename) ;
this.filename = filename ;
}
public String getFilename() {
return filename ;
}
}