Simulate Moves by Producing New Game States
Simulate Moves by Producing New Game States. The last property that you’ll add to your
GameState class is a fixed list of possible moves, which you can find by filling the remaining empty cells in the grid with the current player’s mark.
If the game is not over, you identify the locations of empty cells using a regular expression, and then make a move to each of those cells. Making a move creates a new
Move object, which you append to the list without mutating the game state.
02:20 And that’s it. You’ve now got a solid domain model of the tic-tac-toe game, which you can use to build interactive games for various front ends. The model encapsulates the game’s rules and enforces its constraints.
Become a Member to join the conversation.