Is this a valid do while loop?My program doesn't end when there is a match of three x's or 3 o's. I'm using a one dimensional array to store the values for the user and computers x's and o's for a game of tic tac toe.
TTTboard[] has 9 spaces to store values in. Can I not use function calls for my do while loops parameters?
I'd really appreciate any input!
Thanks a tonne,
melodia
Code:
do
{
userturn(TTTboard);
computerturn(TTTboard);
}while(CheckPossRow(TTTboard)==FALSE||BoardFull(TTTboard,MAX)==FALSE);
}
printf("\tThank you for playing TIC-TAC-TOE! See you soon!\n\n");
system("PAUSE");
return 0;
}
/*******************************************************************************
********************************************************************************
This Function checks with the help of RowIsWinner if there are any winning rows
*******************************************************************************/
int CheckPossRow(char TTTboard[])
{
char Sq1=TTTboard[0];
char Sq2=TTTboard[1];
char Sq3=TTTboard[2];
char Sq4=TTTboard[3];
char Sq5=TTTboard[4];
char Sq6=TTTboard[5];
char Sq7=TTTboard[6];
char Sq8=TTTboard[7];
char Sq9=TTTboard[8];
if(RowIsWinner(Sq1,Sq2,Sq3)==TRUE)
return TRUE;
else if(RowIsWinner(Sq4,Sq5,Sq6)==TRUE)
return TRUE;
else if(RowIsWinner(Sq7,Sq8,Sq9)==TRUE)
return TRUE;
else if(RowIsWinner(Sq1,Sq4,Sq7)==TRUE)
return TRUE;
else if(RowIsWinner(Sq2,Sq5,Sq8)==TRUE)
return TRUE;
else if (RowIsWinner(Sq3,Sq6,Sq9)==TRUE)
return TRUE;
else if(RowIsWinner(Sq1,Sq5,Sq9)==TRUE)
return TRUE;
else if(RowIsWinner(Sq3,Sq5,Sq7)==TRUE)
return TRUE;
else
return FALSE;
}
/*******************************************************************************
********************************************************************************
This function checks to see if the board (array) is full or has empty spaces free
*******************************************************************************/
int BoardFull(char TTTboard[],int max)
{
int i;
for (i=0; i < max; i++)
{
if (TTTboard[i] == EMPTY)
{
return(FALSE); /* it was found */
}
}
return(TRUE); /* if it was not found */
}