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.
34 lines • 1.47 kB
JavaScript
import { always, curry, 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 = (row, col) => withActivePlayer((player) => {
if (player.landscape[row][col + 2][1] !== BuildingEnum.Forest)
return undefined;
return player;
});
const removeForestAt = (row, col) => withActivePlayer((player) => player && Object.assign(Object.assign({}, player), { landscape: [
...player.landscape.slice(0, row),
[
...player.landscape[row].slice(0, col + 2),
[player.landscape[row][col + 2][0]],
...player.landscape[row].slice(col + 2 + 1),
],
...player.landscape.slice(row + 1),
] }));
export const carpentry = (row, col) => pipe(
//
checkSpotIsForest(row, col), removeForestAt(row, col), 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