- Diagonal lines are no longer removed.
This commit is contained in:
@@ -17,16 +17,6 @@ public class Board {
|
||||
// a Ply is a play by 1 side. Increments each time setTile() is called.
|
||||
private int numPlies = 0;
|
||||
|
||||
public Board(Board that) {
|
||||
board = new TileColor[NUM_ROWS][NUM_COLS];
|
||||
|
||||
for (int r = 0; r < NUM_ROWS; r++) {
|
||||
for (int c = 0; c < NUM_COLS; c++) {
|
||||
this.board[r][c] = that.board[r][c];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Board() {
|
||||
board = new TileColor[NUM_ROWS][NUM_COLS];
|
||||
for (int r = 0; r < NUM_ROWS; r++) {
|
||||
@@ -36,12 +26,14 @@ public class Board {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + Arrays.hashCode(board);
|
||||
return result;
|
||||
public Board(Board that) {
|
||||
board = new TileColor[NUM_ROWS][NUM_COLS];
|
||||
|
||||
for (int r = 0; r < NUM_ROWS; r++) {
|
||||
for (int c = 0; c < NUM_COLS; c++) {
|
||||
this.board[r][c] = that.board[r][c];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,6 +65,14 @@ public class Board {
|
||||
return numPlies / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + Arrays.hashCode(board);
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean isPlayerTurn() {
|
||||
return numPlies % 2 == 0;
|
||||
}
|
||||
@@ -91,9 +91,9 @@ public class Board {
|
||||
|
||||
public boolean playTile(CellPointer cp, TileColor tile) {
|
||||
if (board[cp.r][cp.c] != TileColor.NONE) {
|
||||
return false; //illegal move
|
||||
return false; // illegal move
|
||||
}
|
||||
|
||||
|
||||
board[cp.r][cp.c] = tile;
|
||||
|
||||
if (tile != TileColor.NONE) {
|
||||
@@ -151,76 +151,79 @@ public class Board {
|
||||
remove.addAll(hold);
|
||||
}
|
||||
|
||||
// We decided to get rid of diagonals. If we ever decide to bring
|
||||
// them back, all we have to do is un-comment this code.
|
||||
|
||||
// Check descending diagonal.
|
||||
count = 0;
|
||||
hold = new ArrayList<CellPointer>();
|
||||
int row = cp.r;
|
||||
int col = cp.c;
|
||||
loop: while (row >= 0 && col >= 0) {
|
||||
if (board[row][col] == tile) {
|
||||
hold.add(new CellPointer(row, col));
|
||||
count++;
|
||||
} else {
|
||||
break loop;
|
||||
}
|
||||
|
||||
row--;
|
||||
col--;
|
||||
}
|
||||
|
||||
row = cp.r + 1;
|
||||
col = cp.c + 1;
|
||||
loop: while (row < NUM_ROWS && col < NUM_COLS) {
|
||||
if (board[row][col] == tile) {
|
||||
hold.add(new CellPointer(row, col));
|
||||
count++;
|
||||
} else {
|
||||
break loop;
|
||||
}
|
||||
|
||||
row++;
|
||||
col++;
|
||||
}
|
||||
|
||||
if (count >= ROW_REMOVAL_SIZE) {
|
||||
remove.addAll(hold);
|
||||
}
|
||||
|
||||
// Check ascending diagonal.
|
||||
count = 0;
|
||||
hold = new ArrayList<CellPointer>();
|
||||
|
||||
row = cp.r;
|
||||
col = cp.c;
|
||||
loop: while (row < NUM_ROWS && col >= 0) {
|
||||
if (board[row][col] == tile) {
|
||||
hold.add(new CellPointer(row, col));
|
||||
count++;
|
||||
} else {
|
||||
break loop;
|
||||
}
|
||||
|
||||
row++;
|
||||
col--;
|
||||
}
|
||||
|
||||
row = cp.r - 1;
|
||||
col = cp.c + 1;
|
||||
loop: while (row >= 0 && col < NUM_COLS) {
|
||||
if (board[row][col] == tile) {
|
||||
hold.add(new CellPointer(row, col));
|
||||
count++;
|
||||
} else {
|
||||
break loop;
|
||||
}
|
||||
|
||||
row--;
|
||||
col++;
|
||||
}
|
||||
|
||||
if (count >= ROW_REMOVAL_SIZE) {
|
||||
remove.addAll(hold);
|
||||
}
|
||||
// count = 0;
|
||||
// hold = new ArrayList<CellPointer>();
|
||||
// int row = cp.r;
|
||||
// int col = cp.c;
|
||||
// loop: while (row >= 0 && col >= 0) {
|
||||
// if (board[row][col] == tile) {
|
||||
// hold.add(new CellPointer(row, col));
|
||||
// count++;
|
||||
// } else {
|
||||
// break loop;
|
||||
// }
|
||||
//
|
||||
// row--;
|
||||
// col--;
|
||||
// }
|
||||
//
|
||||
// row = cp.r + 1;
|
||||
// col = cp.c + 1;
|
||||
// loop: while (row < NUM_ROWS && col < NUM_COLS) {
|
||||
// if (board[row][col] == tile) {
|
||||
// hold.add(new CellPointer(row, col));
|
||||
// count++;
|
||||
// } else {
|
||||
// break loop;
|
||||
// }
|
||||
//
|
||||
// row++;
|
||||
// col++;
|
||||
// }
|
||||
//
|
||||
// if (count >= ROW_REMOVAL_SIZE) {
|
||||
// remove.addAll(hold);
|
||||
// }
|
||||
//
|
||||
// // Check ascending diagonal.
|
||||
// count = 0;
|
||||
// hold = new ArrayList<CellPointer>();
|
||||
//
|
||||
// row = cp.r;
|
||||
// col = cp.c;
|
||||
// loop: while (row < NUM_ROWS && col >= 0) {
|
||||
// if (board[row][col] == tile) {
|
||||
// hold.add(new CellPointer(row, col));
|
||||
// count++;
|
||||
// } else {
|
||||
// break loop;
|
||||
// }
|
||||
//
|
||||
// row++;
|
||||
// col--;
|
||||
// }
|
||||
//
|
||||
// row = cp.r - 1;
|
||||
// col = cp.c + 1;
|
||||
// loop: while (row >= 0 && col < NUM_COLS) {
|
||||
// if (board[row][col] == tile) {
|
||||
// hold.add(new CellPointer(row, col));
|
||||
// count++;
|
||||
// } else {
|
||||
// break loop;
|
||||
// }
|
||||
//
|
||||
// row--;
|
||||
// col++;
|
||||
// }
|
||||
//
|
||||
// if (count >= ROW_REMOVAL_SIZE) {
|
||||
// remove.addAll(hold);
|
||||
// }
|
||||
|
||||
for (CellPointer cell : remove) {
|
||||
board[cell.r][cell.c] = TileColor.NONE;
|
||||
@@ -230,7 +233,7 @@ public class Board {
|
||||
numPlies++;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
|
||||
Reference in New Issue
Block a user