What I am curious about is if there are any other ways that I'm not thinking of. I'm very curious to see what you guys have come up with, I think it would benefit all of us if we shared our algorithms - there's always room for learning, right? If you have something you'd like to share with the community, come on down!
This is my code:
Code: Select all
int Game::doAITurn()
{
int yCOOR = 0;
int xCOOR = 0;
for (yCOOR = 0; yCOOR < 3; yCOOR++)
{
xCOOR = 0;
if (getSquareState(xCOOR, yCOOR) == getSquareState(xCOOR , (yCOOR + 1) % 3) && getSquareState(xCOOR, yCOOR) != EMPTY)
{
AIMoveX = xCOOR;
AIMoveY = (yCOOR + 2) % 3;
if (getSquareState(AIMoveX, AIMoveY) == EMPTY)
{
//break
return 0;
}
}
for (xCOOR = 0; xCOOR < 3; xCOOR++)
{
if (getSquareState(xCOOR, yCOOR) == getSquareState((xCOOR + 1) % 3, yCOOR) && getSquareState(xCOOR, yCOOR) != EMPTY)
{
AIMoveY = yCOOR;
AIMoveX = (xCOOR + 2) % 3;
if (getSquareState(AIMoveX, AIMoveY) == EMPTY)
{
//break
return 0;
}
}
}
}
}