So this is what the c program is doing right now... it is checking for a winner...
I need it to heck for a winner each time a move is made and since this function is called by the int main...I don't really know how I am going to do it.
could someone show me what to put in this function and then the intmain so that the game will check for a winner or draw??
Code:
int checkWinner(char cell[])
{
int i;
// Diagonals
if (cell[4]!=0 && (cell[4]==cell[0] && cell[4]==cell[8] || cell[4]==cell[2] && cell[4]==cell[6]))
return cell[4];
// Horizontals
for (i=0; i<9; i+=3)
if (cell[i]>' ' && cell[i]==cell[i+1] && cell[i]==cell[i+2])
return cell[i];
// Verticals
for (i=0; i<3; i++)
if (cell[i]>' ' && cell[i]==cell[i+3] && cell[i]==cell[i+6])
return cell[i];
// No match
return ' ';
}
my int main funt right now....(ask if you would like to see whole code..
Code:
int main()
{
char cell[9];
int cont = 1;
int ccode = 0;
info();
init(cell);
gameBoard(cell);
while(cont)
{
userMove(cell);
gameBoard(cell);
//check if user wins
//if user wins, print user won
//and cont-- to exit loop
computerMove(cell);
gameBoard(cell);
checkWinner(cell);
//check if computer wins, print computer won
//and cont-- to exit loop
//if nobody won get another user input
}
return 0;
}
basically the checkwinner is not doing its job right now....its just there but the game works....