hathora-et-labora-game
Version:
Game logic reducer for Uwe Rosenberg's Ora et Labora
29 lines • 1.52 kB
JavaScript
import { addIndex, always, any, curry, filter, identity, map, max, pipe, range, reduce, sum, view } from 'ramda';
import { P, match } from 'ts-pattern';
import { activeLens, getCost, payCost, withActivePlayer } from '../board/player';
import { basicResources, parseResourceParam, stringRepeater } from '../board/resource';
import { ResourceEnum } from '../types';
export const druidsHouse = (input = '', output = '') => {
const { book = 0 } = parseResourceParam(input);
const { wood = 0, clay = 0, grain = 0, penny = 0, sheep = 0, peat = 0 } = parseResourceParam(output);
if (!book)
return identity;
const outputs = [wood, clay, grain, penny, sheep, peat];
if (sum(outputs) !== 8 || any((n) => n === 5, outputs) === false || any((n) => n === 3, outputs) === false) {
return () => undefined;
}
return withActivePlayer(pipe(
//
payCost({ book }), getCost({ wood, clay, grain, penny, sheep, peat })));
};
export const complete = curry((partial, state) => match(partial)
.with([], () => map(
// gross
stringRepeater(ResourceEnum.Book), range(0, 1 + max(1, view(activeLens(state), state).book ?? 0))))
.with([P._], () => addIndex((reduce))((accum, fiveGood, ndx) => {
accum.push(...map((threeGood) => `${stringRepeater(fiveGood, 5)}${stringRepeater(threeGood, 3)}`, filter((r) => r !== fiveGood)(basicResources)));
return accum;
}, [], basicResources))
.with([P._, P._], always(['']))
.otherwise(always([])));
//# sourceMappingURL=druidsHouse.js.map