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.

20 lines 1.04 kB
import { always, curry, map, min, pipe, range, reverse, view } from 'ramda'; import { P, match } from 'ts-pattern'; import { activeLens, getCost, payCost, withActivePlayer } from '../board/player'; import { parseResourceParam, stringRepeater } from '../board/resource'; import { ResourceEnum } from '../types'; export const slaughterhouse = (param = '') => { var _a, _b; const inputs = parseResourceParam(param); return withActivePlayer(pipe( // payCost(inputs), getCost({ meat: Math.min((_a = inputs.sheep) !== null && _a !== void 0 ? _a : 0, (_b = inputs.straw) !== null && _b !== void 0 ? _b : 0) }))); }; export const complete = curry((partial, state) => match(partial) .with([], () => { const { sheep = 0, straw = 0 } = view(activeLens(state), state); return map((n) => `${stringRepeater(ResourceEnum.Sheep, n)}${stringRepeater(ResourceEnum.Straw, n)}`, reverse(range(0, 1 + min(sheep, straw)))); }) .with([P._], always([''])) .otherwise(always([]))); //# sourceMappingURL=slaughterhouse.js.map