- Understand the problem
- Break things down into sub-problems
- Look for patterns and generalise
- Make a model of the real world
- Write an algorithm
- Translate into code
Find an online version for them to play, or just a collaborative drawing app like Zoom Whiteboard
- Draw a 3x3 grid of squares
- Pick a player to go first
- Pick a value (X)
- Pick a square
- if the square is not empty, you can't pick it
- if the square is empty, you can pick it
- Check if someone has won
- if someone won, the game ends and they are declared the winner
- Next player
- Pick a value (O)
- Pick a square
- if the square is not empty, you can't pick it
- if the square is empty, you can pick it
- Check if someone has won
- Next player (X)
- ...
- Someone won, game ends
Player Move:
- Pick a square
- if the square is not empty, you can't pick it
- if the square is empty, you can pick it
- Check if someone has won
- if someone won, the game ends and they are declared the winner
- Next player
- Players - X or O
- Board -
[]
,[[]]
,string
,number
if you really wanted (each number represents a possible board state)
*There are 9 positions and an alphabet with 3 letters (X, O, empty). Total number of possible combinations is 3^9 = 19683. There are 5477 possible legal game states.
- Draw a 3x3 grid of squares
- First player is X
- Player Move:
- Choose a square
- if the square is not empty, you can't pick it
- if the square is empty, you can pick it - put the player symbol in that square
- Check if someone has won
- how?
- if they won, game over
- if not, next player move
State, behaviour, dependencies, show -> State, functions, props, render
Wireframe. View parts. Behaviour parts.
Your turn: X
Goes to these components:
-
Game
- State
- board = [null,null,null,null,null,null,null,null,null] <- "X", "O", or null
- x's turn = true | false
- Behaviour
- make a move
- if the square is not empty, you can’t pick it
- if the square is empty, you can pick it - put the player symbol in that square
- check winner
- check if there’s matching symbols in rows, columns, or diagonals
- if there is, the game ends and the symbol wins
- if the board is full, the game ends as a draw
- make a move
- Render
- Board
- Who’s turn is it?
- Winner
- State
-
Board
- Props
- board
- make a move
- Render
- Squares - 1 for each item in board, arranged into a grid
- Props
-
Square
- Props
- make a move
- value
- Render
- value
- Props