UNPKG

hathora-et-labora-game

Version:

Game logic reducer for Uwe Rosenberg's Ora et Labora

33 lines 1.17 kB
import { always, cond, curry, identity, pipe, reduce, view } from 'ramda'; import { P, match } from 'ts-pattern'; import { getCost, withActivePlayer, payCost, activeLens } from '../board/player'; import { parseResourceParam, totalGoods, differentGoods, allResource, combinations } from '../board/resource'; export const market = (input = '') => { const goods = parseResourceParam(input); return cond([ [always(input === ''), identity], [ always(totalGoods(goods) === 4 && differentGoods(goods) === 4), withActivePlayer(pipe(payCost(goods), getCost({ bread: 1, nickel: 1, penny: 2, }))), ], ]); }; export const complete = curry((partial, state) => match(partial) .with([], () => { const player = view(activeLens(state), state); return [ ...combinations(4, reduce((accum, [key, token]) => { if (player[key]) accum.push(token); return accum; }, [], allResource)), '', ]; }) .with([P._], always([''])) .otherwise(always([]))); //# sourceMappingURL=market.js.map