hathora-et-labora-game
Version:
Game logic reducer for Uwe Rosenberg's Ora et Labora
35 lines • 1.36 kB
JavaScript
import { always, ap, concat, curry, identity, pipe, view } from 'ramda';
import { match, P } from 'ts-pattern';
import { activeLens, payCost, withActivePlayer } from '../board/player';
import { parseResourceParam, shortGameBonusProduction } from '../board/resource';
import { advanceJokerOnRondel, takePlayerJoker } from '../board/rondel';
import { ResourceEnum } from '../types';
export const cooperage = (input = '', output = '') => {
const { wood = 0 } = parseResourceParam(input);
if (wood < 3)
return identity;
const out = match(parseResourceParam(output))
.with({ whiskey: P.when((n) => n && n > 0) }, () => ({ whiskey: 1 }))
.with({ beer: P.when((n) => n && n > 0) }, () => ({ beer: 1 }))
.otherwise(() => ({}));
return pipe(
//
withActivePlayer(payCost({ wood })), takePlayerJoker(out), advanceJokerOnRondel, shortGameBonusProduction(out));
};
export const complete = curry((partial, state) => match(partial)
.with([], () => {
const { wood = 0 } = view(activeLens(state), state);
if (wood <= 3)
return [''];
return [
...ap([
//
concat(ResourceEnum.Beer),
concat(ResourceEnum.Whiskey),
], ['WoWoWo']),
'',
];
})
.with([P._], always(['']))
.otherwise(always([])));
//# sourceMappingURL=cooperage.js.map