- 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.
|
// a Ply is a play by 1 side. Increments each time setTile() is called.
|
||||||
private int numPlies = 0;
|
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() {
|
public Board() {
|
||||||
board = new TileColor[NUM_ROWS][NUM_COLS];
|
board = new TileColor[NUM_ROWS][NUM_COLS];
|
||||||
for (int r = 0; r < NUM_ROWS; r++) {
|
for (int r = 0; r < NUM_ROWS; r++) {
|
||||||
@@ -36,12 +26,14 @@ public class Board {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public Board(Board that) {
|
||||||
public int hashCode() {
|
board = new TileColor[NUM_ROWS][NUM_COLS];
|
||||||
final int prime = 31;
|
|
||||||
int result = 1;
|
for (int r = 0; r < NUM_ROWS; r++) {
|
||||||
result = prime * result + Arrays.hashCode(board);
|
for (int c = 0; c < NUM_COLS; c++) {
|
||||||
return result;
|
this.board[r][c] = that.board[r][c];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -73,6 +65,14 @@ public class Board {
|
|||||||
return numPlies / 2;
|
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() {
|
public boolean isPlayerTurn() {
|
||||||
return numPlies % 2 == 0;
|
return numPlies % 2 == 0;
|
||||||
}
|
}
|
||||||
@@ -91,7 +91,7 @@ public class Board {
|
|||||||
|
|
||||||
public boolean playTile(CellPointer cp, TileColor tile) {
|
public boolean playTile(CellPointer cp, TileColor tile) {
|
||||||
if (board[cp.r][cp.c] != TileColor.NONE) {
|
if (board[cp.r][cp.c] != TileColor.NONE) {
|
||||||
return false; //illegal move
|
return false; // illegal move
|
||||||
}
|
}
|
||||||
|
|
||||||
board[cp.r][cp.c] = tile;
|
board[cp.r][cp.c] = tile;
|
||||||
@@ -151,76 +151,79 @@ public class Board {
|
|||||||
remove.addAll(hold);
|
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.
|
// Check descending diagonal.
|
||||||
count = 0;
|
// count = 0;
|
||||||
hold = new ArrayList<CellPointer>();
|
// hold = new ArrayList<CellPointer>();
|
||||||
int row = cp.r;
|
// int row = cp.r;
|
||||||
int col = cp.c;
|
// int col = cp.c;
|
||||||
loop: while (row >= 0 && col >= 0) {
|
// loop: while (row >= 0 && col >= 0) {
|
||||||
if (board[row][col] == tile) {
|
// if (board[row][col] == tile) {
|
||||||
hold.add(new CellPointer(row, col));
|
// hold.add(new CellPointer(row, col));
|
||||||
count++;
|
// count++;
|
||||||
} else {
|
// } else {
|
||||||
break loop;
|
// break loop;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
row--;
|
// row--;
|
||||||
col--;
|
// col--;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
row = cp.r + 1;
|
// row = cp.r + 1;
|
||||||
col = cp.c + 1;
|
// col = cp.c + 1;
|
||||||
loop: while (row < NUM_ROWS && col < NUM_COLS) {
|
// loop: while (row < NUM_ROWS && col < NUM_COLS) {
|
||||||
if (board[row][col] == tile) {
|
// if (board[row][col] == tile) {
|
||||||
hold.add(new CellPointer(row, col));
|
// hold.add(new CellPointer(row, col));
|
||||||
count++;
|
// count++;
|
||||||
} else {
|
// } else {
|
||||||
break loop;
|
// break loop;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
row++;
|
// row++;
|
||||||
col++;
|
// col++;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (count >= ROW_REMOVAL_SIZE) {
|
// if (count >= ROW_REMOVAL_SIZE) {
|
||||||
remove.addAll(hold);
|
// remove.addAll(hold);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// Check ascending diagonal.
|
// // Check ascending diagonal.
|
||||||
count = 0;
|
// count = 0;
|
||||||
hold = new ArrayList<CellPointer>();
|
// hold = new ArrayList<CellPointer>();
|
||||||
|
//
|
||||||
row = cp.r;
|
// row = cp.r;
|
||||||
col = cp.c;
|
// col = cp.c;
|
||||||
loop: while (row < NUM_ROWS && col >= 0) {
|
// loop: while (row < NUM_ROWS && col >= 0) {
|
||||||
if (board[row][col] == tile) {
|
// if (board[row][col] == tile) {
|
||||||
hold.add(new CellPointer(row, col));
|
// hold.add(new CellPointer(row, col));
|
||||||
count++;
|
// count++;
|
||||||
} else {
|
// } else {
|
||||||
break loop;
|
// break loop;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
row++;
|
// row++;
|
||||||
col--;
|
// col--;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
row = cp.r - 1;
|
// row = cp.r - 1;
|
||||||
col = cp.c + 1;
|
// col = cp.c + 1;
|
||||||
loop: while (row >= 0 && col < NUM_COLS) {
|
// loop: while (row >= 0 && col < NUM_COLS) {
|
||||||
if (board[row][col] == tile) {
|
// if (board[row][col] == tile) {
|
||||||
hold.add(new CellPointer(row, col));
|
// hold.add(new CellPointer(row, col));
|
||||||
count++;
|
// count++;
|
||||||
} else {
|
// } else {
|
||||||
break loop;
|
// break loop;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
row--;
|
// row--;
|
||||||
col++;
|
// col++;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (count >= ROW_REMOVAL_SIZE) {
|
// if (count >= ROW_REMOVAL_SIZE) {
|
||||||
remove.addAll(hold);
|
// remove.addAll(hold);
|
||||||
}
|
// }
|
||||||
|
|
||||||
for (CellPointer cell : remove) {
|
for (CellPointer cell : remove) {
|
||||||
board[cell.r][cell.c] = TileColor.NONE;
|
board[cell.r][cell.c] = TileColor.NONE;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package view;
|
|||||||
import java.awt.GridBagConstraints;
|
import java.awt.GridBagConstraints;
|
||||||
import java.awt.GridBagLayout;
|
import java.awt.GridBagLayout;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
@@ -29,10 +28,10 @@ public class UserChooserFrame extends JFrame {
|
|||||||
"Here should go some rules text. Lorem ipsum dolor sit amet, consectetur adipiscing elit...");
|
"Here should go some rules text. Lorem ipsum dolor sit amet, consectetur adipiscing elit...");
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private final Player comPlayer;
|
||||||
private final JButton playButton = new JButton("Play!");
|
private final JButton playButton = new JButton("Play!");
|
||||||
private final JComboBox<String> userNameBox = new JComboBox<String>();
|
private final JComboBox<String> userNameBox = new JComboBox<String>();
|
||||||
private ArrayList<String> users;
|
private ArrayList<String> users;
|
||||||
private final Player comPlayer;
|
|
||||||
|
|
||||||
public UserChooserFrame(ParsedArgs parsedArgs) {
|
public UserChooserFrame(ParsedArgs parsedArgs) {
|
||||||
this.comPlayer = parsedArgs.getComPlayer();
|
this.comPlayer = parsedArgs.getComPlayer();
|
||||||
@@ -85,29 +84,6 @@ public class UserChooserFrame extends JFrame {
|
|||||||
playButton.addActionListener(psActionListener);
|
playButton.addActionListener(psActionListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
void launchSelectedPlayer() {
|
|
||||||
String name = ((String) userNameBox.getSelectedItem());
|
|
||||||
name = name == null ? name : name.trim().toLowerCase();
|
|
||||||
|
|
||||||
if (name != null && name.compareTo("") != 0) {
|
|
||||||
UserChooserFrame.this.setVisible(false);
|
|
||||||
|
|
||||||
boolean found = false;
|
|
||||||
for (int i = 0; !found && i < users.size(); i++) {
|
|
||||||
if (name.compareTo(users.get(i)) == 0) {
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found) {
|
|
||||||
users.add(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
saveUserList();
|
|
||||||
new MainFrame(name, comPlayer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initLayout() {
|
private void initLayout() {
|
||||||
GridBagLayout gbl = new GridBagLayout();
|
GridBagLayout gbl = new GridBagLayout();
|
||||||
|
|
||||||
@@ -165,4 +141,27 @@ public class UserChooserFrame extends JFrame {
|
|||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void launchSelectedPlayer() {
|
||||||
|
String name = ((String) userNameBox.getSelectedItem());
|
||||||
|
name = name == null ? name : name.trim().toLowerCase();
|
||||||
|
|
||||||
|
if (name != null && name.compareTo("") != 0) {
|
||||||
|
UserChooserFrame.this.setVisible(false);
|
||||||
|
|
||||||
|
boolean found = false;
|
||||||
|
for (int i = 0; !found && i < users.size(); i++) {
|
||||||
|
if (name.compareTo(users.get(i)) == 0) {
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found) {
|
||||||
|
users.add(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
saveUserList();
|
||||||
|
new MainFrame(name, comPlayer);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user