Skip to main content
GameDev.net gamedev.net

PRO Tired of ads? Read GameDev.net ad-free and help keep the community independent with GameDev Pro — $3/month.

Tic-Tac-Toe

Tic-Tac-Toe

uavfun
Random things uavfun thinks are cool · · 1 min read
1,393 0
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;}// Diagonalif (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.

Discussion

Loading comments...