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.
32 lines • 978 B
JavaScript
import { always, pipe } from 'ramda';
import { match } from 'ts-pattern';
import { nextFrame } from '../board/frame';
import { GameCommandEnum } from '../types';
const checkCanCommit = (state) => {
if (state === undefined)
return state;
if (state.frame.currentPlayerIndex !== state.frame.activePlayerIndex)
return undefined;
if (state.frame.neutralBuildingPhase) {
if (state.buildings.length !== 0)
return undefined;
return state;
}
if (state.frame.mainActionUsed)
return state;
return undefined;
};
export const commit = pipe(
//
checkCanCommit, nextFrame);
export const complete = (state) => (partial) => {
return match(partial)
.with([], () => {
if (checkCanCommit(state) === undefined)
return [];
return [GameCommandEnum.COMMIT];
})
.with([GameCommandEnum.COMMIT], () => [''])
.otherwise(always([]));
};
//# sourceMappingURL=commit.js.map