diff --git a/src/App.tsx b/src/App.tsx index 01f4edb..f1aeb30 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -3,7 +3,7 @@ import { Action } from 'redux'; import { connect } from 'react-redux'; import styled from 'styled-components'; import Board from './components/Board'; -import { Player } from './types/Player'; +import { Player, Winner } from './lib/Player'; import { actions, GameState } from './redux/game'; import GlobalStyle from './theming/GlobalStyle'; diff --git a/src/components/Board.tsx b/src/components/Board.tsx index 950b121..fb8b206 100644 --- a/src/components/Board.tsx +++ b/src/components/Board.tsx @@ -3,9 +3,9 @@ import { connect } from 'react-redux'; import { Action } from 'redux'; import styled from 'styled-components'; import Cell from './Cell'; -import { Player } from '../types/Player'; +import { Player } from '../lib/Player'; import { actions, IGameState } from '../redux/game'; -import { Board } from '../types/Board'; +import { Board } from '../lib/Board'; const Table = styled.table` border: 0; diff --git a/src/components/Cell.tsx b/src/components/Cell.tsx index fc65b4e..1201f02 100644 --- a/src/components/Cell.tsx +++ b/src/components/Cell.tsx @@ -1,7 +1,7 @@ import React from 'react'; import styled from 'styled-components'; -import { Cell, empty } from '../types/Board'; -import { Player } from '../types/Player'; +import { Cell, empty } from '../lib/Board'; +import { Player } from '../lib/Player'; export interface Props { value: Cell; diff --git a/src/lib/Board.ts b/src/lib/Board.ts new file mode 100644 index 0000000..e898c39 --- /dev/null +++ b/src/lib/Board.ts @@ -0,0 +1,14 @@ +import { Player } from './Player'; + +export enum EmptyEnum {} +export type Empty = String & EmptyEnum; +export const empty: Empty = ('empty' as String) as Empty; + +export type Cell = Empty | Player; +export type Cells = Cell[]; +export type Row = Cell[]; +export type Rows = Row[]; + +export type Board = Rows; +export const createEmptyRow = (): Row => [empty, empty, empty]; +export const createEmptyBoard = (): Board => [createEmptyRow(), createEmptyRow(), createEmptyRow()]; diff --git a/src/lib/Player.ts b/src/lib/Player.ts new file mode 100644 index 0000000..28086b8 --- /dev/null +++ b/src/lib/Player.ts @@ -0,0 +1,16 @@ +export enum Player { + X = 'X', + O = 'O', +} + +enum TieEnum {} +type Tie = String & TieEnum; +export const tie: Tie = ('tie' as String) as Tie; + +enum UndeterminedEnum {} +type Undetermined = String & UndeterminedEnum; +export const undetermined: Undetermined = ('undetermined' as String) as Undetermined; + +export type Winner = Player | Tie | Undetermined; + +export default Player; diff --git a/src/lib/scoring.ts b/src/lib/scoring.ts index b8278ad..aa44bf1 100644 --- a/src/lib/scoring.ts +++ b/src/lib/scoring.ts @@ -1,5 +1,5 @@ -import { Board, Cell, Cells, empty, Rows } from '../types/Board'; -import { Winner } from '../types/Player'; +import { Board, Cell, Cells, empty, Rows } from './Board'; +import { Player, Winner, tie, undetermined } from './Player'; enum NoOneEnum {} type INoOne = string | NoOneEnum; diff --git a/src/redux/game.ts b/src/redux/game.ts index 028b09c..4f99dc8 100644 --- a/src/redux/game.ts +++ b/src/redux/game.ts @@ -1,6 +1,6 @@ import { Reducer, Action, Dispatch, MiddlewareAPI } from 'redux'; -import { Player, Winner, undetermined } from '../types/Player'; -import { Board, createEmptyBoard, Cell, empty } from '../types/Board'; +import { Player, Winner, undetermined } from '../lib/Player'; +import { Board, createEmptyBoard, Cell, empty } from '../lib/Board'; import { getBoardSummary } from '../lib/scoring'; export const START_GAME = 'START_GAME'; diff --git a/src/types/Board.ts b/src/types/Board.ts deleted file mode 100644 index 5e394cf..0000000 --- a/src/types/Board.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { Player } from './Player'; - -export enum EmptyEnum {} -export type Empty = string & EmptyEnum; -export const empty: Empty = 'empty' as Empty; - -export type Cell = Empty | Player; -export type Cells = Cell[]; -export type Row = Cell[]; -export type Rows = Row[]; - -export type Board = Rows; -export const createEmptyBoard = (): Board => [[empty, empty, empty], [empty, empty, empty], [empty, empty, empty]]; diff --git a/src/types/Player.ts b/src/types/Player.ts deleted file mode 100644 index cdf9cea..0000000 --- a/src/types/Player.ts +++ /dev/null @@ -1,16 +0,0 @@ -export enum Player { - X = 'X', - O = 'O', -} - -enum TieEnum {} -type Tie = string | TieEnum; -export const tie: Tie = 'tie'; - -enum UndeterminedEnum {} -type Undetermined = string | UndeterminedEnum; -export const undetermined: Undetermined = 'undetermined'; - -export type Winner = Player | Tie | Undetermined; - -export default Player;