Thread: tic tac toe AI algorithm?

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    106

    tic tac toe AI algorithm?

    ok so i coded a tic tac toe game(470 lines) and now I would like to implement some AI into it so i can have the ability to play myself.. if you can point me into any direction as far as how an AI algorithm for this would work... I also attatched a c++ file so you can run it if you wish
    thanks cJ

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Look up "minimax".

  3. #3
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    there are 19683 possible board combinations, of which only a subset are actually valid. I wrote a tic tac toe AI about 20 years ago that basically just enumerated all possible boards, and kept a record of all moves in the game, when it won it increased the value of the moves it made, when it lost it decreased them. Then run it overnight playing against itself and it will train well enough. During training have it make random moves, but during actual play have it always pick the best possible move.

    It was simple, worked very well, and ran in under 1MB of memory total.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. tic tac toe AI roadblock >:-(|)
    By dark_rocket in forum Game Programming
    Replies: 5
    Last Post: 06-12-2006, 05:13 AM
  2. Tic Tac Toe AI help please...
    By Rune Hunter in forum Game Programming
    Replies: 12
    Last Post: 11-05-2004, 04:24 PM
  3. help with tic tac toe look ahead algorithm
    By heero24 in forum C Programming
    Replies: 1
    Last Post: 03-07-2004, 05:39 AM
  4. tic tac toe AI
    By abrege in forum C++ Programming
    Replies: 4
    Last Post: 12-05-2002, 07:10 AM
  5. not 3x3 tic tac toe game AI
    By Unregistered in forum Game Programming
    Replies: 9
    Last Post: 08-29-2001, 04:02 AM