• Advertisement
Sign in to follow this  
  • entries
    14
  • comments
    17
  • views
    5609

Tic-Tac-Toe

Sign in to follow this  

172 views

Source + installer (needs .NET Framework 2.0).

AI is moderately stupid, it will go for an obvious win or block yours but that's about it.

Summary of victory checking, since someone was asking about it:

For each player 'p':

bool won = false;
for (int i = 0; i < 3; i++)
{
// Column
if (gameBoard == p && gameBoard[i + 3] == p && gameBoard[i + 6] == p)
won = true;

// Row
if (gameBoard[i * 3] == p && gameBoard[i * 3 + 1] == p && gameBoard[i * 3 + 2] == p)
won = true;
}

// Diagonal
if (gameBoard[4] == p) // center
{
if (gameBoard[0] == p && gameBoard[8] == p)
won = true;
if (gameBoard[2] == p && gameBoard[6] == p)
won = true;
}


Nothing fancy, just brute force.

Yeah, I was bored. Yeah, I'll get back to the asteroids thing.
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement