March 2018
Intermediate to advanced
324 pages
8h 30m
English
The first win condition.
The checkWinCondition private method implements this rule by scanning whether or not the last move is a winning one:
...
private Color winner;
public static final int DISCS_FOR_WIN = 4;
public void putDisc(int column) {
...
if (numOfDiscs < ROWS) {
board[column - 1][numOfDiscs] = currentPlayer;
printBoard();
checkWinCondition(column - 1, numOfDiscs);
switchPlayer();
...
}
private void checkWinCondition(int col, int row) {
Pattern winPattern = Pattern.compile(".*" + currentPlayer + "{" + DISCS_FOR_WIN + "}.*"); // Vertical check StringJoiner stringJoiner ...Read now
Unlock full access