Q U A R T O

Background:
Quarto is a classic board game played by 2 players. The object is to place 4 pieces in a row with at least 1 shared attribute (tall, short, square, circle, light, dark, holes, no holes). Each player selects the piece that their opponent must use.

Flash Game:
Playing the game is rather straightforward. Simply click a piece to select it, and a square on the board to place the piece there. Please note that you must have Flash 5 or higher installed in order to play this game. Otherwise, the game may show up but will not work.
- - Click Here to launch game - -

Project Info:
I became interested in Quarto several years ago, after seeing it on display in a game store. I created a game board and pieces out of some wood in my garage, and played a fair number of games against my friends/family. Unfortunately, my opponents eventually lost interest in the game, and I craved a greater challenge. Thus, the idea of an AI opponent was born. I envisioned a Flash-based project from the start, and only after its completion did I actually check for other Quarto AI's on the net. There is a rather impressive Java applet version here that is capable of computing the perfect game, every time. It also takes a darn long time to run perfectly. My algorithm is somewhat simpler...

Algorithm:
My challenge was to make a game that, while not perfect, would still be fun to play and would run quickly in the average browser. To this end, I devised a relatively simple algorithm in Javascript that would compute a rather intelligent move with a maximum of 1 second execution time on the PC I was using. By creating in Javascript, it would be easy to later paste that code into Flash, adding appropriate graphics/animations/sounds. You can look at the code for my functional text mockup. Please note that this is just test code... it plays well, but is not optimised, and only works with IE.

Basic play consists of 3 basic rules:

  1. When placing a piece, win if possible.
  2. When selecting a piece, choose one that cannot be used to win.
  3. When placing a piece in a non-win condition, place piece in such a way that Rule #2 can still be satisfied immediately following.
Hard difficulty mode uses all 3 of these rules. Easy only uses Rule #1, and Brain-Dead randomly chooses pieces/squares with no intelligence at all.

Getting everything to work in Flash was an interesting challenge. While Flash 5 has full Javascript support, it does NOT have the same execution time as a browser. I was horrified to get everything in and working, only to find that the game had slowed to an almost unplayable pace. So, I began stepping through every piece of the algorithm, elminating overt CPU waste and in general optimising the heck out of everything. This was almost, but not quite, enough. To get that last little speed boost needed to make the game reasonably pleasurable, I re-arranged when the AI processing was called. By carefully placing the calls before/after certain animation sequences, I was able to hide much of the execution time, and make the game appear to play faster.