diff --git a/src/model/Board.java b/src/model/Board.java index 184dc54..b87416a 100755 --- a/src/model/Board.java +++ b/src/model/Board.java @@ -37,7 +37,7 @@ public boolean isValidSquare(int row, int col) { * Initialize the board putting checker pieces in their starting locations */ private void init() { - for(int row = 0; row < 3; row++){ + for (int row = 0; row < 3; row++){ for (int col = 0; col < 4; col++) { Piece red_piece = new Piece(Color.RED, 2*col + (row % 2), row); Piece black_piece = new Piece(Color.BLACK, 2*col + (BOARD_SIZE - 1 - row) %2, BOARD_SIZE - 1 - row); @@ -47,11 +47,26 @@ private void init() { } } + /** + * Tests board equality. + * @param other The other board. + * @return true if the board's pieces are all equal to the other board's pieces. + */ + public boolean equals(Board other) { + for (int i = 0; i < BOARD_SIZE; ++i) { + for (int j = 0; j < BOARD_SIZE; ++j) { + if(!(this.representation[i][j]).equals(other.getRepresentation()[i][j])) + return false; + } + } + return true; + } + /** * Print the current board representation */ public void print() { - for(int row = 0; row < BOARD_SIZE; row++) { + for (int row = 0; row < BOARD_SIZE; row++) { for (int col = 0; col < BOARD_SIZE; col++) { if (!isOccupied(row, col)) System.out.print("| "); @@ -62,7 +77,7 @@ else if (representation[row][col].getColor() == Color.RED) { System.out.print("|R"); } else { - if(representation[row][col].getType() == Type.NORMAL) + if (representation[row][col].getType() == Type.NORMAL) System.out.print("|b"); else System.out.print("|B"); @@ -94,6 +109,10 @@ public ArrayList getBlackPieces() { public void setBlackPieces(ArrayList black_pieces) { this.black_pieces = black_pieces; + } + + public Piece[][] getRepresentation() { + return this.representation; } } diff --git a/src/model/Location.java b/src/model/Location.java index 6ea1574..4bb4498 100644 --- a/src/model/Location.java +++ b/src/model/Location.java @@ -13,4 +13,8 @@ public Location(int row, int column) { this.row = row; this.column = column; } + + public boolean equals(Location other) { + return this.row == other.row && this.column == other.column; + } } diff --git a/src/model/Piece.java b/src/model/Piece.java index 0a4f8e6..909c2e8 100755 --- a/src/model/Piece.java +++ b/src/model/Piece.java @@ -36,4 +36,10 @@ public Type getType() { public Color getColor() { return this.color; } + + public boolean equals(Piece other) { + return this.color == other.color && + this.location.equals(other.getLocation()) && + this.type == other.getType(); + } }