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.

21 lines 1.13 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 dormitory = (param = '') => { var _a, _b, _c; const input = parseResourceParam(param); const iterations = Math.min(((_a = input.straw) !== null && _a !== void 0 ? _a : 0) + ((_b = input.grain) !== null && _b !== void 0 ? _b : 0), (_c = input.wood) !== null && _c !== void 0 ? _c : 0); return withActivePlayer(pipe( // payCost(input), getCost({ ceramic: 1, book: iterations }))); }; export const complete = curry((partial, state) => match(partial) .with([], () => { const { wood = 0, straw = 0 } = view(activeLens(state), state); return map((n) => `${stringRepeater(ResourceEnum.Wood, n)}${stringRepeater(ResourceEnum.Straw, n)}`, reverse(range(0, 1 + min(wood, straw)))); }) .with([P._], always([''])) .otherwise(always([]))); //# sourceMappingURL=dormitory.js.map