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.
32 lines • 1.59 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([], () => {
var _a;
return map(
// gross
stringRepeater(ResourceEnum.Book), range(0, 1 + max(1, (_a = view(activeLens(state), state).book) !== null && _a !== void 0 ? _a : 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