From e813dffc26d4ccd5d33a03e7f109e7348c9c03a6 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 25 Oct 2023 01:51:24 +0200 Subject: Add skeleton. --- rules.js | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 rules.js (limited to 'rules.js') diff --git a/rules.js b/rules.js new file mode 100644 index 0000000..3486699 --- /dev/null +++ b/rules.js @@ -0,0 +1,55 @@ +"use strict" + +var game +var view +var states + +const SUF = "Suffragist" +const OPP = "Opposition" + +exports.scenarios = [ "Standard" ] +exports.roles = [ SUF, OPP ] + +exports.setup = function (seed, scenario, options) { + game = { + seed: seed, + log: [], + undo: [], + active: null, + state: null, + } + return game +} + +exports.action = function (state, current, action, arg) { + game = state + let S = states[game.state] + if (action in S) + S[action](arg, current) + else + throw new Error("Invalid action: " + action) + return game +} + +exports.resign = function (state, current) { + game = state + if (game.state !== "game_over") { + if (current === SUF) + goto_game_over(OPP, "Suffragist resigned.") + if (current === OPP) + goto_game_over(SUF, "Opposition resigned.") + } + return game +} + +exports.view = function(state, current) { + game = state + + let view = { + log: game.log, + prompt: null, + actions: null, + } + + return view +} -- cgit v1.2.3