2 // TicTacToe Board flags
11 board = new int[3][3];
12 for (int i = 0; i < 3; i++)
13 for (int j = 0; j < 3; j++)
17 public int makeMove(int row, int col) {
18 if (boardFull() == 1) {
22 if (board[row][col] != 0) { // Space taken
27 if (checkForWin(1) == 1) { // Check if player won
31 // Computer makes move
32 if (computerMakeMove() == 1) { // If made move successful
33 if (checkForWin(2) == 1) { // Check if computer won
38 else { // Board full, no winner
46 public int boardFull() {
47 for (int i = 0; i < 3; i++)
48 for (int j = 0; j < 3; j++)
54 public int computerMakeMove() {
55 for (int i = 0; i < 3; i++)
56 for (int j = 0; j < 3; j++)
57 if (board[i][j] == 0) {
64 public int checkForWin(int p) {
65 // Add logic for checking if player p wins
68 if ((board[0][0] == p) && (board[0][1] == p) && (board[0][2] == p) ||
69 (board[1][0] == p) && (board[1][1] == p) && (board[1][2] == p) ||
70 (board[2][0] == p) && (board[2][1] == p) && (board[2][2] == p)) {
75 if ((board[0][0] == p) && (board[1][0] == p) && (board[2][0] == p) ||
76 (board[0][1] == p) && (board[1][1] == p) && (board[2][1] == p) ||
77 (board[0][2] == p) && (board[1][2] == p) && (board[2][2] == p)) {
82 if ((board[0][0] == p) && (board[1][1] == p) && (board[2][2] == p) ||
83 (board[0][2] == p) && (board[1][1] == p) && (board[2][0] == p)) {