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.

37 lines (34 loc) 1.26 kB
import { always, concat, curry, lift, min, pipe, unnest, view, zip, zipWith } from 'ramda' import { P, match } from 'ts-pattern' import { activeLens, getCost, payCost, withActivePlayer } from '../board/player' import { concatStr, parseResourceParam, resourceArray } from '../board/resource' import { GameStatePlaying, ResourceEnum } from '../types' export const chapel = (param = '') => { const { penny = 0, whiskey = 0, beer = 0 } = parseResourceParam(param) const book = Math.min(1, penny) const reliquary = Math.min(3, whiskey, beer) return withActivePlayer( pipe( // payCost({ penny, whiskey, beer }), getCost({ book, reliquary }) ) ) } export const complete = curry((partial: string[], state: GameStatePlaying): string[] => match(partial) .with([], () => { const { beer = 0, whiskey = 0, penny = 0 } = view(activeLens(state), state) const rqIter = min(beer, whiskey) return lift(concatStr)( zipWith( (a, b) => concat(a, b), resourceArray(ResourceEnum.Beer, 3)(rqIter), resourceArray(ResourceEnum.Whiskey, 3)(rqIter) ), resourceArray(ResourceEnum.Penny, 1)(penny) ) }) .with([P._], always([''])) .otherwise(always([])) )