Skip to content

Commit

Permalink
fixed isValidSquare to comply with row/col standard. refactored curly…
Browse files Browse the repository at this point in the history
… braces.
  • Loading branch information
Aaron committed Apr 20, 2016
1 parent 8e062a8 commit 6f956c9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 58 deletions.
40 changes: 17 additions & 23 deletions src/model/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

/**
* The representation is a 8x8 grid where
* A[y][x] denotes the (x, y) indexed piece.
* It is swapped because we dereference by "row" first,
* which is "y".
* A[row][col] marks the position of the checker piece.
* Smoke starts at lower row and fire starts at higher row.
* @author Ayamin
*
*/
Expand All @@ -28,15 +27,18 @@ public Board() {
movesSinceCapture = 0;
init();
}


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

/**
* Initialize the board putting checker pieces in their starting locations
*/
private void init()
{
private void init() {
for(int row = 0; row < 3; row++){
for (int col = 0; col < 4; col++)
{
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);
representation[row][2*col+ (row % 2)] = red_piece;
Expand All @@ -48,29 +50,23 @@ private void init()
/**
* Print the current board representation
*/
public void print()
{
for(int row = 0; row < BOARD_SIZE; row++)
{
for (int col = 0; col < BOARD_SIZE; col++)
{
public void print() {
for(int row = 0; row < BOARD_SIZE; row++) {
for (int col = 0; col < BOARD_SIZE; col++) {
if (!isOccupied(row, col))
System.out.print("| ");
else if (representation[row][col].getColor() == Color.RED)
{
else if (representation[row][col].getColor() == Color.RED) {
if (representation[row][col].getType() == Type.NORMAL)
System.out.print("|r");
else
System.out.print("|R");
}
else
{
else {
if(representation[row][col].getType() == Type.NORMAL)
System.out.print("|b");
else
System.out.print("|B");
}

}
System.out.println("|");
}
Expand All @@ -80,8 +76,7 @@ else if (representation[row][col].getColor() == Color.RED)
* return true if square contains a piece
* return false otherwise
*/
public boolean isOccupied(int row, int col)
{
public boolean isOccupied(int row, int col) {
return representation[row][col] != null;
}

Expand All @@ -99,7 +94,6 @@ public ArrayList<Piece> getBlackPieces() {

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

}
}

35 changes: 0 additions & 35 deletions src/model/Player.java

This file was deleted.

0 comments on commit 6f956c9

Please sign in to comment.