Code: Select all
//AI move
void Game::SmartAIMove()
{
do
{
if( firstTurn == true )
{
AIMoveX = rand() % 3;
AIMoveY = rand() % 3;
firstTurn = false;
}
else
{
//All Variants
IFforSmartAI(0,1,2,0,0,true);
IFforSmartAI(3,4,5,1,0,true);
IFforSmartAI(5,6,7,2,0,true);
IFforSmartAI(0,3,6,0,0,false);
IFforSmartAI(1,4,7,0,1,false);
IFforSmartAI(2,5,8,0,2,false);
// IFforSmartAI(0,4,8);
// IFforSmartAI(2,4,6);
}
} while( GetSquareState( AIMoveX,AIMoveY )!= EMPTY );
}
void Game::IFforSmartAI( int index0,int index1,int index2,int row,int column,bool incCol )
{
if( ( GetSquareState(index0) == GetSquareState(index1) )!= EMPTY && GetSquareState(index2) == EMPTY )
{
//Last element
AIMoveX = column;
AIMoveY = row;
//Move horizontally
if(incCol == true)
{
AIMoveX = 2;
}
//Vertical
else
{
AIMoveY = 2;
}
}
else if( ( GetSquareState(index1) == GetSquareState(index2) )!= EMPTY && GetSquareState(index0) == EMPTY )
{
//First element
AIMoveX = column;
AIMoveY = row;
}
else if( ( GetSquareState(index0) == GetSquareState(index2) )!= EMPTY && GetSquareState(index1) == EMPTY )
{
AIMoveX = column;
AIMoveY = row;
//2 element
if(incCol == true)
{
AIMoveX = 1;
}
else
{
AIMoveY = 1;
}
}