Tuesday, 22 February 2011

Tic Tac Toe

A little while ago, I got some insperation off a friend of mine. He had been working on his own game called 4 square, which has "elements of Go, Reversi and Arimaa blended" [link]. He was having some trouble with the implimentation of AI, as he was coding the game in Game Maker [link] it was very slow. I myself had never created anything with AI that did more then 1 or 2 functions. A week before this I found a fun library to use for making games known as Allegro, so with my friends motivation I decided to try and make something "simple", like Tic Tac Toe. Or so I thought. The basic mechanics of Tic Tac Toe were no problem at all to impliment, it was the AI that I had most trouble with and ended up having to stop this current project and re-do the whole entire thing. I managed to grasp a small idea on how to approach the AI for Tic Tac Toe after viewing a few online tic tac toe games. Here is a small AI list of steps:
  1. Find a free corner.
  2. Yet again find another free corner.
  3. Check if player needs to be blocked.
  4. Check if AI can win.
  5. Check if there are any optional ways of winning.
  6. Find a free spot.
Notes:
  • Steps 1 and 2 are only for the first 2 moves, as the AI goes first the player will only end up with 2 nodes on the board by the start of step 3.
  • Steps 3 - 5 are repeated continuously throughout the game.
  • Step 6 by the time it hits this step, the game is usually a draw.
Anyway, here is the link to tic tac toe (source included): Click here.
It's obviously not complete as I had made many mistakes throughout coding this project, it was only for me to learn nothing too serious. I will try my best to make a completely new and working version in the near future.

Thanks for reading. I will also be posting many new / old games I have created in the near future with a nice little story behind it.

No comments:

Post a Comment