summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--play.js165
-rw-r--r--rules.js184
2 files changed, 247 insertions, 102 deletions
diff --git a/play.js b/play.js
index d35e3d3..fbc92d4 100644
--- a/play.js
+++ b/play.js
@@ -4,6 +4,77 @@
global view, data, player, send_action, action_button, scroll_with_middle_mouse
*/
+const first_piece = data.first_piece
+const last_piece = data.last_piece
+
+// :r !python3 tools/genlayout.py
+const LAYOUT = {
+ "Andhra DS": [785, 1014],
+ "Andhra BK": [678, 1060],
+ "Andhra VE": [653, 1165],
+ "Andhra mongols": [748, 1215],
+ "Bengal DS": [1148, 455],
+ "Bengal BK": [1079, 536],
+ "Bengal VE": [1122, 626],
+ "Bengal mongols": [1209, 663],
+ "Gondwana DS": [992, 685],
+ "Gondwana BK": [848, 695],
+ "Gondwana VE": [864, 842],
+ "Gondwana mongols": [990, 743],
+ "Gujarat DS": [362, 611],
+ "Gujarat BK": [250, 601],
+ "Gujarat VE": [386, 723],
+ "Gujarat mongols": [134, 611],
+ "Jaunpur DS": [979, 422],
+ "Jaunpur BK": [788, 526],
+ "Jaunpur VE": [915, 586],
+ "Jaunpur mongols": [867, 385],
+ "Karnataka DS": [551, 1213],
+ "Karnataka BK": [651, 1298],
+ "Karnataka VE": [572, 1390],
+ "Karnataka mongols": [483, 1254],
+ "Madhyadesh DS": [724, 746],
+ "Madhyadesh BK": [571, 868],
+ "Madhyadesh VE": [653, 941],
+ "Madhyadesh mongols": [613, 770],
+ "Maharashtra DS": [465, 907],
+ "Maharashtra BK": [531, 997],
+ "Maharashtra VE": [525, 1084],
+ "Maharashtra mongols": [387, 900],
+ "Malwa DS": [682, 574],
+ "Malwa BK": [515, 623],
+ "Malwa VE": [511, 735],
+ "Malwa mongols": [537, 557],
+ "Orissa DS": [1168, 798],
+ "Orissa BK": [1082, 800],
+ "Orissa VE": [955, 929],
+ "Orissa mongols": [935, 991],
+ "Rajput Kingdoms DS": [427, 367],
+ "Rajput Kingdoms BK": [205, 483],
+ "Rajput Kingdoms VE": [433, 502],
+ "Rajput Kingdoms mongols": [229, 383],
+ "Sindh DS": [110, 327],
+ "Sindh BK": [40, 492],
+ "Sindh VE": [42, 544],
+ "Sindh mongols": [36, 344],
+ "Tamilakam DS": [756, 1338],
+ "Tamilakam BK": [648, 1478],
+ "Tamilakam VE": [657, 1543],
+ "Tamilakam mongols": [752, 1394],
+ "Delhi DS": [718, 316],
+ "Delhi BK": [571, 422],
+ "Delhi VE": [724, 414],
+ "Delhi mongols": [573, 324],
+ "Mountain Passes DS": [404, 106],
+ "Mountain Passes BK": [236, 110],
+ "Mountain Passes VE": [318, 105],
+ "Mountain Passes mongols": [263, 183],
+ "Punjab DS": [504, 170],
+ "Punjab BK": [279, 262],
+ "Punjab VE": [477, 266],
+ "Punjab mongols": [370, 233],
+}
+
/* COMMON */
function set_has(set, item) {
@@ -40,23 +111,6 @@ function map_get(map, key, missing) {
/* DATA */
-// Factions
-const DS = 0
-const BK = 1
-const VE = 2
-
-const NAME_DS = "DS"
-const NAME_BK = "BK"
-const NAME_VE = "VE"
-
-// 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
-
// Spaces
const S_ANDHRA = 0
const S_BENGAL = 1
@@ -528,6 +582,18 @@ function init_ui() {
ui.pieces = []
+ create_piece_list(DS, DISC, "piece ds disc", -4, 10)
+ create_piece_list(DS, ELITE, "piece ds governor", 100, 100)
+ create_piece_list(DS, TROOPS, "piece ds cube", 0, 4)
+
+ create_piece_list(BK, DISC, "piece bk disc", -4, 10)
+ create_piece_list(BK, ELITE, "piece bk amir", 2, 0)
+
+ create_piece_list(VE, DISC, "piece ve disc", -4, 10)
+ create_piece_list(VE, ELITE, "piece ve raja", 2, 0)
+
+ create_piece_list(MI, TROOPS, "piece mongol cube", 2, 0)
+
return
/*
@@ -542,9 +608,7 @@ return
*/
- create_piece_list(DS, DISK, "piece ds disk", -4, 10)
- create_piece_list(DS, GOVERNOR, "piece ds governor", 0, 4)
- create_piece_list(DS, CUBE, "piece ds cube", 0, 4)
+
create_piece_list(BK, DISK, "piece ve disk", -4, 10)
create_piece_list(BK, AMIR, "piece ve amir", 2, 0)
@@ -552,7 +616,7 @@ return
create_piece_list(VE, DISK, "piece ve disk", -4, 10)
create_piece_list(VE, RAJA, "piece ve raja", 2, 0)
- create_piece_list(MONGOLS, CUBE, "piece mongol cube", 2, 0)
+ create_piece_list(MI, CUBE, "piece mongol cube", 2, 0)
}
/* UPDATE */
@@ -578,12 +642,10 @@ function action_menu(menu, action_list) {
const LAYOUT_CACHE = {
Center: [],
- Govt: [],
- FARC: [],
- AUC: [],
- Cartels: [],
- COIN: [],
- INSURGENTS: [],
+ DS: [],
+ BK: [],
+ VE: [],
+ mongols: [],
}
function get_layout_xy(s, f = "Center") {
@@ -606,7 +668,7 @@ function layout_available(faction, type, xorig, yorig) {
layout_pieces(list, xorig, yorig + 35, null, AVAILABLE)
}
-function layout_pieces(list, xorig, yorig, bases, shipments, s, faction) {
+function layout_pieces(list, xorig, yorig, discs, s) {
const dx = 17
const dy = 11
let off_x = 0
@@ -635,18 +697,18 @@ function layout_pieces(list, xorig, yorig, bases, shipments, s, faction) {
let ncol = Math.ceil(list.length / nrow)
let z = 50
let i = 0
- if ((s >= 0 && s <= last_city) || s >= first_loc) {
- off_x = (nrow - ncol) * 6
- off_y = (nrow - 1) * 8
- }
+ // if ((s >= 0 && s <= last_city) || s >= first_loc) {
+ // off_x = (nrow - ncol) * 6
+ // off_y = (nrow - 1) * 8
+ // }
for (let row = 0; row < nrow; ++row)
for (let col = 0; col < ncol; ++col)
if (i < list.length)
layout_piece_rowcol(nrow, ncol, row, col, list[list.length-(++i)], z--)
}
- if (bases)
- layout_dept_bases(bases, xorig + off_x, yorig + 12 + off_y, s)
+ // if (discs)
+ // layout_discs(discs, xorig + off_x, yorig + 12 + off_y, s)
}
function place_piece(p, x, y, z) {
@@ -659,7 +721,7 @@ function place_piece(p, x, y, z) {
p.my_z = z
}
-function layout_dept_bases(list, xc, yc, s) {
+function layout_discs(list, xc, yc, s) {
if (list.length === 1) {
place_piece(list[0], xc - 20 + 32, yc - 10, 52)
}
@@ -855,6 +917,39 @@ function on_update() {
layout_score()
+ let items = [ ]
+ let discs = [ ]
+ for (let s = 0; s < data.spaces.length; ++s) {
+ let xy
+
+ items.length = discs.length = 0
+ filter_piece_list(discs, s, DS, DISC)
+ filter_piece_list(items, s, DS, ELITE)
+ filter_piece_list(items, s, DS, TROOPS)
+ xy = get_layout_xy(s, "DS")
+ console.log(xy)
+ console.log(items)
+ layout_pieces(items, xy[0], xy[1], discs, DS)
+
+ items.length = discs.length = 0
+ filter_piece_list(discs, s, BK, DISC)
+ filter_piece_list(items, s, BK, ELITE)
+ xy = get_layout_xy(s, "BK")
+ layout_pieces(items, xy[0], xy[1], discs, BK)
+
+ items.length = discs.length = 0
+ filter_piece_list(discs, s, VE, DISC)
+ filter_piece_list(items, s, VE, ELITE)
+ xy = get_layout_xy(s, "VE")
+ layout_pieces(items, xy[0], xy[1], discs, VE)
+
+ items.length = discs.length = 0
+ filter_piece_list(items, s, MI, TROOPS)
+ xy = get_layout_xy(s, "mongols")
+ layout_pieces(items, xy[0], xy[1], discs, MI)
+
+ }
+
return
layout_sop()
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