Advertisement Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    14
  • comments
    17
  • views
    5724

Tic-Tac-Toe

Sign in to follow this  
uavfun

229 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
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!