UNPKG

@gamepark/rules-api

Version:

API to implement the rules of a board game

19 lines 823 B
import { applyAutomaticMoves } from './automatic-moves.util'; import { hasRandomMove } from './random.util'; export function playAction(rules, move, playerId) { if (hasRandomMove(rules)) { move = rules.randomize(move, playerId); } const action = { playerId, move, consequences: [] }; const consequences = rules.play(JSON.parse(JSON.stringify(move))); applyAutomaticMoves(rules, consequences, move => action.consequences.push(move)); return action; } export function replayAction(rules, action) { rules.play(JSON.parse(JSON.stringify(action.move))); action.consequences.forEach(move => rules.play(JSON.parse(JSON.stringify(move)))); } export function replayActions(rules, actions) { actions.forEach(action => replayAction(rules, action)); } //# sourceMappingURL=action.util.js.map