Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

What are the algorithms I could use to create an AI for the game TicTacToe. I have already used Alpha–beta pruning and Predictive modelling. What the other good Algorithms I can use to create this AI.

I want to practice a new language this would a great way to learn a new language.

Thanks

share|improve this question

closed as off-topic by MichaelT, World Engineer Oct 6 '13 at 16:46

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about what language, technology, or project one should take up next are off topic on Programmers, as they can only attract subjective opinions for answers. There are too many individual factors behind the question to create answers that will have lasting value. You may be able to get help in The Whiteboard, our chat room." – MichaelT, World Engineer
If this question can be reworded to fit the rules in the help center, please edit the question.

5  
solve it –  MichaelT Oct 6 '13 at 12:31
2  
welcome to programmers. List questions are frowned upon on this website. –  Simon Oct 6 '13 at 13:48
    
@Simon what do you mean? –  Taufiq Oct 6 '13 at 13:51
1  
@Taufiq please check here for more information. In particular You should only ask practical, answerable questions based on actual problems that you face. Generally, asking questions like please provide a list of items that can do X or what should I do next should be avoided. You should also try to demonstrate that you have tried to answer the question yourself, which is not the case here. –  Simon Oct 6 '13 at 14:14
2  
@Taufiq practical, answerable questions based on actual problems is an entire Stack Exchange network wide guideline. –  MichaelT Oct 6 '13 at 16:18

1 Answer 1

Since Tic-Tac-Toe is a solved game, I would recommend simply playing a perfect game every time.

The following algorithm will allow you (or the AI) to always deny your opponent victory:

  1. Win:
    If you have two in a row, you can place a third to get three in a row.
  2. Block:
    If the opponent has two in a row, you must play the third to block the opponent.
  3. Fork:
    Create an opportunity where you have two threats to win (two non-blocked lines of 2).
  4. Blocking an opponent's fork:
    If there is a configuration where the opponent can fork, you must block that fork.
  5. Center:
    You play the center if open.
  6. Opposite corner:
    If the opponent is in the corner, you play the opposite corner.
  7. Empty corner:
    You play in a corner square.
  8. Empty side:
    You play in a middle square on any of the 4 sides.

Pick the highest possible on the list

The perfect heuristic is pretty simple in terms of AI programming. The most difficult heuristic part to implement is searching for fork configurations. Once you have that the other checks are next to trivial!

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.