Last active
October 15, 2020 15:45
-
-
Save codingedgar/3e1fdb6d3138bab2a10ba2c925268fab to your computer and use it in GitHub Desktop.
example1 types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type Player = 'X' | 'O' | |
| type Coordinate = 1 | 2 | 3 | |
| type Coordinates = { row: Coordinate; column: Coordinate } | |
| type CellState = { kind: 'Playable' } | { kind: 'Played', player: Player } | |
| type Cell = Coordinates & { state: CellState } | |
| type Board = [Cell, Cell, Cell, Cell, Cell, Cell, Cell, Cell, Cell] | |
| type ResultType = | |
| | 'Draw' | |
| | 'Row1' | |
| | 'Row2' | |
| | 'Row3' | |
| | 'Column1' | |
| | 'Column2' | |
| | 'Column3' | |
| | 'Diagonal1' | |
| | 'Diagonal2' | |
| type Result = { type: Extract<ResultType, 'Draw'> } | { type: Exclude<ResultType, 'Draw'>, player: Player } | |
| type Event = | |
| | PlayedEvent | |
| | RestartedEvent | |
| type RestartedEvent = { type: 'RESTARTED' } | |
| type PlayedEvent = { type: 'PLAYED', payload: Coordinates } | |
| type Context = | |
| { | |
| matchScore: MatchScore | |
| board: Board | |
| result: Option<Result> | |
| } | |
| type MatchScore = Record<ResultType, Option<{ player: Player, count: number }>> | |
| type Scheme = { | |
| states: { | |
| X: {} | |
| O: {} | |
| DONE: {} | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment