-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
28 lines (23 loc) · 826 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { updateState, findPossibleActions, diceRollAction } from './src/game';
import { createState } from './src/state';
import { partial } from 'lodash';
export function continueGame(state) {
const getState = () => state;
const nextActionType = () => state.get('nextActionType');
const rollDice = diceRollAction(state.get('playerTurn'));
const getPossibleActions = partial(findPossibleActions, state);
const update = (action) => continueGame(updateState(state, action));
return Object.freeze({
getState,
nextActionType,
rollDice,
getPossibleActions,
update
});
}
export function createGame({ playerCount }) {
if (playerCount <= 0 || playerCount >= 5) {
throw new Error('Cannot create game with the player count specified');
}
return continueGame(createState(playerCount));
}