Skip to content

Instantly share code, notes, and snippets.

@codingedgar
Last active October 15, 2020 15:45
Show Gist options
  • Select an option

  • Save codingedgar/3e1fdb6d3138bab2a10ba2c925268fab to your computer and use it in GitHub Desktop.

Select an option

Save codingedgar/3e1fdb6d3138bab2a10ba2c925268fab to your computer and use it in GitHub Desktop.
example1 types
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