How AI learns to play games like Tic-Tac-Toe
Summary
Degree programs
Research themes
This activity is part of our Science Lab series. Check out the ANU Science Lab for more experiments! In this activity, you will explore how artificial intelligence (AI) learns to play games through an unplugged computer science challenge. Using noughts and crosses (also known as tic-tac-toe), you will discover how algorithms, rules and strategies help computers make decisions. Watch the video above to see how it works.
Materials
For this activity:
- A few sheets of paper
- Pens or pencils in two different colours
- A partner to play against
- A list of written rules or a notepad to draft your algorithm
How to play unplugged AI noughts and crosses
Step 1: Practise and reflect on strategy
- Draw a standard 3 × 3 noughts and crosses grid on a piece of paper.
- Play a few rounds with your partner, taking turns to place O and X marks.
- Think about the decisions you made during the game. Did you choose the centre square first? Did you aim for the corners? Write down each decision as a clear instruction.
Step 2: Test a basic algorithm
An algorithm is a step-by-step set of instructions used to solve a problem.
Create a simple algorithm by writing the following rules on paper:
- If the centre square is available, place your mark in the centre.
- If you have two marks in a row, place your next mark in the remaining space to win.
- If a corner square is available, place your mark in a corner.
- If the centre and corners are occupied, place your mark in an empty side square.
Play a round with your partner. Both players must follow these rules exactly and cannot make decisions outside the written instructions.
As you play, think about whether the algorithm is missing any important rules.
Step 3: Improve your algorithm
Add another rule to your algorithm:
- If your opponent has two marks in a row, place your mark in the remaining space to block them from winning.
Play the game again using the updated rules.
Did the outcome change? Was it harder to win? Did the game end in a draw?
How does game-playing AI work?
This activity demonstrates some of the key ideas behind computer science and artificial intelligence.
Computers solve problems by following algorithms. An algorithm is simply a sequence of instructions that tells a computer what to do in a particular situation.
When programmers develop AI systems that can play games:
- They create rules that help the AI evaluate different moves.
- The AI follows those rules to decide what action to take.
- Missing or poorly designed rules can cause the AI to make mistakes.
- More advanced AI systems learn by playing many games and improving their decision-making over time.
Rather than relying only on rules written by humans, modern AI systems can identify patterns, test strategies and refine their performance through repeated practice.
The same principles used in game-playing AI can also be applied to real-world challenges. Computer scientists use AI and decision-making algorithms in fields such as robotics, medical research, emergency management and autonomous vehicles.
Science fair project: Take it further
Once you have mastered noughts and crosses, test your algorithm design skills with some new challenges.
- Try writing a complete algorithm for a more complex game such as Connect Four or checkers. How many additional rules are needed to account for the larger board and greater number of possible moves?
- Create two different rule sets. Give one player an aggressive strategy focused on winning quickly and the other player a defensive strategy focused on blocking opponents. Which strategy performs better over multiple games?
- Assign a score to each rule. Add one point when a rule contributes to a win and subtract one point when a rule contributes to a loss. After ten rounds, review the scores and reorder your rules based on their performance. Has your "paper AI" improved its strategy?
- Create a table to record your results and observations. Which rules were the most effective? Which strategies led to the highest win rate? Can you identify a set of rules that rarely loses?
Enjoyed this experiment? Explore more hands-on activities on the Science Lab ANU YouTube channel.