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.
22 lines • 1.13 kB
JavaScript
import { always, curry, identity, map, 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 camera = (param = '') => {
const { book = 0, ceramic = 0 } = parseResourceParam(param);
const iterations = Math.min(2, book, ceramic);
if (!iterations)
return identity;
return withActivePlayer(pipe(
//
payCost({ book: iterations, ceramic: iterations }), getCost({ penny: iterations, clay: iterations, reliquary: iterations })));
};
export const complete = curry((partial, state) => match(partial)
.with([], () => {
const { book = 0, ceramic = 0 } = view(activeLens(state), state);
return map((iterations) => `${stringRepeater(ResourceEnum.Straw, iterations)}${stringRepeater(ResourceEnum.Wood, iterations)}`, reverse(range(0, 1 + Math.min(book, ceramic, 2))));
})
.with([P._], always(['']))
.otherwise(always([])));
//# sourceMappingURL=camera.js.map