Author Topic: Triple Triad AI  (Read 5032 times)

Alhexx

  • *
  • Posts: 1894
    • View Profile
    • http://www.alhexx.com
Triple Triad AI
« on: 2004-06-05 12:27:31 »
As some of you may have already read in another topic, I've currently started my own version of Triple Triad.
I'm currently starting programming the engine, however, I've got a problem...

I want to add a "Practice" feature as Qhimm did in his TTG.
However, I've got absolutely NO IDEA how program an AI.
Since we have some software/game developers here, I hope you'll be able to help me here...

 - Alhexx

Qhimm

  • Founder
  • *
  • Posts: 1996
    • View Profile
    • Qhimm.com
Triple Triad AI
« Reply #1 on: 2004-06-05 13:27:01 »
You usually start with an evaluation function, in Triple Triad's case the current score. The player will want to maximize his score, and the computer will want to minimize the player's score (= increase its own). Then you need a way to express the current "state" of the game, i.e. which cards have been placed where and which colors they are. Then your most simple AI would simply "practice" on this state, that is simulate what would happen if a certain card was placed in a certain spot, remember the result, undo (or start over) and try the next possibility, until all possibilities have been tried. Then it's just a matter of picking the move that produced the highest benefit = score.

This is roughly how the "Moomba" difficulty in TTG works. More advanced AI:s will search further ahead, that is evaluate what the player's response would be, and the AI:s response to that in turn etc. This practice is pretty much doable in Triple Triad, since the game is small enough for the computer to read all the way to the end of the game.

DeadLajik

  • *
  • Posts: 53
    • View Profile
Triple Triad AI
« Reply #2 on: 2004-06-06 18:47:47 »
What I did, when I had to program AI for some simple game, is have the AI player build a game tree. Depending on how simple the game is.. there are different techniques. I represented my game tree with a 3 dimensional array of around 30 elements. The game was simple enough where I could implement the entire tree in memory, but for advanced games, like Chess this is impossible.

For a game like tripple triad you'd have to calculate different states and put these states into a game tree like structure. The computer would calculate these states and mark them based on who is likely to win. E.g. "If I play this card here.. can I possibly win?? No? Then what if I put it in the next sqaure?".  It would then continue to expand the nodes and build the tree further in areas where it had a better chance of winning since the AI player wants to go down that branch of the tree.

I know this probably doesn't make any sense, but if you can get an AI book you'll want to look into some of the MIN-MAX algorithms and ALPHA-BETA tree pruning. The books I have use the classical tic-tac-toe example to explain how they work but you should be able to adapt it to tripple triad.

At the beginning of the game there will be a lot of stuff to calculate so you could make it a little faster by forcing the computer to play a cards that should be played in certain spots..

e.g.  if you represent a cards numbers by {Left,Top,Right,Bottom} and the AI has a card like {0,0,A,A}, you would force him to play that card in the top left corner.

Hope that helps.

Kislinskiy

  • Guest
Triple Triad AI
« Reply #3 on: 2004-06-06 19:34:59 »