Kod:
[COLOR=#000000]/* Tic - Tac - Toe Program[/COLOR]
[COLOR=#000000]* Programmer: Akin Eman[/COLOR]
[COLOR=#000000]* Date: 12.12.2013[/COLOR]
[COLOR=#000000]* Version: 4[/COLOR]
[COLOR=#000000]*/[/COLOR]
[COLOR=#000000]#include <stdio.h>[/COLOR]
[COLOR=#000000]#include <stdlib.h>[/COLOR]
[COLOR=#000000]#include <time.h>[/COLOR]
[COLOR=#000000]/* Function Prototype */[/COLOR]
[COLOR=#000000]void introduction(void); /* Display function: Game rules */[/COLOR]
[COLOR=#000000]int filled(char tttBrd[][3]); /* Check funtion: the board filled or not */[/COLOR]
[COLOR=#000000]void displayTtt(char tttBrd[][3]); /* Display function: the board is showed on cmd */[/COLOR]
[COLOR=#000000]int tttWin(char tttBrd[][3]); /* Check functiom: who is the winned */[/COLOR]
[COLOR=#000000]int main(void)[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]/* Declaration of variables */[/COLOR]
[COLOR=#000000]char tttBoard[3][3]; /* Board array 3 x 3 matrix */[/COLOR]
[COLOR=#000000]char player1[20]; /* First player name */[/COLOR]
[COLOR=#000000]char player2[20]; /* Second player name */[/COLOR]
[COLOR=#000000]char answer; /* to reset the game */[/COLOR]
[COLOR=#000000]char answer2;[/COLOR]
[COLOR=#000000]int row, column; /* matrix: row and column */[/COLOR]
[COLOR=#000000]int status; /* matrix: filled or not */[/COLOR]
[COLOR=#000000]int result; /* fp win, sp win or draw */[/COLOR]
[COLOR=#000000]int coin; /* who is the start first */[/COLOR]
[COLOR=#000000]int i;[/COLOR]
[COLOR=#000000]/* Some information about this program */[/COLOR]
[COLOR=#000000]introduction();[/COLOR]
[COLOR=#000000]while(1) /* repetation for reset the game */[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]for(row = 0; row < 3; ++row)[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]for(column = 0; column < 3; ++column)[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]tttBoard[row][column] = ' ';[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]status = 0;[/COLOR]
[COLOR=#000000]result = 0;[/COLOR]
[COLOR=#000000]i = 0;[/COLOR]
[COLOR=#000000]printf("Enter your choose <Multiplayer> or <Computer> (M/C)");[/COLOR]
[COLOR=#000000]scanf(" %c", &answer2);[/COLOR]
[COLOR=#000000]if(answer2 > 76 && answer2 < 78 || answer2 > 108 && answer2 < 110)[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]/* Players have to give their name this step */[/COLOR]
[COLOR=#000000]printf("First player enter your name: ");[/COLOR]
[COLOR=#000000]scanf("%s", &player1);[/COLOR]
[COLOR=#000000]printf("Second player enter your name: ");[/COLOR]
[COLOR=#000000]scanf("%s", &player2);[/COLOR]
[COLOR=#000000]/* Coin experiment */[/COLOR]
[COLOR=#000000]srand(time(NULL));[/COLOR]
[COLOR=#000000]coin = rand() % (1 - 0 + 1) + 0;[/COLOR]
[COLOR=#000000]if(coin == 0)[/COLOR]
[COLOR=#000000]printf("\nThe coin is <tails> %s start first\n\n", player1);[/COLOR]
[COLOR=#000000]else if(coin == 1)[/COLOR]
[COLOR=#000000]printf("\nThe coin is <heads> %s start first\n\n", player2);[/COLOR]
[COLOR=#000000]/* This step the loop work until status is equal to zero that [/COLOR]
[COLOR=#000000]* means board is not full yet [/COLOR]
[COLOR=#000000]*/ [/COLOR]
[COLOR=#000000]while(!(result == 1 || result == -1) && i < 9)[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]if(coin == 0){[/COLOR]
[COLOR=#000000]if(status == 0 && result != -1)[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]/* First player (X) give the coordinates */ [/COLOR]
[COLOR=#000000]printf("%s >> You have to play\n\n", player1);[/COLOR]
[COLOR=#000000]printf("Enter a row and column coordinates seperated by space> ");[/COLOR]
[COLOR=#000000]scanf("%d%d", &row, &column);[/COLOR]
[COLOR=#000000]while(tttBoard[row][column] != ' ')[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]printf("\nThis cell is full!\n");[/COLOR]
[COLOR=#000000]printf("Enter valid coordinates seperated by spaces> ");[/COLOR]
[COLOR=#000000]scanf("%d%d", &row, &column);[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]while( !((row >= 0 && row <= 2) && (column >= 0 && column <= 2)) )[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]printf("\nInvalid row or column coordinates!\n");[/COLOR]
[COLOR=#000000]printf("Enter valid coordinates seperated by spaces> ");[/COLOR]
[COLOR=#000000]scanf("%d%d", &row, &column);[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]/* The coordinates which is given by first player asign the array */[/COLOR]
[COLOR=#000000]tttBoard[row][column] = 'X';[/COLOR]
[COLOR=#000000]/* That is the check function which controls that board is full or not */[/COLOR]
[COLOR=#000000]status = filled(tttBoard);[/COLOR]
[COLOR=#000000]printf("\n%s (X) vs %s (O)\n", player1, player2);[/COLOR]
[COLOR=#000000]/* That is the display function which show the board on cmd */[/COLOR]
[COLOR=#000000]displayTtt(tttBoard);[/COLOR]
[COLOR=#000000]result = tttWin(tttBoard);[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]if(status == 0 && result != 1)[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]/* Second player (O) give the coordinates */[/COLOR]
[COLOR=#000000]printf("%s >> You have to play\n\n", player2);[/COLOR]
[COLOR=#000000]printf("Enter a row and column coordinates seperated by space> ");[/COLOR]
[COLOR=#000000]scanf("%d%d", &row, &column);[/COLOR]
[COLOR=#000000]while(tttBoard[row][column] != ' ')[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]printf("\nThis cell is full!\n");[/COLOR]
[COLOR=#000000]printf("Enter valid coordinates seperated by spaces> ");[/COLOR]
[COLOR=#000000]scanf("%d%d", &row, &column);[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]while( !((row >= 0 && row <= 2) && (column >= 0 && column <= 2)) )[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]printf("\nInvalid row or column coordinates!\n");[/COLOR]
[COLOR=#000000]printf("Enter valid coordinates seperated by spaces> ");[/COLOR]
[COLOR=#000000]scanf("%d%d", &row, &column);[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]/* The coordinates which is given by second player asign the array */[/COLOR]
[COLOR=#000000]tttBoard[row][column] = 'O';[/COLOR]
[COLOR=#000000]/* That is the check function which controls that board is full or not */[/COLOR]
[COLOR=#000000]status = filled(tttBoard);[/COLOR]
[COLOR=#000000]printf("\n%s (X) vs %s (O)\n", player1, player2);[/COLOR]
[COLOR=#000000]/* That is the display function which show the board on cmd */[/COLOR]
[COLOR=#000000]displayTtt(tttBoard);[/COLOR]
[COLOR=#000000]result = tttWin(tttBoard);[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}else if(coin == 1){[/COLOR]
[COLOR=#000000]if(status == 0 && result != 1)[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]/* Second player (O) give the coordinates */[/COLOR]
[COLOR=#000000]printf("%s >> You have to play\n\n", player2);[/COLOR]
[COLOR=#000000]printf("Enter a row and column coordinates seperated by space> ");[/COLOR]
[COLOR=#000000]scanf("%d%d", &row, &column);[/COLOR]
[COLOR=#000000]while(tttBoard[row][column] != ' ')[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]printf("\nThis cell is full!\n");[/COLOR]
[COLOR=#000000]printf("Enter valid coordinates seperated by spaces> ");[/COLOR]
[COLOR=#000000]scanf("%d%d", &row, &column);[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]while( !((row >= 0 && row <= 2) && (column >= 0 && column <= 2)) )[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]printf("\nInvalid row or column coordinates!\n");[/COLOR]
[COLOR=#000000]printf("Enter valid coordinates seperated by spaces> ");[/COLOR]
[COLOR=#000000]scanf("%d%d", &row, &column);[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]/* The coordinates which is given by second player asign the array */[/COLOR]
[COLOR=#000000]tttBoard[row][column] = 'O';[/COLOR]
[COLOR=#000000]/* That is the check function which controls that board is full or not */[/COLOR]
[COLOR=#000000]status = filled(tttBoard);[/COLOR]
[COLOR=#000000]printf("\n%s (X) vs %s (O)\n", player1, player2);[/COLOR]
[COLOR=#000000]/* That is the display function which show the board on cmd */[/COLOR]
[COLOR=#000000]displayTtt(tttBoard);[/COLOR]
[COLOR=#000000]result = tttWin(tttBoard);[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]if(status == 0 && result != -1)[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]/* First player (X) give the coordinates */ [/COLOR]
[COLOR=#000000]printf("%s >> You have to play\n\n", player1);[/COLOR]
[COLOR=#000000]printf("Enter a row and column coordinates seperated by space> ");[/COLOR]
[COLOR=#000000]scanf("%d%d", &row, &column);[/COLOR]
[COLOR=#000000]while(tttBoard[row][column] != ' ')[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]printf("\nThis cell is full!\n");[/COLOR]
[COLOR=#000000]printf("Enter valid coordinates seperated by spaces> ");[/COLOR]
[COLOR=#000000]scanf("%d%d", &row, &column);[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]while( !((row >= 0 && row <= 2) && (column >= 0 && column <= 2)) )[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]printf("\nInvalid row or column coordinates!\n");[/COLOR]
[COLOR=#000000]printf("Enter valid coordinates seperated by spaces> ");[/COLOR]
[COLOR=#000000]scanf("%d%d", &row, &column);[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]/* The coordinates which is given by first player asign the array */[/COLOR]
[COLOR=#000000]tttBoard[row][column] = 'X';[/COLOR]
[COLOR=#000000]/* That is the check function which controls that board is full or not */[/COLOR]
[COLOR=#000000]status = filled(tttBoard);[/COLOR]
[COLOR=#000000]printf("\n%s (X) vs %s (O)\n", player1, player2);[/COLOR]
[COLOR=#000000]/* That is the display function which show the board on cmd */[/COLOR]
[COLOR=#000000]displayTtt(tttBoard);[/COLOR]
[COLOR=#000000]result = tttWin(tttBoard);[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]i = i + 1;[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]/***************** PLAYER VS COMPUTER *****************/[/COLOR]
[COLOR=#000000]else if(answer2 > 66 && answer2 < 68 || answer2 > 98 && answer2 < 100)[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]printf("Enter your name: ");[/COLOR]
[COLOR=#000000]scanf("%s", player1);[/COLOR]
[COLOR=#000000]while(!(result == 1 || result == -1))[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]if(status == 0)[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]/* First player (X) give the coordinates */ [/COLOR]
[COLOR=#000000]printf("%s >> You have to play\n\n", player1);[/COLOR]
[COLOR=#000000]printf("Enter a row and column coordinates seperated by space> ");[/COLOR]
[COLOR=#000000]scanf("%d%d", &row, &column);[/COLOR]
[COLOR=#000000]while(tttBoard[row][column] != ' ')[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]printf("\nThis cell is full!\n");[/COLOR]
[COLOR=#000000]printf("Enter valid coordinates seperated by spaces> ");[/COLOR]
[COLOR=#000000]scanf("%d%d", &row, &column);[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]while( !((row >= 0 && row <= 2) && (column >= 0 && column <= 2)) )[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]printf("\nInvalid row or column coordinates!\n");[/COLOR]
[COLOR=#000000]printf("Enter valid coordinates seperated by spaces> ");[/COLOR]
[COLOR=#000000]scanf("%d%d", &row, &column);[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]/* The coordinates which is given by first player asign the array */[/COLOR]
[COLOR=#000000]tttBoard[row][column] = 'X';[/COLOR]
[COLOR=#000000]/* That is the check function which controls that board is full or not */[/COLOR]
[COLOR=#000000]status = filled(tttBoard);[/COLOR]
[COLOR=#000000]printf("\n%s (X) vs Computer (O)\n", player1);[/COLOR]
[COLOR=#000000]/* That is the display function which show the board on cmd */[/COLOR]
[COLOR=#000000]displayTtt(tttBoard);[/COLOR]
[COLOR=#000000]result = tttWin(tttBoard);[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]if(status == 0)[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]printf("Computer is playing\n\n");[/COLOR]
[COLOR=#000000]row = rand() % 3;[/COLOR]
[COLOR=#000000]column = rand() % 3;[/COLOR]
[COLOR=#000000]while(tttBoard[row][column] != ' ')[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]row = rand() % 3;[/COLOR]
[COLOR=#000000]column = rand() % 3;[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]tttBoard[row][column] = 'O';[/COLOR]
[COLOR=#000000]/* That is the check function which controls that board is full or not */[/COLOR]
[COLOR=#000000]status = filled(tttBoard);[/COLOR]
[COLOR=#000000]printf("\n%s (X) vs Computer (O)\n", player1, player2);[/COLOR]
[COLOR=#000000]/* That is the display function which show the board on cmd */[/COLOR]
[COLOR=#000000]displayTtt(tttBoard);[/COLOR]
[COLOR=#000000]result = tttWin(tttBoard);[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]if(answer2 > 76 && answer2 < 78 || answer2 > 108 && answer2 < 110)[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]if(result == 1){[/COLOR]
[COLOR=#000000]printf("****************************************** \n\n");[/COLOR]
[COLOR=#000000]printf("\t %s Win Congratulations\n\n", player1); /* First player win */[/COLOR]
[COLOR=#000000]printf("****************************************** \n\n");[/COLOR]
[COLOR=#000000]}else if(result == -1){[/COLOR]
[COLOR=#000000]printf("****************************************** \n\n");[/COLOR]
[COLOR=#000000]printf("\t %s Win Congratulations\n\n", player2); /* Second player win */[/COLOR]
[COLOR=#000000]printf("****************************************** \n\n");[/COLOR]
[COLOR=#000000]}else{[/COLOR]
[COLOR=#000000]printf("**************************\n");[/COLOR]
[COLOR=#000000]printf("* The game is draw *\n"); /* Game is draw */[/COLOR]
[COLOR=#000000]printf("**************************\n\n");[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}else if(answer2 > 66 && answer2 < 68 || answer2 > 98 && answer2 < 100)[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]if(result == 1){[/COLOR]
[COLOR=#000000]printf("****************************************** \n\n");[/COLOR]
[COLOR=#000000]printf("\t %s Win Congratulations\n\n", player1); /* First player win */[/COLOR]
[COLOR=#000000]printf("****************************************** \n\n");[/COLOR]
[COLOR=#000000]}else if(result == -1){[/COLOR]
[COLOR=#000000]printf("****************************************** \n\n");[/COLOR]
[COLOR=#000000]printf("\t Computer Win Congratulations\n\n"); /* Second player win */[/COLOR]
[COLOR=#000000]printf("****************************************** \n\n");[/COLOR]
[COLOR=#000000]}else{[/COLOR]
[COLOR=#000000]printf("**************************\n");[/COLOR]
[COLOR=#000000]printf("* The game is draw *\n"); /* Game is draw */[/COLOR]
[COLOR=#000000]printf("**************************\n\n");[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]printf("Do you want to reset the game ? (Y/N)\n> ");[/COLOR]
[COLOR=#000000]scanf(" %c", &answer);[/COLOR]
[COLOR=#000000]printf("\n\n");[/COLOR]
[COLOR=#000000]if(answer > 88 && answer < 90 || answer > 120 && answer < 122)[/COLOR]
[COLOR=#000000]continue;[/COLOR]
[COLOR=#000000]break;[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]return 0;[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]void introduction(void)[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]printf(" _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _\n");[/COLOR]
[COLOR=#000000]printf("|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_ |_|_|_|_|_|_|_|_|_|_|_|_|_|_|\n");[/COLOR]
[COLOR=#000000]printf("|_| |_|\n");[/COLOR]
[COLOR=#000000]printf("|_| Hello Players! |_|\n");[/COLOR]
[COLOR=#000000]printf("|_| First of all, thank you for using this game program |_|\n");[/COLOR]
[COLOR=#000000]printf("|_| Secondly, I will advise that you have to read rules carefully |_|\n");[/COLOR]
[COLOR=#000000]printf("|_| Only two players can play tic - tac - toe game |_|\n");[/COLOR]
[COLOR=#000000]printf("|_| The game begin with players enter their name |_|\n");[/COLOR]
[COLOR=#000000]printf("|_| Next, The coin experiment is done |_|\n");[/COLOR]
[COLOR=#000000]printf("|_| Players enter the coordinates seperated by space |_|\n");[/COLOR]
[COLOR=#000000]printf("|_| Nobody can play twice his/her turn |_|\n");[/COLOR]
[COLOR=#000000]printf("|_| You should wait your turn |_|\n");[/COLOR]
[COLOR=#000000]printf("|_| As you wish you can play against the computer |_|\n");[/COLOR]
[COLOR=#000000]printf("|_| Finally, |_|\n");[/COLOR]
[COLOR=#000000]printf("|_| <<<<< Good Luck >>>>> |_|\n");[/COLOR]
[COLOR=#000000]printf("|_|_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _|_|\n");[/COLOR]
[COLOR=#000000]printf("|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_ |_|_|_|_|_|_|_|_|_|_|_|_|_|_|\n\n");[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]int filled(char tttBrd[][3])[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]int r, c; /* row and column subscripts */[/COLOR]
[COLOR=#000000]int ans; /* whether or not board filled */[/COLOR]
[COLOR=#000000]/* Assume board is filled until blank is found */[/COLOR]
[COLOR=#000000]ans = 1;[/COLOR]
[COLOR=#000000]/* Resets ans to zero if a blank is found */[/COLOR]
[COLOR=#000000]for(r = 0; r < 3; ++r)[/COLOR]
[COLOR=#000000]for(c = 0; c < 3; ++c)[/COLOR]
[COLOR=#000000]if(tttBrd[r][c] == ' ')[/COLOR]
[COLOR=#000000]ans = 0;[/COLOR]
[COLOR=#000000]return (ans);[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]void displayTtt(char tttBrd[3][3])[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]printf("\n");[/COLOR]
[COLOR=#000000]printf(" _ _ _ _ _ _ _ _\n");[/COLOR]
[COLOR=#000000]printf("| | | |\n");[/COLOR]
[COLOR=#000000]printf("| %c | %c | %c |\n",tttBrd[0][0], tttBrd[0][1], tttBrd[0][2]);[/COLOR]
[COLOR=#000000]printf("|_ _ | _ _| _ _|\n");[/COLOR]
[COLOR=#000000]printf("| | | |\n");[/COLOR]
[COLOR=#000000]printf("| %c | %c | %c |\n",tttBrd[1][0], tttBrd[1][1], tttBrd[1][2]);[/COLOR]
[COLOR=#000000]printf("|_ _ | _ _| _ _|\n");[/COLOR]
[COLOR=#000000]printf("| | | |\n");[/COLOR]
[COLOR=#000000]printf("| %c | %c | %c |\n",tttBrd[2][0], tttBrd[2][1], tttBrd[2][2]);[/COLOR]
[COLOR=#000000]printf("|_ _ | _ _| _ _|\n");[/COLOR]
[COLOR=#000000]printf("\n\n");[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]int tttWin(char tttBrd[3][3])[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]int i; /* counter */[/COLOR]
[COLOR=#000000]int j = 0; [/COLOR]
[COLOR=#000000]int k = 0;[/COLOR]
[COLOR=#000000]if((tttBrd[0][0] == tttBrd[1][1] && tttBrd[0][0] == tttBrd[2][2]) || (tttBrd[0][2] == tttBrd[1][1] && tttBrd[0][2] == tttBrd[2][0]))[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]if(tttBrd[0][0] == tttBrd[1][1] && tttBrd[0][0] == tttBrd[2][2])[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]if(tttBrd[0][0] == 'X')[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]j = j + 1;[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]else if(tttBrd[0][0] == 'O')[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]k = k + 1;[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]else if(tttBrd[0][2] == tttBrd[1][1] && tttBrd[0][2] == tttBrd[2][0])[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]if(tttBrd[0][2] == 'X')[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]j = j + 1;[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]else if(tttBrd[0][2] == 'O')[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]k = k + 1;[/COLOR]
[COLOR=#000000]} [/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]else[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]for(i = 0; i <=2; i++)[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]if(tttBrd[i][0] == tttBrd[i][1] && tttBrd[i][0] == tttBrd[i][2])[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]if(tttBrd[i][0] == 'X')[/COLOR]
[COLOR=#000000]j = j + 1;[/COLOR]
[COLOR=#000000]if(tttBrd[i][0] == 'O')[/COLOR]
[COLOR=#000000]k = k + 1;[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]if(tttBrd[0][i] == tttBrd[1][i] && tttBrd[0][i] == tttBrd[2][i])[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]if(tttBrd[0][i] == 'X')[/COLOR]
[COLOR=#000000]j = j + 1;[/COLOR]
[COLOR=#000000]else if(tttBrd[0][i] == 'O')[/COLOR]
[COLOR=#000000]k = k + 1;[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]} [/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]if(j > k)[/COLOR]
[COLOR=#000000]return 1;[/COLOR]
[COLOR=#000000]else if(k > j)[/COLOR]
[COLOR=#000000]return -1;[/COLOR]
[COLOR=#000000]else[/COLOR]
[COLOR=#000000]return 0;[/COLOR]
[COLOR=#000000]}[/COLOR]