checking for win in tic tac toe
in my last tic tac toe game, checking for the win was very primative. my board array is set up like this:
[1,1] [1,2] [1,3]
[2,1] [2,2] [2,3]
[3,1] [3,2] [3,3]
this is how my old checkforwin looked:
Code:
void checkforwin()
{
int w=1;
char d='X';
win=0;
for(int p=1;p<=2;p++)
{
if(p==2)
{
d='O';
w=2;
}
for(int g=1;g<4;g++)
{
if(board[1][g]==d && board[2][g]==d && board[3][g]==d)
{
win=w;
}
}
for(int t=1;t<4;t++)
{
if(board[t][1]==d && board[t][2]==d && board[t][3]==d)
{
win=w;
}
}
if(board[1][1]==d && board[2][2]==d && board[3][3]==d)
{
win=w;
}
if(board[3][1]==d && board[2][2]==d && board[1][3]==d)
{
win=w;
}
}
}
im thinking of this: perhaps i could search the array for x (or 0), and then see if it is in a line or something. just anything better than what is above. also, sorry for so much posting.