tic-tac-toe. , , .
if. 8 -, 8 if. , , , , , . - , tic-tac-toe . , Connect Four, , tic-tac-toe if.
. , , , , if if for. , - , .
, , . .
typedef struct
{
int valid;
int rowA, colA;
int rowB, colB;
int rowC, colC;
}
stPath;
static stPath paths[] =
{
{ TRUE, 0, 0, 0, 1, 0, 2 },
{ TRUE, 1, 0, 1, 1, 1, 2 },
{ TRUE, 2, 0, 2, 1, 2, 2 },
{ TRUE, 0, 0, 1, 0, 2, 0 },
{ TRUE, 0, 1, 1, 1, 2, 1 },
{ TRUE, 0, 2, 1, 2, 2, 2 },
{ TRUE, 0, 0, 1, 1, 2, 2 },
{ TRUE, 0, 2, 1, 1, 2, 0 },
{ FALSE, 0, 0, 0, 0, 0, 0 }
};
int checkforwin( char board[3][3] )
{
int a, b, c;
stPath *pptr;
for ( pptr = paths; pptr->valid; pptr++ )
{
a = board[pptr->rowA][pptr->colA];
b = board[pptr->rowB][pptr->colB];
c = board[pptr->rowC][pptr->colC];
if ( a == b && b == c && a != ' ' )
return( (a == 'X') ? 1 : -1 );
}
return( 0 );
}
, , , , , , .