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.
42 lines • 2.32 kB
JavaScript
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import { add, always, curry, map, min, pipe, range, reverse, unnest, view } from 'ramda';
import { P, match } from 'ts-pattern';
import { activeLens, getCost, payCost, withActivePlayer } from '../board/player';
import { costMoney, parseResourceParam, stringRepeater } from '../board/resource';
import { ResourceEnum } from '../types';
export const cloisterLibrary = (inputs = '') => {
const input = parseResourceParam(inputs);
const { book = 0 } = input, inputWithoutBook = __rest(input, ["book"]);
const newBooks = Math.min(costMoney(inputWithoutBook), 3);
const soldBook = Math.min(book !== null && book !== void 0 ? book : 0, 1);
return withActivePlayer(pipe(
//
payCost(inputWithoutBook), getCost({ book: newBooks }), payCost({ book: soldBook }), getCost({ meat: soldBook, wine: soldBook })));
};
export const complete = curry((partial, state) => match(partial)
.with([], () => {
const player = view(activeLens(state), state);
const { penny = 0, book = 0 } = player;
// step 1: figure out how many times we might send in penny, given max pennies
const pennyAmounts = reverse(range(0, 1 + Math.min(3, penny)));
// step 2: for each amount of penny, figure out how many books they would have
const paymentAmounts = map((pennyAmount) => [pennyAmount + book, stringRepeater(ResourceEnum.Penny, pennyAmount)], pennyAmounts);
// then for each of those, sell 0 or 1 book if there are any
const consumeBreadAmounts = unnest(map(([sellableBooks, resourceString]) => pipe(
//
min(1), add(1), range(0), (reverse), map(stringRepeater(ResourceEnum.Book)), map((s) => resourceString + String(s)))(sellableBooks), paymentAmounts));
return consumeBreadAmounts;
})
.with([P._], always(['']))
.otherwise(always([])));
//# sourceMappingURL=cloisterLibrary.js.map