hathora-et-labora-game
Version:
Game logic reducer for Uwe Rosenberg's Ora et Labora
25 lines (22 loc) • 727 B
text/typescript
import { always, curry, xor } from 'ramda'
import { P, match } from 'ts-pattern'
import { getCost, withActivePlayer } from '../board/player'
import { parseResourceParam } from '../board/resource'
import { GameState, StateReducer } from '../types'
export const falseLighthouse = (param = ''): StateReducer => {
const { whiskey = 0, beer = 0 } = parseResourceParam(param)
if (!xor(whiskey === 1, beer === 1)) return () => undefined
return withActivePlayer(
getCost({
penny: 3,
whiskey,
beer,
})
)
}
export const complete = curry((partial: string[], state: GameState): string[] =>
match(partial)
.with([], always(['Be', 'Wh']))
.with([P._], always(['']))
.otherwise(always([]))
)