UNPKG

hathora-et-labora-game

Version:

Game logic reducer for Uwe Rosenberg's Ora et Labora

34 lines 1.44 kB
import { always, curry, pipe, reduce, view } from 'ramda'; import { P, match } from 'ts-pattern'; import { activeLens, getCost, payCost, withActivePlayer } from '../board/player'; import { parseResourceParam, totalGoods, differentGoods, multiplyGoods, maskGoods, allResource, combinations, basicResources, } from '../board/resource'; const ALLOWED_OUTPUT = ['peat', 'clay', 'wood', 'sheep', 'grain', 'penny']; export const cloisterCourtyard = (input = '', output = '') => { const inputs = parseResourceParam(input); const outputs = parseResourceParam(output); if (totalGoods(inputs) !== 3) return () => undefined; if (differentGoods(inputs) !== 3) return () => undefined; if (totalGoods(maskGoods(ALLOWED_OUTPUT)(outputs)) !== 1 || differentGoods(outputs) !== 1) return () => undefined; return withActivePlayer(pipe( // payCost(inputs), getCost(multiplyGoods(6)(outputs)))); }; export const complete = curry((partial, state) => match(partial) .with([], () => { const player = view(activeLens(state), state); return [ ...combinations(3, reduce((accum, [key, token]) => { if (player[key]) accum.push(token); return accum; }, [], allResource)), '', ]; }) .with([P._], () => basicResources) .with([P._, P._], always([''])) .otherwise(always([]))); //# sourceMappingURL=cloisterCourtyard.js.map