summaryrefslogtreecommitdiff
path: root/rules.js
blob: 34866991001f539611d6bdab386039d52eb89a3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
}