Closed FZarsaz closed 2 years ago
public boolean isWin(Player player) { if (this.arr[0][0] == player.getOperator() && this.arr[0][1] == player.getOperator() && this.arr[0][2] == player.getOperator()) return true; if (this.arr[1][0] == player.getOperator() && this.arr[1][1] == player.getOperator() && this.arr[1][2] == player.getOperator()) return true; if (this.arr[2][0] == player.getOperator() && this.arr[2][1] == player.getOperator() && this.arr[2][2] == player.getOperator()) return true; if (this.arr[0][0] == player.getOperator() && this.arr[1][0] == player.getOperator() && this.arr[2][0] == player.getOperator()) return true; if (this.arr[0][1] == player.getOperator() && this.arr[1][1] == player.getOperator() && this.arr[2][1] == player.getOperator()) return true; if (this.arr[0][2] == player.getOperator() && this.arr[1][2] == player.getOperator() && this.arr[2][2] == player.getOperator()) return true; if (this.arr[0][0] == player.getOperator() && this.arr[1][1] == player.getOperator() && this.arr[2][2] == player.getOperator()) return true; if (this.arr[0][2] == player.getOperator() && this.arr[1][1] == player.getOperator() && this.arr[2][0] == player.getOperator()) return true; return false; }
public static char hasWon(char[][]board) { // Row for(int i = 0; i < 3; i++) { if(board[i][0] == board[i][1] && board[i][1] == board [i][2] && board [i][0] != '-') { return board [i][0]; } } // Col for(int j = 0; j < 3; i++) { if(board[0][j] == board[1][j] && board[1][j] == board [2][j] && board [0][j] != '-') { return board [0][j]; } } // Diagonal if(board[0][0] == board[1][1] && board[1][1] == board [2][2] && board [0][0] != '-') { return board [0][0]; }
if(board[2][0] == board[1][1] && board[i][1] == board [0][2] && board [2][0] != '-') { return board [i2[0];
} // Nobody return '-';
}