1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
char winCheck( Game *g )
{
int gridCount = 0;
for( int i = 0; i < 3; i++ )
{
if( ( g->getGrid( i, 0 ) == 88 ) && ( g->getGrid( i, 1 ) == 88 ) && ( g->getGrid( i, 2 ) == 88 ) )
{
return 88;
}
if( ( g->getGrid( i, 0 ) == 79 ) && ( g->getGrid( i, 1 ) == 79 ) && ( g->getGrid( i, 2 ) == 79 ) )
{
return 79;
}
}
for( int i = 0; i < 3; i++ )
{
if( ( g->getGrid( 0, i ) == 88 ) && ( g->getGrid( 1, i ) == 88 ) && ( g->getGrid( 2, i ) == 88 ) )
{
return 88;
}
if( ( g->getGrid( 0, i ) == 79 ) && ( g->getGrid( 1, i ) == 79 ) && ( g->getGrid( 2, i ) == 79 ) )
{
return 79;
}
}
if( ( g->getGrid( 0, 0 ) == 88 ) && ( g->getGrid( 1, 1 ) == 88 ) && ( g->getGrid( 2, 2 ) == 88 ) )
return 88;
if( ( g->getGrid( 0, 0 ) == 79 ) && ( g->getGrid( 1, 1 ) == 79 ) && ( g->getGrid( 2, 2 ) == 79 ) )
return 79;
if( ( g->getGrid( 0, 2 ) == 88 ) && ( g->getGrid( 1, 1 ) == 88 ) && ( g->getGrid( 2, 0 ) == 88 ) )
return 88;
if( ( g->getGrid( 0, 2 ) == 79 ) && ( g->getGrid( 1, 1 ) == 79 ) && ( g->getGrid( 2, 0 ) == 79 ) )
return 79;
//check for a full grid( no win )
for( int i = 0; i < 3; i++ )
{
for( int j = 0; j < 3; j++ )
{
if( g->getGrid( i, j ) != 43 )
{
gridCount++;
}
if( gridCount == 9 )
return 99;
}
}
return 0;
}
|