It's just a Tic-Tac-Toe game.
Rules :
- Do a line with 3 cross/circle to win
To add later :
- AI to play against the player
- Add music/sound effect (SFX when drawing a cross/circle is pretty annoying)
Roucasse, years ago I pondered if there was some formula or table in to building an unbeatable Tic Tac Toe. That is, no thinking was required on the part of the computer. And - I solved it.
21673498
Player Computer 1 | 2 | 3 2 | 1 | 6 --+---+-- --+---+-- 4 | X | 6 7 | X | 3 --+---+-- --+---+-- 7 | 8 | 9 4 | 9 | 8 |
The computer always starts, always uses X, and always starts in the center. Then it's the player's turn. From the table you can see that if the player goes to square 1 then it will 'think' and go to square 2.
For square 8, the computer will go to square 9.
There is no way the player can win, the computer does not overwrite its own or the player's move, and the game can only end in a CAT or the computer wins, one or the other.
Tic Tac Toe today is a little trickier. You want to create a situation where you can get a TIC TAC TOE from 2-different ways, so even if your opponent blocks one, you get them on the next. :)
You might also look at this:
http://www.wikihow.com/Sample/Tic-Tac-Toe-Strategies
Now while Tic Tac Toe is interesting, what might be more challenging and fun would be to enter in the SIZE of the board, not just 3x3 but 3x4, 4x3, 4x4, or even 7x7.
Then you also get to choose how many you might have in a row, column, or diagonally.
So it might be possible to play on a 7x7 board, but the winning condition would be to only get 3 connected.
Makes for a unique and challenging game to play and program ! :)
What I'd suggest? Randomize the array of spaces for CPU's third option. Then:
IF youcanwin : win
ELSEIF youcanblock : block
ELSEIF space.previous + 1 (available) : space.previous+1
ELSEIF space.previous + 2 (available) : space.previous+2
...
Then since it's semi-random; let the AI go first.
[Please log in to post a comment]