Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron committed Apr 21, 2016
2 parents 5662aca + 8540176 commit 30fd758
Showing 1 changed file with 19 additions and 27 deletions.
46 changes: 19 additions & 27 deletions src/model/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,16 @@ public class Board {
private final int BOARD_SIZE = 8;
private Piece[][] representation;

// Pieces available to the Players
private ArrayList<Piece> red_pieces;
private ArrayList<Piece> black_pieces;

// Move properties
private int movesSinceCapture;
public enum Direction {UP, DOWN, LEFT, RIGHT};


public Board() {
representation = new Piece[BOARD_SIZE][BOARD_SIZE];
movesSinceCapture = 0;
init();

}

/**
Expand All @@ -42,18 +40,18 @@ public Board(Board other) {
}
}
movesSinceCapture = other.getMovesSinceCapture();
}
}

public boolean isValidSquare(int row, int col) {
return 0 <= row && row < BOARD_SIZE &&
0 <= col && col < BOARD_SIZE;
public boolean isValidSquare(Location location) {
return 0 <= location.row && location.row < BOARD_SIZE &&
0 <= location.column && location.column < BOARD_SIZE;
}

/**
* 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);
Expand Down Expand Up @@ -179,7 +177,7 @@ public ArrayList<Board> generateFrontier(Color color) {
public void print() {
for (int row = 0; row < BOARD_SIZE; row++) {
for (int col = 0; col < BOARD_SIZE; col++) {
if (!isOccupied(row, col))
if (!isOccupied(new Location(row, col)))
System.out.print("| ");
else if (representation[row][col].getColor() == Color.RED) {
if (representation[row][col].getType() == Type.NORMAL)
Expand All @@ -198,29 +196,23 @@ else if (representation[row][col].getColor() == Color.RED) {
}
}


public boolean isValidJump(Move move) {
Piece monkey = representation[(move.destination.row + move.source.row)/2][(move.destination.column + move.source.column)/2];
Piece toMove = representation[move.source.row][move.source.column];
return isValidSquare(move.destination) && !isOccupied(move.destination)
&& monkey != null
&& monkey.getColor() == toMove.opposite();
}

/**
* return true if square contains a piece
* return false otherwise
*/
public boolean isOccupied(int row, int col) {
return representation[row][col] != null;
public boolean isOccupied(Location location) {
return representation[location.row][location.column] != null;
}

public ArrayList<Piece> getRedPieces() {
return red_pieces;
}

public void setRedPieces(ArrayList<Piece> red_pieces) {
this.red_pieces = red_pieces;
}

public ArrayList<Piece> getBlackPieces() {
return black_pieces;
}

public void setBlackPieces(ArrayList<Piece> black_pieces) {
this.black_pieces = black_pieces;
}

public Piece[][] getRepresentation() {
return this.representation;
Expand Down

0 comments on commit 30fd758

Please sign in to comment.