UNPKG

hathora-et-labora-game

Version:

Game logic reducer for Uwe Rosenberg's Ora et Labora

26 lines (23 loc) 765 B
import { always, curry, pipe, view } from 'ramda' import { P, match } from 'ts-pattern' import { activeLens, getCost, payCost, withActivePlayer } from '../board/player' import { parseResourceParam } from '../board/resource' import { GameState, StateReducer } from '../types' export const malthouse = (param = ''): StateReducer => { const { grain = 0 } = parseResourceParam(param) return withActivePlayer( pipe( payCost({ grain }), getCost({ malt: grain, straw: grain, }) ) ) } export const complete = curry((partial: string[], state: GameState): string[] => match(partial) .with([], () => (view(activeLens(state), state).grain ? ['Gn', ''] : [''])) .with([P._], always([''])) .otherwise(always([])) )