Added more stuffs to README. Cleaned up code

master^2
Minh D. Bui 2 years ago
parent 5a30b9ec12
commit 25c26ca354

Binary file not shown.

@ -23,7 +23,6 @@ import model.Connect4MoveMessage;
import model.IllegalArgumentException;
import model.Minimax_AlphaBeta;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
@ -66,7 +65,7 @@ public class Connect4 extends Application implements Runnable {
* @param primaryStage the window of the GUI
*/
@Override
public void start(Stage primaryStage) throws Exception {
public void start(Stage primaryStage) {
boolean foundSerializedFile = this.deserializeGameModel();
if (!foundSerializedFile) {
initGame();
@ -212,7 +211,7 @@ public class Connect4 extends Application implements Runnable {
/**
* This method is to set the GUI to the center of the pane
*
* @param newView
* @param newView Passing a new view to
*/
private void setViewTo(Observer newView) {
window.setCenter(null);

@ -1,333 +0,0 @@
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import model.Connect4Model;
import controller.Connect4Controller;
/**
* This class contains test methods for our Connect4 game.
*
* @author Minh Bui
*
*/
public class Connect4Test {
/**
* Test method for Connect4Model.wonByDiagonal().
*/
@Test
void testWonByDiagonal() {
Connect4Model gm = new Connect4Model();
Connect4Controller controller = new Connect4Controller(gm);
try {
gm.setObjectAt(3, 0, gm.getHumanChar());
gm.setObjectAt(2, 1, gm.getHumanChar());
gm.setObjectAt(1, 2, gm.getHumanChar());
gm.setObjectAt(0, 3, gm.getHumanChar());
// System.out.println(controller.gameBoardToString());
assert (gm.wonByDiagonal(gm.getHumanChar()));
gm = new Connect4Model();
controller = new Connect4Controller(gm);
gm.setObjectAt(4, 0, gm.getHumanChar());
gm.setObjectAt(3, 1, gm.getHumanChar());
gm.setObjectAt(2, 2, gm.getHumanChar());
gm.setObjectAt(1, 3, gm.getHumanChar());
// System.out.println(controller.gameBoardToString());
assert (gm.wonByDiagonal(gm.getHumanChar()));
gm = new Connect4Model();
controller = new Connect4Controller(gm);
gm.setObjectAt(3, 1, gm.getHumanChar());
gm.setObjectAt(2, 2, gm.getHumanChar());
gm.setObjectAt(1, 3, gm.getHumanChar());
gm.setObjectAt(0, 4, gm.getHumanChar());
// System.out.println(controller.gameBoardToString());
assert (gm.wonByDiagonal(gm.getHumanChar()));
gm = new Connect4Model();
controller = new Connect4Controller(gm);
gm.setObjectAt(4, 1, gm.getHumanChar());
gm.setObjectAt(3, 2, gm.getHumanChar());
gm.setObjectAt(2, 3, gm.getHumanChar());
gm.setObjectAt(1, 4, gm.getHumanChar());
// System.out.println(controller.gameBoardToString());
assert (gm.wonByDiagonal(gm.getHumanChar()));
gm = new Connect4Model();
controller = new Connect4Controller(gm);
gm.setObjectAt(6, 0, gm.getHumanChar());
gm.setObjectAt(5, 1, gm.getHumanChar());
gm.setObjectAt(4, 2, gm.getHumanChar());
gm.setObjectAt(3, 3, gm.getHumanChar());
// System.out.println(controller.gameBoardToString());
assert (gm.wonByDiagonal(gm.getHumanChar()));
gm = new Connect4Model();
controller = new Connect4Controller(gm);
gm.setObjectAt(6, 2, gm.getHumanChar());
gm.setObjectAt(5, 3, gm.getHumanChar());
gm.setObjectAt(4, 4, gm.getHumanChar());
gm.setObjectAt(3, 5, gm.getHumanChar());
// System.out.println(controller.gameBoardToString());
assert (gm.wonByDiagonal(gm.getHumanChar()));
gm = new Connect4Model();
controller = new Connect4Controller(gm);
gm.setObjectAt(3, 0, gm.getHumanChar());
gm.setObjectAt(4, 1, gm.getHumanChar());
gm.setObjectAt(5, 2, gm.getHumanChar());
gm.setObjectAt(6, 3, gm.getHumanChar());
// System.out.println(controller.gameBoardToString());
assert (gm.wonByDiagonal(gm.getHumanChar()));
gm = new Connect4Model();
controller = new Connect4Controller(gm);
gm.setObjectAt(0, 2, gm.getHumanChar());
gm.setObjectAt(1, 3, gm.getHumanChar());
gm.setObjectAt(2, 4, gm.getHumanChar());
gm.setObjectAt(3, 5, gm.getHumanChar());
// System.out.println(controller.gameBoardToString());
assert (gm.wonByDiagonal(gm.getHumanChar()));
gm = new Connect4Model();
controller = new Connect4Controller(gm);
gm.setObjectAt(1, 1, gm.getHumanChar());
gm.setObjectAt(2, 2, gm.getHumanChar());
gm.setObjectAt(3, 3, gm.getHumanChar());
gm.setObjectAt(4, 4, gm.getHumanChar());
// System.out.println(controller.gameBoardToString());
assert (gm.wonByDiagonal(gm.getHumanChar()));
gm = new Connect4Model();
controller = new Connect4Controller(gm);
gm.setObjectAt(0, 2, gm.getHumanChar());
gm.setObjectAt(1, 3, gm.getHumanChar());
gm.setObjectAt(2, 4, gm.getHumanChar());
gm.setObjectAt(3, 5, gm.getHumanChar());
// System.out.println(controller.gameBoardToString());
assert (gm.wonByDiagonal(gm.getHumanChar()));
gm = new Connect4Model();
controller = new Connect4Controller(gm);
gm.setObjectAt(0, 0, gm.getHumanChar());
gm.setObjectAt(1, 1, gm.getHumanChar());
gm.setObjectAt(3, 3, gm.getHumanChar());
gm.setObjectAt(4, 4, gm.getHumanChar());
// System.out.println(controller.gameBoardToString());
assert (!gm.wonByDiagonal(gm.getHumanChar()));
gm = new Connect4Model();
controller = new Connect4Controller(gm);
gm.setObjectAt(2, 2, gm.getHumanChar());
gm.setObjectAt(1, 1, gm.getHumanChar());
gm.setObjectAt(3, 3, gm.getHumanChar());
gm.setObjectAt(4, 4, gm.getHumanChar());
// System.out.println(controller.gameBoardToString());
assert (gm.wonByDiagonal(gm.getHumanChar()));
} catch (model.IllegalArgumentException e) {
// Nothing will happen. Test cases are all valid input.
}
}
/**
* Test method for model.Connect4Model.wonByRow().
*/
@Test
void testWonByRow() {
Connect4Model gm = new Connect4Model();
Connect4Controller controller = new Connect4Controller(gm);
try {
gm.setObjectAt(0, 0, gm.getHumanChar());
gm.setObjectAt(1, 0, gm.getHumanChar());
gm.setObjectAt(2, 0, gm.getHumanChar());
gm.setObjectAt(3, 0, gm.getHumanChar());
// System.out.println(controller.gameBoardToString());
assert (gm.wonByRow(gm.getHumanChar()));
gm = new Connect4Model();
controller = new Connect4Controller(gm);
gm.setObjectAt(0, 0, gm.getHumanChar());
gm.setObjectAt(1, 0, gm.getHumanChar());
gm.setObjectAt(4, 0, gm.getHumanChar());
gm.setObjectAt(5, 0, gm.getHumanChar());
// System.out.println(controller.gameBoardToString());
assert (!gm.wonByRow(gm.getHumanChar()));
} catch (model.IllegalArgumentException e) {
// Test cases are all valid.
}
}
/**
* Test method for Connect4Model.wonByCol().
*/
@Test
void testWonByCol() {
Connect4Model gm = new Connect4Model();
Connect4Controller controller = new Connect4Controller(gm);
try {
gm.setObjectAt(0, 1, gm.getHumanChar());
gm.setObjectAt(0, 2, gm.getHumanChar());
gm.setObjectAt(0, 3, gm.getHumanChar());
gm.setObjectAt(0, 4, gm.getHumanChar());
// System.out.println(controller.gameBoardToString());
assert (gm.wonByCol(gm.getHumanChar()));
gm = new Connect4Model();
controller = new Connect4Controller(gm);
gm.setObjectAt(5, 1, gm.getHumanChar());
gm.setObjectAt(5, 2, gm.getHumanChar());
gm.setObjectAt(5, 4, gm.getHumanChar());
gm.setObjectAt(5, 5, gm.getHumanChar());
// System.out.println(controller.gameBoardToString());
assert (!gm.wonByCol(gm.getHumanChar()));
} catch (model.IllegalArgumentException e) {
// Nothing to do.
}
}
/**
* Test misc methods.
*/
@Test
void testMisc() {
Connect4Model gm = new Connect4Model();
Connect4Controller controller = new Connect4Controller(gm);
// Testing board toString() method.
String empty_board = "_ _ _ _ _ _ _ " + "\n" + "_ _ _ _ _ _ _ " + "\n" + "_ _ _ _ _ _ _ " + "\n"
+ "_ _ _ _ _ _ _ " + "\n" + "_ _ _ _ _ _ _ " + "\n" + "_ _ _ _ _ _ _ " + "\n" + "0 1 2 3 4 5 6\n";
assertEquals(controller.gameBoardToString(), empty_board);
// Testing other misc methods.
assert (gm.isHumanMove());
try {
assertEquals(gm.getObjectAt(0, 0), gm.getBlankChar());
} catch (model.IllegalArgumentException e) {
// Guaranteed succeed. Nothing to do.
}
try {
controller.placeToken(0);
} catch (model.IllegalArgumentException e) {
// Nothing to handle.
}
gm.switchTurn();
assert (!gm.isHumanMove());
gm.computerMove(gm.getComputerChar(), false);
// Play a random game where computer vs computer.
gm = new Connect4Model();
controller = new Connect4Controller(gm);
while (!controller.gameIsOver()) {
gm.computerMove(gm.getHumanChar(), false);
gm.switchTurn();
gm.computerMove(gm.getComputerChar(), false);
gm.switchTurn();
}
// Test tie game.
gm = new Connect4Model();
controller = new Connect4Controller(gm);
for (int i = 0; i < gm.getMaxRow() * gm.getMaxCol(); i++)
gm.switchTurn();
try {
gm.setObjectAt(0, 0, gm.getComputerChar());
gm.setObjectAt(0, 1, gm.getHumanChar());
gm.setObjectAt(0, 2, gm.getComputerChar());
gm.setObjectAt(0, 3, gm.getHumanChar());
gm.setObjectAt(0, 4, gm.getComputerChar());
gm.setObjectAt(0, 5, gm.getHumanChar());
gm.setObjectAt(1, 0, gm.getHumanChar());
gm.setObjectAt(1, 1, gm.getComputerChar());
gm.setObjectAt(1, 2, gm.getHumanChar());
gm.setObjectAt(1, 3, gm.getComputerChar());
gm.setObjectAt(1, 4, gm.getHumanChar());
gm.setObjectAt(1, 5, gm.getComputerChar());
gm.setObjectAt(2, 0, gm.getComputerChar());
gm.setObjectAt(2, 1, gm.getHumanChar());
gm.setObjectAt(2, 2, gm.getComputerChar());
gm.setObjectAt(2, 3, gm.getHumanChar());
gm.setObjectAt(2, 4, gm.getComputerChar());
gm.setObjectAt(2, 5, gm.getHumanChar());
gm.setObjectAt(3, 0, gm.getComputerChar());
gm.setObjectAt(3, 1, gm.getHumanChar());
gm.setObjectAt(3, 2, gm.getComputerChar());
gm.setObjectAt(3, 3, gm.getHumanChar());
gm.setObjectAt(3, 4, gm.getComputerChar());
gm.setObjectAt(3, 5, gm.getHumanChar());
gm.setObjectAt(4, 0, gm.getComputerChar());
gm.setObjectAt(4, 1, gm.getHumanChar());
gm.setObjectAt(4, 2, gm.getComputerChar());
gm.setObjectAt(4, 3, gm.getHumanChar());
gm.setObjectAt(4, 4, gm.getComputerChar());
gm.setObjectAt(4, 5, gm.getHumanChar());
gm.setObjectAt(5, 0, gm.getHumanChar());
gm.setObjectAt(5, 1, gm.getComputerChar());
gm.setObjectAt(5, 2, gm.getHumanChar());
gm.setObjectAt(5, 3, gm.getComputerChar());
gm.setObjectAt(5, 4, gm.getHumanChar());
gm.setObjectAt(5, 5, gm.getComputerChar());
gm.setObjectAt(6, 0, gm.getHumanChar());
gm.setObjectAt(6, 1, gm.getComputerChar());
gm.setObjectAt(6, 2, gm.getHumanChar());
gm.setObjectAt(6, 3, gm.getComputerChar());
gm.setObjectAt(6, 4, gm.getHumanChar());
gm.setObjectAt(6, 5, gm.getComputerChar());
// Try to insert a token into a full grid.
assert(!controller.placeToken(0));
} catch (model.IllegalArgumentException e) {
// No exception will be caught.
}
assert (!gm.isBlank(6, 5));
// System.out.println(controller.gameBoardToString());
// System.out.println(gm.didWin(gm.getComputerChar()));
// System.out.println(gm.didWin(gm.getHumanChar()));
// System.out.println (gm.isTied());
// System.out.println(gm.moveMaked);
assert (gm.isTied());
// Test exceptions and faulty input.
final Connect4Model gm1 = new Connect4Model();
final Connect4Controller controller1 = new Connect4Controller(gm1);
assertThrows(model.IllegalArgumentException.class, () -> gm1.getObjectAt(-1, 0));
assertThrows(model.IllegalArgumentException.class, () -> gm1.getObjectAt(7, 0));
assertThrows(model.IllegalArgumentException.class, () -> gm1.getObjectAt(2, -1));
assertThrows(model.IllegalArgumentException.class, () -> gm1.getObjectAt(2, 6));
assertThrows(model.IllegalArgumentException.class, () -> gm1.setObjectAt(-1, 0, gm1.getHumanChar()));
assertThrows(model.IllegalArgumentException.class, () -> gm1.setObjectAt(7, 0, gm1.getHumanChar()));
assertThrows(model.IllegalArgumentException.class, () -> gm1.setObjectAt(2, -1, gm1.getHumanChar()));
assertThrows(model.IllegalArgumentException.class, () -> gm1.setObjectAt(2, 6, gm1.getHumanChar()));
assertThrows(model.IllegalArgumentException.class, () -> controller1.placeToken(-1));
assertThrows(model.IllegalArgumentException.class, () -> controller1.placeToken(7));
}
}

@ -5,6 +5,31 @@ Connect 4 is a two-player zero-sum connection game. For more details on rules, p
![Connect4](https://i.imgur.com/MibgAOA.png)
## How to run the code locally
### Requirements:
- Java RE 8
- JavaFX 2
Clone the repository (duh)
```
git clone https://github.com/minhdb/ChatRoom.git
```
Here are the steps for IntelliJ IDEA. Other IDEs should have similar settings.
`File -> Project Structure -> Module -> Select Java SDK`
Add JavaFX as a dependency.
`Run -> Edit Configuration ... -> Add VM option`
```
--module-path [PATH_TO_JAVA_FX]/lib --add-modules=javafx.controls,javafx.fxml
```
## Features
· Allows either the AI or the user to play.
@ -24,7 +49,7 @@ Computer player's using Minimax alogrithms with alpha-beta pruning. More details
The Server will always take the first turn. If it is a human player, the player will click and send the event to the client. Otherwise the AI will generate its turn and send it to the client. The client will go second. This will repeat until the game is over.
A move made over network is implemented using serialization. Here's the details:
```
public class Connect4MoveMessage implements Serializable {
public static int YELLOW = 1;
@ -49,6 +74,7 @@ public class Connect4MoveMessage implements Serializable {
public int getColor() { … }
}
```

@ -2,10 +2,9 @@ package model;
/**
* An interface for generating strategies.
*
*
*/
public interface ComputerPlayer {
public int getMove(Connect4Model gameModel, boolean max);
}

@ -12,11 +12,6 @@ public class Connect4Model extends java.util.Observable implements java.io.Seria
*/
private static final long serialVersionUID = 1L;
/**
* Representation of the board.
*/
private char[][] board;
/**
* The maximum size for each rows.
*/
@ -33,11 +28,6 @@ public class Connect4Model extends java.util.Observable implements java.io.Seria
*/
private final int CONNECT_SIZE = 4;
/**
* Indicates if it's currently the human turn.
*/
private boolean isHumanMove;
/**
* The default character representation of the player.
*/
@ -59,18 +49,30 @@ public class Connect4Model extends java.util.Observable implements java.io.Seria
private transient ComputerPlayer computerPlayer;
/**
* Counts the total number of moves that have been made.
* Encapsulate move information to send over to the views.
*/
private int moveMaked;
private transient Connect4MoveMessage moveMsg;
/**
* Encapsulate move information to send over to the views.
* Indicates if it's currently the human turn.
*/
private transient Connect4MoveMessage moveMsg;
private boolean isHumanMove;
/**
* Counts the total number of moves that have been made.
*/
private int moveMaked;
/**
* Representation of the board.
*/
private char[][] board;
/**
* Ctor for Connect4Model.
*/
public Connect4Model() {
board = new char[ROWS_NUM][COLS_NUM];
for (int i = 0; i < ROWS_NUM; i++) {
for (int j = 0; j < COLS_NUM; j++) {
@ -80,30 +82,13 @@ public class Connect4Model extends java.util.Observable implements java.io.Seria
// Human moves first by default.
isHumanMove = true;
// computerPlayer = new RandomAI();
computerPlayer = new Minimax_AlphaBeta();
moveMaked = 0;
moveMsg = null;
setChanged();
notifyObservers(moveMsg);
}
/*
public void newGame() {
board = new char[ROWS_NUM][COLS_NUM];
for (int i = 0; i < ROWS_NUM; i++) {
for (int j = 0; j < COLS_NUM; j++) {
board[i][j] = blankChar;
}
}
// Human moves first by default.
isHumanMove = true;
// computerPlayer = new RandomAI();
computerPlayer = new Minimax_AlphaBeta();
moveMaked = 0;
moveMsg = new Connect4MoveMessage();
setChanged();
notifyObservers(moveMsg);
}*/
public void setComputerPlayer(ComputerPlayer another) {
this.computerPlayer = another;
@ -118,10 +103,14 @@ public class Connect4Model extends java.util.Observable implements java.io.Seria
* @throws IllegalArgumentException when x is not between 0 and ROWS_NUM or y is
* not between 0 and COLS_NUM.
*/
public char getObjectAt(int x, int y) throws model.IllegalArgumentException {
if ((x >= this.ROWS_NUM || x < 0) || (y >= this.COLS_NUM || y < 0)) {
public char getObjectAt(final int x, final int y) throws model.IllegalArgumentException {
if ( (x >= this.ROWS_NUM || x < 0) ||
(y >= this.COLS_NUM || y < 0)) {
throw new model.IllegalArgumentException("Invalid arguments.");
}
return this.board[x][y];
}
@ -134,15 +123,22 @@ public class Connect4Model extends java.util.Observable implements java.io.Seria
* @throws IllegalArgumentException when x is not between 0 and ROWS_NUM or y is
* not between 0 and COLS_NUM.
*/
public void setObjectAt(int x, int y, char obj) throws model.IllegalArgumentException {
public void setObjectAt(final int x, final int y, final char obj) throws model.IllegalArgumentException {
if ((x >= this.ROWS_NUM || x < 0) || (y >= this.COLS_NUM || y < 0)) {
throw new model.IllegalArgumentException("Invalid arguments.");
}
this.board[x][y] = obj;
if (obj == this.getComputerChar()) {
moveMsg = new Connect4MoveMessage(this.board[0].length - y - 1, x , 2);
} else
} else {
moveMsg = new Connect4MoveMessage(this.board[0].length - y - 1, x , 1);
}
setChanged();
notifyObservers(moveMsg);
}
@ -154,7 +150,7 @@ public class Connect4Model extends java.util.Observable implements java.io.Seria
* @param y stand for column
* @return true if the cell (x,y) is empty.
*/
public boolean isBlank(int x, int y) {
public boolean isBlank(final int x, final int y) {
return this.board[x][y] == blankChar;
}
@ -212,14 +208,22 @@ public class Connect4Model extends java.util.Observable implements java.io.Seria
return this.isHumanMove;
}
public void setHumanTurn(boolean isHumanTurn) {
isHumanMove = isHumanTurn;
/**
* Set the flag for human turn.
*
* @param isHumanTurn Set isHumanMove to true if this is true and false otherwise.
*/
public void setHumanTurn(final boolean isHumanTurn) {
this.isHumanMove = isHumanTurn;
}
/**
* A helper method to switch turn in a single game.
*/
public void switchTurn() {
this.moveMaked++;
isHumanMove = !isHumanMove;
// this.notifyObservers();
}
/**
@ -228,20 +232,30 @@ public class Connect4Model extends java.util.Observable implements java.io.Seria
* @param playerChar A character that represents the player.
* @return True if playerChar wins the game by column and false otherwise.
*/
public boolean wonByCol(char playerChar) {
public boolean wonByCol(final char playerChar) {
boolean won = false;
for (int i = 0; i < ROWS_NUM; i++) {
int colSum = 0;
for (int j = 0; j < COLS_NUM; j++) {
if (board[i][j] == playerChar) {
colSum++;
if (colSum == CONNECT_SIZE)
return true;
} else
colSum = 0;
if (colSum == CONNECT_SIZE) {
won = true;
break;
}
} else {
colSum = 0;
}
}
}
return false;
return won;
}
/**
@ -250,19 +264,30 @@ public class Connect4Model extends java.util.Observable implements java.io.Seria
* @param playerChar A character that represents the player.
* @return True if playerChar wins the game by row and false otherwise.
*/
public boolean wonByRow(char playerChar) {
public boolean wonByRow(final char playerChar) {
boolean won = false;
for (int i = 0; i < COLS_NUM; i++) {
int rowSum = 0;
for (int j = 0; j < ROWS_NUM; j++) {
if (board[j][i] == playerChar) {
rowSum++;
if (rowSum == CONNECT_SIZE)
return true;
} else
if (rowSum == CONNECT_SIZE) {
won = true;
break;
}
} else {
rowSum = 0;
}
}
return false;
}
return won;
}
/**
@ -271,17 +296,21 @@ public class Connect4Model extends java.util.Observable implements java.io.Seria
* @param playerChar A character that represents the player.
* @return True if playerChar wins the game diagonally and false otherwise.
*/
public boolean wonByDiagonal(char playerChar) {
public boolean wonByDiagonal(final char playerChar) {
int sum = 0;
boolean won = false;
// Covering from left to right.
for (int i = 3; i < ROWS_NUM; i++) {
sum = 0;
for (int j = 0; j < COLS_NUM && j <= i; j++) {
if (board[i - j][j] == playerChar) {
sum++;
if (sum == CONNECT_SIZE)
return true;
if (sum == CONNECT_SIZE) {
won = true;
break;
}
} else {
sum = 0;
}
@ -289,28 +318,32 @@ public class Connect4Model extends java.util.Observable implements java.io.Seria
}
for (int j = 1; j < 3; j++) {
sum = 0;
for (int k = 0; j + k < COLS_NUM; k++) {
// System.out.println(ROWS_NUM - 1 - k + " " + (j + k));
if (board[ROWS_NUM - 1 - k][j + k] == playerChar) {
sum++;
if (sum == CONNECT_SIZE)
return true;
} else
if (sum == CONNECT_SIZE) {
won = true;
break;
}
} else {
sum = 0;
}
}
}
// Covering from right to left.
for (int i = 3; i >= 0; i--) {
sum = 0;
for (int j = 0; j < COLS_NUM && (i + j) < ROWS_NUM; j++) {
if (board[i + j][j] == playerChar) {
// System.out.println(i + j + " " + j);
sum++;
if (sum == CONNECT_SIZE)
return true;
if (sum == CONNECT_SIZE) {
won = true;
break;
}
} else {
sum = 0;
}
@ -322,13 +355,16 @@ public class Connect4Model extends java.util.Observable implements java.io.Seria
for (int k = 0; j + k < COLS_NUM; k++) {
if (board[0 + k][j + k] == playerChar) {
sum++;
if (sum == CONNECT_SIZE)
return true;
} else
if (sum == CONNECT_SIZE) {
won = true;
break;
}
} else {
sum = 0;
}
}
return false;
}
return won;
}
/**
@ -350,13 +386,6 @@ public class Connect4Model extends java.util.Observable implements java.io.Seria
public boolean isTied() {
// Tie condition: Out of moves AND nobody wins.
return (moveMaked == ROWS_NUM * COLS_NUM && !(didWin(computerChar) || didWin(humanChar)));
// Board is filled.
/*
* boolean isFilled = true; for (int i = 0; i < board.length; i++) { for (int j
* = 0; j < board[0].length; j++) { if (board[i][j] == '_') { isFilled = false;
* break; } } } return (isFilled && !(didWin(computerChar) ||
* didWin(humanChar)));
*/
}
/**

Loading…
Cancel
Save