summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
authorJoël Simoneau <simoneaujoel@gmail.com>2024-10-21 16:14:29 -0400
committerJoël Simoneau <simoneaujoel@gmail.com>2024-10-21 16:14:29 -0400
commitb7c2cba89e8d5c25f6dcf1898a506652bec94b84 (patch)
treed98062de983374339ebc4ba78b31a42f27009aa7 /rules.js
parent2213dd764d468147a175baac6c7c4c92c783777b (diff)
downloadvijayanagara-b7c2cba89e8d5c25f6dcf1898a506652bec94b84.tar.gz
feat: setup
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js184
1 files changed, 117 insertions, 67 deletions
diff --git a/rules.js b/rules.js
index 4cb186c..61733f4 100644
--- a/rules.js
+++ b/rules.js
@@ -5,48 +5,29 @@ let game = null
let view = null
/* DATA */
-
-// const data = require("./data.js")
-
-const space_name = [
- "Andhra",
- "Bengal",
- "Gondwana",
- "Gujarat",
- "Jaunpur",
- "Karnataka",
- "Madhyadesh",
- "Maharashtra",
- "Malwa",
- "Orissa",
- "Rajput Kingdoms",
- "Sindh",
- "Tamilakam",
- "Delhi",
- "Mountain Passes",
- "Punjab",
- "Mongol Invaders",
- "DS Available",
- "BK Available",
- "VE Available",
-]
-
-const S_ANDHRA = 0
-const S_BENGAL = 1
-const S_GONDWANA = 2
-const S_GUJARAT = 3
-const S_JAUNPUR = 4
-const S_KARNATAKA = 5
-const S_MADHYADESH = 6
-const S_MAHARASHTRA = 7
-const S_MALWA = 8
-const S_ORISSA = 9
-const S_RAJPUT_KINGDOMS = 10
-const S_SINDH = 11
-const S_TAMILAKAM = 12
-const S_DELHI = 13
-const S_MOUNTAIN_PASSES = 14
-const S_PUNJAB = 15
+const data = require("./data.js")
+const space_name = data.space_name
+
+function get_space_id(name) {
+ return space_name.indexOf(name);
+}
+
+const S_ANDHRA = get_space_id("Andhra")
+const S_BENGAL = get_space_id("Bengal")
+const S_GONDWANA = get_space_id("Gondwana")
+const S_GUJARAT = get_space_id("Gujarat")
+const S_JAUNPUR = get_space_id("Jaunpur")
+const S_KARNATAKA = get_space_id("Karnataka")
+const S_MADHYADESH = get_space_id("Madhyadesh")
+const S_MAHARASHTRA = get_space_id("Maharashtra")
+const S_MALWA = get_space_id("Malwa")
+const S_ORISSA = get_space_id("Orissa")
+const S_RAJPUT_KINGDOMS = get_space_id("Rajput Kingdoms")
+const S_SINDH = get_space_id("Sindh")
+const S_TAMILAKAM = get_space_id("Tamilakam")
+const S_DELHI = get_space_id("Delhi")
+const S_MOUNTAIN_PASSES = get_space_id("Mountain Passes")
+const S_PUNJAB = get_space_id("Punjab")
const S_MONGOL_INVADERS = 16
const S_DS_AVAILABLE = 17
const S_BK_AVAILABLE = 18
@@ -58,26 +39,7 @@ const S_VE_INF_2 = 23
const S_VE_INF_3 = 24
const S_VE_INF_4 = 25
-// Factions
-const DS = 0
-const BK = 1
-const VE = 2
-
-// Sequence of Play options
-const ELIGIBLE = 0
-const SOP_LIMITED_COMMAND = 1
-const SOP_COMMAND_DECREE = 2
-const SOP_EVENT_OR_COMMAND = 3
-const SOP_PASS = 4
-const INELIGIBLE = 5
-
-const faction_name = [ "Delhi Sultanate", "Bahmani Kingdom", "Vijayanagara Empire" ]
-
-// Role names
-const NAME_DS = "DS"
-const NAME_BK = "BK"
-const NAME_VE = "VE"
-const NAME_SOLO = "Solo"
+const faction_name = [ "Delhi Sultanate", "Bahmani Kingdom", "Vijayanagara Empire", "Mongol Invaders" ]
exports.scenarios = [ "Standard", "Solo" ]
@@ -124,11 +86,12 @@ exports.view = function (state, role) {
actions: null,
log: game.log,
current: game.current,
- vp: [ 18, 0, 0 ],
- resources: [ 12, 6, 7 ],
+ vp: game.vp,
+ resources: game.resources,
bk_inf: 0,
ve_inf: 0,
deck: [ this_card, deck_size, game.of_gods_and_kings ],
+ pieces: game.pieces,
}
if (game.result) {
@@ -210,15 +173,14 @@ exports.setup = function (seed, scenario, _options) {
active: null,
current: 0,
state: null,
-
cylinder: [ ELIGIBLE, ELIGIBLE, ELIGIBLE ],
resources: [ 12, 6, 7 ],
+ vp: [ 18, 0, 0 ],
bk_inf: 0,
ve_inf: 0,
tributary: 8191, // all 13 provinces
rebel: 0, // amir/raja rebel status
- pieces: [], // piece locations
-
+ pieces: Array(103).fill(AVAILABLE), // piece locations
deck: [],
}
@@ -232,9 +194,46 @@ exports.setup = function (seed, scenario, _options) {
game.current = DS
game.state = "todo"
+ // Setup
+ setup_standard()
+
return save_game()
}
+function setup_standard() {
+ setup_piece(DS, DISC, 1, "S_ANDHRA")
+ setup_piece(DS, ELITE, 1, S_MALWA)
+ setup_piece(DS, TROOPS, 4, S_DELHI)
+ setup_piece(DS, TROOPS, 4, S_PUNJAB)
+ setup_piece(DS, TROOPS, 3, S_MALWA)
+ setup_piece(DS, TROOPS, 2, S_JAUNPUR)
+ setup_piece(DS, TROOPS, 2, S_MADHYADESH)
+ setup_piece(DS, TROOPS, 2, S_MOUNTAIN_PASSES)
+ setup_piece(DS, TROOPS, 1, S_ANDHRA)
+ setup_piece(DS, TROOPS, 1, S_GUJARAT)
+ setup_piece(DS, TROOPS, 1, S_RAJPUT_KINGDOMS)
+ setup_piece(DS, TROOPS, 1, S_SINDH)
+ setup_piece(DS, TROOPS, 1, S_TAMILAKAM)
+
+ setup_piece(BK, ELITE, 1, S_GONDWANA)
+ setup_piece(BK, ELITE, 1, S_GUJARAT)
+ setup_piece(BK, ELITE, 2, S_MADHYADESH)
+ setup_piece(BK, ELITE, 4, S_MAHARASHTRA)
+
+ setup_piece(VE, ELITE, 1, S_TAMILAKAM)
+ setup_piece(VE, ELITE, 2, S_ANDHRA)
+ setup_piece(VE, ELITE, 3, S_KARNATAKA)
+}
+
+function setup_piece(faction, type, count, where) {
+ for (let p = data.first_piece[faction][type]; count > 0; ++p) {
+ if (piece_space(p) < 0) {
+ set_piece_space(p, where)
+ --count
+ }
+ }
+}
+
/* LOGGING */
function log(msg) {
@@ -328,6 +327,17 @@ function log_summary_remove(p) {
}
+// === MISC PIECE QUERIES ===
+
+function piece_space(p) {
+ return game.pieces[p]
+}
+
+function set_piece_space(p, s) {
+ game.pieces[p] = s
+}
+
+
/* COMMON LIBRARY */
function clear_undo() {
@@ -657,3 +667,43 @@ function object_group_by(items, callback) {
}
return groups
}
+
+
+// === CONST ===
+
+// Factions
+const DS = 0
+const BK = 1
+const VE = 2
+const MI = 3
+
+// Role names
+const NAME_DS = "DS"
+const NAME_BK = "BK"
+const NAME_VE = "VE"
+const NAME_SOLO = "Solo"
+
+// Player pieces types
+const DISC = 0
+const ELITE = 1
+const TROOPS = 2
+
+// Pieces status
+const AVAILABLE = -1
+const OUT_OF_PLAY = -2
+const ANY_PIECES = [ DISC, ELITE, TROOPS ]
+const PIECE_FACTION_TYPE_NAME = [
+ [ "Qasbah", "Governors", "Troops" ],
+ [ "Fort", "Amirs", null ],
+ [ "Temple", "Rajas", null ],
+ [ null, null, "Invaders"]
+]
+
+// Sequence of Play options
+const ELIGIBLE = 0
+const SOP_LIMITED_COMMAND = 1
+const SOP_COMMAND_DECREE = 2
+const SOP_EVENT_OR_COMMAND = 3
+const SOP_PASS = 4
+const INELIGIBLE = 5
+// === CONST === \ No newline at end of file