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.
40 lines • 1.6 kB
JavaScript
import { always, curry, identity, pipe, view } from 'ramda';
import { P, match } from 'ts-pattern';
import { activeLens, getCost, withActivePlayer } from '../board/player';
import { BuildingEnum } from '../types';
import { forestLocations, forestLocationsForCol } from '../board/landscape';
// TODO: refactor this with carpentry
const checkSpotIsForest = (row, col) => (player) => {
if (player === undefined)
return undefined;
if (player.landscape[row][col + 2][1] !== BuildingEnum.Forest)
return undefined;
return player;
};
const removeForestAt = (row, col) => (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 forestHut = (row, col) => {
if (row === undefined || col === undefined)
return identity;
return withActivePlayer(pipe(
//
checkSpotIsForest(row, col), removeForestAt(row, col), getCost({ sheep: 2, wood: 2, stone: 1 })));
};
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=forestHut.js.map