UNPKG

@gamepark/rules-api

Version:

API to implement the rules of a board game

25 lines 1.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.replayActions = exports.replayAction = exports.playAction = void 0; var automatic_moves_util_1 = require("./automatic-moves.util"); var random_util_1 = require("./random.util"); function playAction(rules, move, playerId) { if ((0, random_util_1.hasRandomMove)(rules)) { move = rules.randomize(move, playerId); } var action = { playerId: playerId, move: move, consequences: [] }; var consequences = rules.play(JSON.parse(JSON.stringify(move))); (0, automatic_moves_util_1.applyAutomaticMoves)(rules, consequences, function (move) { return action.consequences.push(move); }); return action; } exports.playAction = playAction; function replayAction(rules, action) { rules.play(JSON.parse(JSON.stringify(action.move))); action.consequences.forEach(function (move) { return rules.play(JSON.parse(JSON.stringify(move))); }); } exports.replayAction = replayAction; function replayActions(rules, actions) { actions.forEach(function (action) { return replayAction(rules, action); }); } exports.replayActions = replayActions; //# sourceMappingURL=action.util.js.map