UNPKG

hathora-et-labora-game

Version:

Plays Uwe Rosenberg's Ora et Labora for the Hathora engine. It reduces a list of moves into a board game state.

32 lines 1.2 kB
import { always, curry, pipe, reduce, view } from 'ramda'; import { P, match } from 'ts-pattern'; import { activeLens, getWonder, payCost, withActivePlayer } from '../board/player'; import { allResource, combinations, differentGoods, parseResourceParam } from '../board/resource'; import { removeWonder } from '../board/state'; const check13DifferentGoods = (input) => (player) => { const count = differentGoods(input); if (count !== 13) return undefined; return player; }; export const chamberOfWonders = (param = '') => (state) => { const inputs = parseResourceParam(param); return pipe(withActivePlayer(pipe( // check13DifferentGoods(inputs), payCost(inputs), getWonder())), removeWonder)(state); }; export const complete = curry((partial, state) => match(partial) .with([], () => { const player = view(activeLens(state), state); return [ ...combinations(13, reduce((accum, [key, token]) => { if (player[key]) accum.push(token); return accum; }, [], allResource)), '', ]; }) .with([P._], always([''])) .otherwise(always([]))); //# sourceMappingURL=chamberOfWonders.js.map