private void setWinner() { if (checkWinner(XCHAR)) winner = XCHAR; else if (checkWinner(OCHAR)) winner = OCHAR; else if (countMoves() == boardSize * boardSize) winner = DRAWCHAR; else winner = EMPTYCHAR; } private int countMoves() { int count = 0; for (int i = 0; i < boardSize; i++) for (int j = 0; j < boardSize; j++) if (board[i][j] != EMPTYCHAR) count++; return count; } private boolean checkWinner(int c) { if (checkMainDiag(c)) return true; if (checkOtherDiag(c)) return true; for (int i = 0; i < boardSize; i++) { if (checkWinnerRow(i, c)) return true; if (checkWinnerCol(i, c)) return true; } return false; } private boolean checkMainDiag(int c) { for (int i = 0; i < boardSize; i++) if (board[i][i] != c) return false; return true; } private boolean checkOtherDiag(int c) { for (int i = 0; i < boardSize; i++) if (board[i][boardSize - i - 1] != c) return false; return true; } private boolean checkWinnerRow(int row, int c) { for (int i = 0; i < boardSize; i++) if (board[row][i] != c) return false; return true; } private boolean checkWinnerCol(int col, int c) { for (int i = 0; i < boardSize; i++) if (board[i][col] != c) return false; return true; }