UNPKG

@gamepark/rules-api

Version:

API to implement the rules of a board game

44 lines 1.51 kB
import { MaterialMoveBuilder } from '../moves'; import { MaterialRulesPart } from './MaterialRulesPart'; /** * Base class for any part of the rules where multiple players have to do something at the same time. */ export class SimultaneousRule extends MaterialRulesPart { endPlayerTurn = MaterialMoveBuilder.endPlayerTurn; /** * See {@link Rules.isTurnToPlay} */ isTurnToPlay(player) { return this.game.rule?.players?.includes(player) ?? false; } /** * @returns all the active players */ get activePlayers() { return this.game.rule?.players ?? []; } /** * See {@link Rules.getLegalMoves} */ getLegalMoves(player) { return this.isTurnToPlay(player) ? this.getActivePlayerLegalMoves(player) : []; } /** * This function is called immediately after a {@link EndPlayerTurn} has been played. * @param _move The move which has just been played * @param _context Context of execution * @returns {MaterialMove[]} Any consequences that should automatically be played after the move */ onPlayerTurnEnd(_move, _context) { return []; } } /** * Type guard to know if a {@link MaterialRulesPart} is a {@link SimultaneousRule} * @param rule The rule * @returns true if the rule if a {@link SimultaneousRule} */ export function isSimultaneousRule(rule) { return rule !== undefined && typeof rule.getMovesAfterPlayersDone === 'function'; } //# sourceMappingURL=SimultaneousRule.js.map