UNPKG

hathora-et-labora-game

Version:

Game logic reducer for Uwe Rosenberg's Ora et Labora

41 lines 1.71 kB
import { always, curry, identity, pipe, view } from 'ramda'; import { P, match } from 'ts-pattern'; import { addBonusAction } from '../board/frame'; import { activeLens, withActivePlayer } from '../board/player'; import { BuildingEnum, GameCommandEnum } from '../types'; import { forestLocations, forestLocationsForCol } from '../board/landscape'; const checkSpotIsForest = (col, row) => withActivePlayer((player) => { if (player.landscape[row + player.landscapeOffset][col + 2][1] !== BuildingEnum.Forest) return undefined; return player; }); const removeForestAt = (col, row) => withActivePlayer((player) => player && { ...player, landscape: [ ...player.landscape.slice(0, row + player.landscapeOffset), [ ...player.landscape[row + player.landscapeOffset].slice(0, col + 2), [player.landscape[row + player.landscapeOffset][col + 2][0]], ...player.landscape[row + player.landscapeOffset].slice(col + 2 + 1), ], ...player.landscape.slice(row + player.landscapeOffset + 1), ], }); export const carpentry = (col, row) => { if (Number.isNaN(col) || Number.isNaN(row)) return identity; return pipe( // checkSpotIsForest(col, row), removeForestAt(col, row), addBonusAction(GameCommandEnum.BUILD)); }; export const complete = curry((partial, state) => { const player = view(activeLens(state), state); return match(partial) .with([], () => [...forestLocations(player), '']) .with([P._], ([c]) => { return [...forestLocationsForCol(c, player)]; }) .with([P._, P._], always([''])) .otherwise(always([])); }); //# sourceMappingURL=carpentry.js.map