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.

19 lines 988 B
import { always, curry, map, min, range, reverse, view } from 'ramda'; import { P, match } from 'ts-pattern'; import { activeLens, withActivePlayer } from '../board/player'; import { parseResourceParam, stringRepeater } from '../board/resource'; import { ResourceEnum } from '../types'; export const windmill = (param = '') => { const { grain = 0 } = parseResourceParam(param); const iterations = Math.min(grain, 7); return (state) => state && withActivePlayer((player) => (Object.assign(Object.assign({}, player), { grain: player.grain - iterations, flour: player.flour + iterations, straw: player.straw + iterations })))(state); }; export const complete = curry((partial, state) => match(partial) .with([], () => { const { grain = 0 } = view(activeLens(state), state); return map(stringRepeater(ResourceEnum.Grain), reverse(range(0, 1 + min(7, grain)))); }) .with([P._], always([''])) .otherwise(always([]))); //# sourceMappingURL=windmill.js.map