I was wondering how you guys did the homework. I've nearly finished making an algorithm that plays perfectly(code is below).
I originally had it checking for conditions like
Code: Select all
if(s1==X && s2==X && s0=EMPTY){
AIMoveX=0;
AIMoveY=0;
}
I hope he covers more advance AI techniques later on.
But, was wondering how you do the next part I.e. make it move the cursor towards it. Wouldn't you have to create a new function that changes the position of the cursor. Can someone give me a hint on how they did it?
Code: Select all
void Game::AIGetMoveRand()
{
if(nTurns== 0)
{
AIMoveX = 0;
AIMoveY = 0;
}
if(nTurns==2)
{
if(s4==O)
{
AIMoveX=2;
AIMoveY=2;
} else if (s1==EMPTY&& s2==EMPTY)
{
AIMoveX=2;
AIMoveY=0;
} else {
AIMoveX=0;
AIMoveY=2;
}
}
if(nTurns == 4)
{
if(s8==X){
AIMoveX=2;
AIMoveY=0;
} else if(s2==X && s1==EMPTY){
AIMoveX=1;
AIMoveY=0;
} else if(s2==X && s1==O)
{
AIMoveX=1;
AIMoveY=1;
} else if(s3==EMPTY&& s6==X)
{
AIMoveX=0;
AIMoveY=1;
} else {
AIMoveX=1;
AIMoveY=1;
}
}
}
For example if I knew he played on the centre, is there a way to stay in the loop that is player 2 played O in the centre on turn 1 and not have to check every possibility again?