Skip to content

Commit

Permalink
Added comments and improved readability
Browse files Browse the repository at this point in the history
  • Loading branch information
Domenick D'Onofrio committed Mar 29, 2016
1 parent 799d9ae commit e007286
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
24 changes: 18 additions & 6 deletions src/model/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public enum Direction {UP, DOWN, LEFT, RIGHT};
public Board() {
representation = new Piece[BOARD_SIZE][BOARD_SIZE];
movesSinceCapture = 0;
initBoard();
init();
}

public boolean isValidSquare(int i, int j) {
Expand All @@ -27,6 +27,7 @@ public boolean isValidSquare(int i, int j) {

/**
* Checks if a piece can attack another in a given direction.
*
* @param p The piece.
* @param X The direction along the x-coordinate (LEFT or RIGHT).
* @param Y The direction along the y-coordinate (UP or DOWN).
Expand Down Expand Up @@ -56,6 +57,7 @@ public boolean checkAttackDirection(Piece p, Direction X, Direction Y) {
* that move is invalid because the player can keep on attacking.
* We go by the convention that black starts out at the "bottom", and
* red starts out at the "top". Smoke moves before fire.
*
* @param p
* @return
*/
Expand All @@ -71,8 +73,11 @@ public boolean hasAttackVector(Piece p) {
}
return can_attack;
}

private void initBoard()

/**
* Initialize the board putting checker pieces in their starting locations
*/
private void init()
{
for(int row = 0; row < 3; row++){
for (int col = 0; col < 4; col++)
Expand All @@ -84,8 +89,11 @@ private void initBoard()
}
}
}

public void printBoard()

/**
* Print the current board representation
*/
public void print()
{
for(int row = 0; row < BOARD_SIZE; row++)
{
Expand All @@ -112,7 +120,11 @@ else if (representation[row][col].getColor() == Color.RED)
System.out.println("|");
}
}


/**
* return true if square contains a piece
* return false otherwise
*/
public boolean isOccupied(int row, int col)
{
return representation[row][col] != null;
Expand Down
2 changes: 1 addition & 1 deletion src/test/BoardTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class BoardTest {

public static void main(String[]args) {
Board checkers = new Board();
checkers.printBoard();
checkers.print();
}
}

0 comments on commit e007286

Please sign in to comment.