tic-tac-toe-finite-state-machine icon indicating copy to clipboard operation
tic-tac-toe-finite-state-machine copied to clipboard

An exercise to build a tic-tac-toe finite state machine in typescript and xstate

Tic-Tac-Toe State Machine

This was an experiment of mine both to learn Typescript and also Xstate. The state machine has 5,478 game states, and three "final" states of X_WINS, O_WINS, or DRAW.

The state chart was generated by a fairly simple recursive algorithm, the details of which are left up to the reader as an exercise.

The only game assumption is that X always goes first.

Run It!! 👀

If you paste the contents of machine.ts into the Xstate Visualizer, you get something that looks like the following. Pretty simple!! 🙄

StateChart

Run Locally

Based on create-react-app.

npm install
npm start