There is zero JavaScript to play this game of Tic-Tac-Toe, only TypeScript type definitions. You'll notice everything in src
is written as .d.ts
files to prove this to you.
There are also tests to validate the functionality of the games' components.
The game is set up and ready to play in ./game-demo.ts
. The board that's set up is structed like so:
type Board = [
["1", "2", "3"],
["4", "5", "6"],
["7", "8", "9"],
];
To play a move, you use the Prompt
type:
type TurnOne = Prompt<Board, "7">;
This will play X
where the "7"
previously was, and the "AI" will automatically play "O"
:
type Board = [
["O", "2", "3"],
["4", "5", "6"],
["X", "8", "9"],
];
When a few moves are played:
type Board = [
["O", "O", "3"],
["4", "5", "6"],
["X", "X", "9"],
];
Prompt<Board, "9">
It will output: "Player wins!"
or "Computer wins!"
depending on who last played.
ai.ts
, everything else should support thiswin-conditions.ts
.