//"use strict" const { finished } = require("nodemailer/lib/xoauth2/index.js") const data = require("./data.js") console.log('hello') var game, view, states = {} const DEM = "Democrat" const COM = "Communist" const first_strategy_card = 1 const last_strategy_card = 110 /* to check! */ const hand_limit = 8 const spaces = [ {name: 'Schwerin', name_unique: 'Schwerin', space_id: 1, socio: 4, stability: 3, battleground: 0, country: 1, box: {x: 111, y: 61, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [2, 3, , , ]}, {name: 'Rostock', name_unique: 'Rostock', space_id: 2, socio: 4, stability: 3, battleground: 0, country: 1, box: {x: 228, y: 41, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [1, 3, , , ]}, {name: 'Berlin', name_unique: 'Berlin', space_id: 3, socio: 2, stability: 3, battleground: 1, country: 1, box: {x: 251, y: 113, h: 65, w: 105}, demInfl: 0, comInfl: 2, demCtrl: 0, comCtrl: 0, adjacent: [1, 2, 5, 9, ]}, {name: 'German Writers', name_unique: 'German Writers', space_id: 4, socio: 5, stability: 2, battleground: 0, country: 1, box: {x: 58, y: 185, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [5, , , , ]}, {name: 'Walter Ulbricht Academy', name_unique: 'Walter Ulbricht Academy', space_id: 5, socio: 6, stability: 1, battleground: 0, country: 1, box: {x: 175, y: 187, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [3, 4, , , ]}, {name: 'Lutherian Church', name_unique: 'Lutherian Church', space_id: 6, socio: 7, stability: 5, battleground: 1, country: 1, box: {x: 300, y: 212, h: 65, w: 105}, demInfl: 1, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [9, , , , ]}, {name: 'Magdeburg', name_unique: 'Magdeburg', space_id: 7, socio: 4, stability: 3, battleground: 1, country: 1, box: {x: 58, y: 275, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [8, 10, 11, , ]}, {name: 'Halle', name_unique: 'Halle', space_id: 8, socio: 4, stability: 3, battleground: 0, country: 1, box: {x: 175, y: 278, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [7, 10, 11, , ]}, {name: 'Leipzig', name_unique: 'Leipzig', space_id: 9, socio: 4, stability: 3, battleground: 1, country: 1, box: {x: 297, y: 297, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [3, 6, 8, 11, 12]}, {name: 'Erfurt', name_unique: 'Erfurt', space_id: 10, socio: 3, stability: 4, battleground: 0, country: 1, box: {x: 23, y: 356, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [7, , , , ]}, {name: 'Karl-Marx-Stadt', name_unique: 'Karl-Marx-Stadt', space_id: 11, socio: 4, stability: 3, battleground: 1, country: 1, box: {x: 138, y: 385, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [7, 8, 9, 12, ]}, {name: 'Dresden', name_unique: 'Dresden', space_id: 12, socio: 1, stability: 4, battleground: 1, country: 1, box: {x: 262, y: 375, h: 65, w: 105}, demInfl: 0, comInfl: 2, demCtrl: 0, comCtrl: 0, adjacent: [9, 11, 19, 27, ]}, {name: 'Szczecin', name_unique: 'Szczecin', space_id: 13, socio: 4, stability: 3, battleground: 0, country: 2, box: {x: 434, y: 204, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [14, 16, , , ]}, {name: 'Gdansk', name_unique: 'Gdansk', space_id: 14, socio: 4, stability: 3, battleground: 1, country: 2, box: {x: 699, y: 215, h: 65, w: 105}, demInfl: 1, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [13, 15, 16, 17, 18]}, {name: 'Bydgoszcz', name_unique: 'Bydgoszcz', space_id: 15, socio: 1, stability: 4, battleground: 0, country: 2, box: {x: 679, y: 304, h: 65, w: 105}, demInfl: 0, comInfl: 1, demCtrl: 0, comCtrl: 0, adjacent: [15, 17, , , ]}, {name: 'Poznan', name_unique: 'Poznan', space_id: 16, socio: 4, stability: 3, battleground: 1, country: 2, box: {x: 521, y: 355, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [13, 14, 19, 20, ]}, {name: 'Warszawa', name_unique: 'Warszawa', space_id: 17, socio: 2, stability: 3, battleground: 1, country: 2, box: {x: 806, y: 383, h: 65, w: 105}, demInfl: 0, comInfl: 1, demCtrl: 0, comCtrl: 0, adjacent: [14, 15, 18, 21, 24]}, {name: 'Bialystok', name_unique: 'Bialystok', space_id: 18, socio: 3, stability: 4, battleground: 0, country: 2, box: {x: 940, y: 342, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [14, 17, 24, , ]}, {name: 'Wroclaw', name_unique: 'Wroclaw', space_id: 19, socio: 4, stability: 3, battleground: 1, country: 2, box: {x: 462, y: 443, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [12, 16, 20, 22, ]}, {name: 'Catholic Church', name_unique: 'Catholic Church Poland', space_id: 20, socio: 7, stability: 5, battleground: 0, country: 2, box: {x: 625, y: 437, h: 65, w: 105}, demInfl: 5, comInfl: 0, demCtrl: 1, comCtrl: 0, adjacent: [16, 19, 21, 22, 23]}, {name: 'Lodz', name_unique: 'Lodz', space_id: 21, socio: 4, stability: 3, battleground: 1, country: 2, box: {x: 749, y: 486, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [17, 20, 23, 24, ]}, {name: 'Katowice', name_unique: 'Katowice', space_id: 22, socio: 4, stability: 3, battleground: 0, country: 2, box: {x: 570, y: 569, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [19, 20, 21, 33, ]}, {name: 'Krakow', name_unique: 'Krakow', space_id: 23, socio: 4, stability: 3, battleground: 1, country: 2, box: {x: 711, y: 598, h: 65, w: 105}, demInfl: 1, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [20, 21, 23, 25, ]}, {name: 'Lublin', name_unique: 'Lublin', space_id: 24, socio: 3, stability: 4, battleground: 0, country: 2, box: {x: 879, y: 603, h: 65, w: 105}, demInfl: 0, comInfl: 1, demCtrl: 0, comCtrl: 0, adjacent: [17, 18, 21, , ]}, {name: 'Jagiellian University', name_unique: 'Jagiellian University', space_id: 25, socio: 6, stability: 1, battleground: 0, country: 2, box: {x: 679, y: 681, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [23, 26, , , ]}, {name: 'Polish Writers', name_unique: 'Polish Writers', space_id: 26, socio: 5, stability: 2, battleground: 0, country: 2, box: {x: 832, y: 694, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [25, , , , ]}, {name: 'Plzen', name_unique: 'Plzen', space_id: 27, socio: 1, stability: 4, battleground: 0, country: 3, box: {x: 159, y: 483, h: 65, w: 105}, demInfl: 0, comInfl: 2, demCtrl: 0, comCtrl: 0, adjacent: [12, 29, , , ]}, {name: 'Ceske Budejovice', name_unique: 'Ceske Budejovice', space_id: 28, socio: 3, stability: 3, battleground: 0, country: 3, box: {x: 196, y: 601, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [28, 29, , , ]}, {name: 'Praha', name_unique: 'Praha', space_id: 29, socio: 2, stability: 3, battleground: 1, country: 3, box: {x: 317, y: 614, h: 65, w: 105}, demInfl: 0, comInfl: 2, demCtrl: 0, comCtrl: 0, adjacent: [27, 28, 30, 32, ]}, {name: 'Charles University', name_unique: 'Charles University', space_id: 30, socio: 6, stability: 1, battleground: 1, country: 3, box: {x: 380, y: 532, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [29, 31, , , ]}, {name: 'Czech Writers', name_unique: 'Czech Writers', space_id: 31, socio: 5, stability: 2, battleground: 1, country: 3, box: {x: 444, y: 607, h: 65, w: 105}, demInfl: 2, comInfl: 0, demCtrl: 1, comCtrl: 0, adjacent: [30, , , , ]}, {name: 'Brno', name_unique: 'Brno', space_id: 32, socio: 4, stability: 3, battleground: 1, country: 3, box: {x: 403, y: 711, h: 65, w: 105}, demInfl: 0, comInfl: 1, demCtrl: 0, comCtrl: 0, adjacent: [29, 33, 34, , ]}, {name: 'Ostrava', name_unique: 'Ostrava', space_id: 33, socio: 4, stability: 3, battleground: 1, country: 3, box: {x: 523, y: 681, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [22, 32, 34, 35, ]}, {name: 'Bratislava', name_unique: 'Bratislava', space_id: 34, socio: 4, stability: 3, battleground: 1, country: 3, box: {x: 417, y: 797, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [32, 33, 35, , ]}, {name: 'Catholic Church', name_unique: 'Catholic Church Czech', space_id: 35, socio: 7, stability: 5, battleground: 0, country: 3, box: {x: 538, y: 794, h: 65, w: 105}, demInfl: 1, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [33, 34, 36, , ]}, {name: 'Presov', name_unique: 'Presov', space_id: 36, socio: 3, stability: 4, battleground: 0, country: 3, box: {x: 658, y: 794, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [35, 37, , , ]}, {name: 'Kosice', name_unique: 'Kosice', space_id: 37, socio: 3, stability: 4, battleground: 0, country: 3, box: {x: 777, y: 815, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [36, 42, , , ]}, {name: 'Catholic Church', name_unique: 'Catholic Church Hungary', space_id: 38, socio: 7, stability: 5, battleground: 0, country: 4, box: {x: 314, y: 886, h: 65, w: 105}, demInfl: 1, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [39, 43, , , ]}, {name: 'Gyor', name_unique: 'Gyor', space_id: 39, socio: 4, stability: 3, battleground: 0, country: 4, box: {x: 434, y: 887, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [38, 40, 43, 44, ]}, {name: 'Tatabanya', name_unique: 'Tatabanya', space_id: 40, socio: 4, stability: 3, battleground: 0, country: 4, box: {x: 549, y: 886, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [39, 41, 45, , ]}, {name: 'Miskolc', name_unique: 'Miskolc', space_id: 41, socio: 4, stability: 3, battleground: 1, country: 4, box: {x: 664, y: 901, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [40, 42, 45, , ]}, {name: 'Debrecen', name_unique: 'Debrecen', space_id: 42, socio: 4, stability: 3, battleground: 1, country: 4, box: {x: 781, y: 938, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [37, 41, , , ]}, {name: 'Szombathely', name_unique: 'Szombathely', space_id: 43, socio: 1, stability: 4, battleground: 0, country: 4, box: {x: 316, y: 963, h: 65, w: 105}, demInfl: 0, comInfl: 1, demCtrl: 0, comCtrl: 0, adjacent: [38, 39, 44, , ]}, {name: 'Szekesfehervar', name_unique: 'Szekesfehervar', space_id: 44, socio: 4, stability: 3, battleground: 0, country: 4, box: {x: 442, y: 962, h: 65, w: 105}, demInfl: 1, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [39, 43, 45, , ]}, {name: 'Budapest', name_unique: 'Budapest', space_id: 45, socio: 2, stability: 3, battleground: 1, country: 4, box: {x: 630, y: 983, h: 65, w: 105}, demInfl: 1, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [4, 41, 44, 47, 48]}, {name: 'Hungarian Writers', name_unique: 'Hungarian Writers', space_id: 46, socio: 5, stability: 2, battleground: 0, country: 4, box: {x: 348, y: 1040, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [47, , , , ]}, {name: 'Eotvos Lorand University', name_unique: 'Eotvos Lorand University', space_id: 47, socio: 6, stability: 1, battleground: 0, country: 4, box: {x: 512, y: 1034, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [46, 45, , , ]}, {name: 'Szeged', name_unique: 'Szeged', space_id: 48, socio: 3, stability: 4, battleground: 1, country: 4, box: {x: 632, y: 1073, h: 65, w: 105}, demInfl: 1, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [45, 49, 50, , ]}, {name: 'Pecs', name_unique: 'Pecs', space_id: 49, socio: 3, stability: 4, battleground: 1, country: 4, box: {x: 486, y: 1105, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [48, , , , ]}, {name: 'Timisoara', name_unique: 'Timisoara', space_id: 50, socio: 4, stability: 3, battleground: 1, country: 5, box: {x: 597, y: 1204, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [48, 51, 60, , ]}, {name: 'Cluj-Napoca', name_unique: 'Cluj-Napoca', space_id: 51, socio: 1, stability: 4, battleground: 1, country: 5, box: {x: 756, y: 1125, h: 65, w: 105}, demInfl: 0, comInfl: 2, demCtrl: 0, comCtrl: 0, adjacent: [50, 54, 58, , ]}, {name: 'Targu Mures', name_unique: 'Targu Mures', space_id: 52, socio: 3, stability: 4, battleground: 0, country: 5, box: {x: 915, y: 1136, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [53, 56, , , ]}, {name: 'Iasi', name_unique: 'Iasi', space_id: 53, socio: 4, stability: 3, battleground: 1, country: 5, box: {x: 1072, y: 1097, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [52, 57, 62, , ]}, {name: 'Babes-Bolyai University', name_unique: 'Babes-Bolyai University', space_id: 54, socio: 6, stability: 1, battleground: 0, country: 5, box: {x: 746, y: 1203, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [51, 55, , , ]}, {name: 'Romanian Writers', name_unique: 'Romanian Writers', space_id: 55, socio: 5, stability: 2, battleground: 0, country: 5, box: {x: 739, y: 1278, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [54, , , , ]}, {name: 'Hargita/Covasna', name_unique: 'Hargita/Covasna', space_id: 56, socio: 8, stability: 4, battleground: 0, country: 5, box: {x: 928, y: 1227, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [52, , , , ]}, {name: 'Brasov', name_unique: 'Brasov', space_id: 57, socio: 4, stability: 3, battleground: 1, country: 5, box: {x: 1049, y: 1225, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [53, 59, 61, , ]}, {name: 'Orthodox Church', name_unique: 'Orthodox Church Romania', space_id: 58, socio: 7, stability: 3, battleground: 0, country: 5, box: {x: 855, y: 1338, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [51, 60, , , ]}, {name: 'Ploiesti', name_unique: 'Ploiesti', space_id: 59, socio: 4, stability: 3, battleground: 0, country: 5, box: {x: 1061, y: 1316, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [57, 61, 62, , ]}, {name: 'Craiova', name_unique: 'Craiova', space_id: 60, socio: 3, stability: 4, battleground: 0, country: 5, box: {x: 763, y: 1411, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [50, 58, 61, , ]}, {name: 'Bucuresti', name_unique: 'Bucuresti', space_id: 61, socio: 2, stability: 3, battleground: 1, country: 5, box: {x: 929, y: 1445, h: 65, w: 105}, demInfl: 0, comInfl: 2, demCtrl: 0, comCtrl: 0, adjacent: [51, 57, 59, 60, 63]}, {name: 'Galatii', name_unique: 'Galatii', space_id: 62, socio: 4, stability: 3, battleground: 1, country: 5, box: {x: 1104, y: 1399, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [53, 59, 63, , ]}, {name: 'Constanta', name_unique: 'Constanta', space_id: 63, socio: 4, stability: 3, battleground: 0, country: 5, box: {x: 1130, y: 1517, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [61, 62, 72, , ]}, {name: 'Pleven', name_unique: 'Pleven', space_id: 64, socio: 3, stability: 4, battleground: 0, country: 6, box: {x: 764, y: 1534, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [67, , , , ]}, {name: 'Orthodox Church', name_unique: 'Orthodox Church Bulgaria', space_id: 65, socio: 7, stability: 3, battleground: 0, country: 6, box: {x: 882, y: 1540, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [66, 68, , , ]}, {name: 'Ruse', name_unique: 'Ruse', space_id: 66, socio: 4, stability: 3, battleground: 1, country: 6, box: {x: 998, y: 1540, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [65, 69, 70, 71, 72]}, {name: 'Sofia University', name_unique: 'Sofia University', space_id: 67, socio: 6, stability: 1, battleground: 0, country: 6, box: {x: 645, y: 1650, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [68, 73, , , ]}, {name: 'Sofia', name_unique: 'Sofia', space_id: 68, socio: 2, stability: 3, battleground: 1, country: 6, box: {x: 768, y: 1653, h: 65, w: 105}, demInfl: 0, comInfl: 2, demCtrl: 0, comCtrl: 0, adjacent: [64, 65, 67, 69, 74]}, {name: 'Stara Zagora', name_unique: 'Stara Zagora', space_id: 69, socio: 1, stability: 4, battleground: 0, country: 6, box: {x: 886, y: 1694, h: 65, w: 105}, demInfl: 0, comInfl: 1, demCtrl: 0, comCtrl: 0, adjacent: [66, 68, 71, , ]}, {name: 'Razgrad', name_unique: 'Razgrad', space_id: 70, socio: 8, stability: 4, battleground: 0, country: 6, box: {x: 954, y: 1620, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [66, , , , ]}, {name: 'Burgas', name_unique: 'Burgas', space_id: 71, socio: 4, stability: 3, battleground: 1, country: 6, box: {x: 1004, y: 1695, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [66, 69, 72, , ]}, {name: 'Varna', name_unique: 'Varna', space_id: 72, socio: 4, stability: 3, battleground: 1, country: 6, box: {x: 1086, y: 1613, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [63, 66, 71, , ]}, {name: 'Bulgarian Writers', name_unique: 'Bulgarian Writers', space_id: 73, socio: 5, stability: 2, battleground: 0, country: 6, box: {x: 652, y: 1726, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [67, , , , ]}, {name: 'Plovdiv', name_unique: 'Plovdiv', space_id: 74, socio: 4, stability: 3, battleground: 1, country: 6, box: {x: 771, y: 1739, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [68, 75, , , ]}, {name: 'Sliven', name_unique: 'Sliven', space_id: 75, socio: 3, stability: 4, battleground: 0, country: 6, box: {x: 894, y: 1768, h: 65, w: 105}, demInfl: 0, comInfl: 0, demCtrl: 0, comCtrl: 0, adjacent: [75, , , , ]}, ] const cards = [ null, {number: 1, period: 1, side: 'C', name: 'Legacy of Martial Law*', ops: 2, remove: 1}, {number: 2, period: 1, side: 'D', name: 'Solidarity Legalized*', ops: 4, remove: 1}, {number: 3, period: 1, side: 'D', name: 'Walesa*', ops: 3, remove: 1}, {number: 4, period: 1, side: 'D', name: 'Michnik*', ops: 1, remove: 1}, {number: 5, period: 1, side: 'D', name: 'General Strike', ops: 3, remove: 0}, {number: 6, period: 1, side: 'C', name: 'Brought in for Questioning', ops: 3, remove: 0}, {number: 7, period: 1, side: 'C', name: 'State Run Media*', ops: 2, remove: 1}, {number: 8, period: 1, side: 'N', name: 'Prudence', ops: 4, remove: 0}, {number: 9, period: 1, side: 'C', name: 'The Wall*', ops: 1, remove: 1}, {number: 10, period: 1, side: 'C', name: 'Cult of Personality*', ops: 3, remove: 1}, {number: 11, period: 1, side: 'C', name: 'Dissident Arrested', ops: 2, remove: 0}, {number: 12, period: 1, side: 'C', name: 'Apparatchiks*', ops: 2, remove: 1}, {number: 13, period: 1, side: 'C', name: 'Stasi*', ops: 1, remove: 1}, {number: 14, period: 1, side: 'N', name: 'Gorbachev Charms the West', ops: 4, remove: 0}, {number: 15, period: 1, side: 'C', name: 'Honecker*', ops: 3, remove: 1}, {number: 16, period: 1, side: 'C', name: 'Nomenklatura*', ops: 2, remove: 1}, {number: 17, period: 1, side: 'D', name: 'Roundtable Talks', ops: 3, remove: 0}, {number: 18, period: 1, side: 'C', name: 'Poszgay Defends the Revolution*', ops: 2, remove: 1}, {number: 19, period: 1, side: 'D', name: 'Papal Visit*', ops: 2, remove: 1}, {number: 20, period: 1, side: 'C', name: 'Deutsche Marks*', ops: 4, remove: 1}, {number: 21, period: 1, side: 'N', name: 'Common European Home', ops: 2, remove: 0}, {number: 22, period: 1, side: 'N', name: 'Power Struggle - Poland', ops: 0, remove: 0}, {number: 23, period: 1, side: 'N', name: 'Power Struggle - Hungary', ops: 0, remove: 0}, {number: 24, period: 1, side: 'D', name: 'St. Nicholas Church*', ops: 1, remove: 1}, {number: 25, period: 1, side: 'C', name: 'Perestroika*', ops: 3, remove: 1}, {number: 26, period: 1, side: 'D', name: 'Helsinki Final Act*', ops: 1, remove: 1}, {number: 27, period: 1, side: 'D', name: 'Consumerism', ops: 3, remove: 0}, {number: 28, period: 1, side: 'C', name: 'Factory Party Cells', ops: 3, remove: 0}, {number: 29, period: 1, side: 'D', name: 'Jan Palach Week*', ops: 1, remove: 1}, {number: 30, period: 1, side: 'C', name: 'Tear Gas*', ops: 1, remove: 1}, {number: 31, period: 1, side: 'D', name: 'Intelligentsia', ops: 2, remove: 0}, {number: 32, period: 1, side: 'C', name: 'Peasant Parties*', ops: 2, remove: 1}, {number: 33, period: 1, side: 'D', name: 'Sajudis*', ops: 2, remove: 1}, {number: 34, period: 1, side: 'D', name: 'Fidesz*', ops: 2, remove: 1}, {number: 35, period: 1, side: 'C', name: 'Heal Our Bleeding Wound', ops: 3, remove: 0}, {number: 36, period: 1, side: 'D', name: 'Dash for the West*', ops: 3, remove: 1}, {number: 37, period: 1, side: 'C', name: 'Nagy Reburied*', ops: 3, remove: 1}, {number: 38, period: 1, side: 'C', name: 'The July Concept*', ops: 3, remove: 1}, {number: 39, period: 1, side: 'D', name: 'Eco-Glasnost*', ops: 2, remove: 1}, {number: 40, period: 1, side: 'D', name: 'Hungarian Democratic Forum*', ops: 3, remove: 1}, {number: 41, period: 2, side: 'C', name: 'Ceausescu*', ops: 3, remove: 1}, {number: 42, period: 2, side: 'N', name: 'Power Struggle - East Germany', ops: 0, remove: 0}, {number: 43, period: 2, side: 'N', name: 'Power Struggle - Bulgaria', ops: 0, remove: 0}, {number: 44, period: 2, side: 'N', name: 'Inflationary Currency*', ops: 3, remove: 1}, {number: 45, period: 2, side: 'D', name: 'Soviet Troop Withdrawals*', ops: 4, remove: 1}, {number: 46, period: 2, side: 'D', name: 'Goodbye Lenin!*', ops: 3, remove: 1}, {number: 47, period: 2, side: 'C', name: 'Bulgarian Turks expelled*', ops: 3, remove: 1}, {number: 48, period: 2, side: 'D', name: '\"We are the People!\"', ops: 3, remove: 0}, {number: 49, period: 2, side: 'D', name: 'Foreign Currency Debt Burden', ops: 1, remove: 0}, {number: 50, period: 2, side: 'D', name: 'This Sinatra Doctrine*', ops: 3, remove: 1}, {number: 51, period: 2, side: 'C', name: '40th Anniversary Celebration*', ops: 2, remove: 1}, {number: 52, period: 2, side: 'C', name: 'Normalization*', ops: 3, remove: 1}, {number: 53, period: 2, side: 'C', name: 'Li Peng*', ops: 2, remove: 1}, {number: 54, period: 3, side: 'D', name: 'The Crowd Turns Against Ceausescu*', ops: 3, remove: 1}, {number: 55, period: 2, side: 'N', name: 'Power Struggle - Czechoslovakia', ops: 0, remove: 0}, {number: 56, period: 2, side: 'D', name: 'Foreign Television*', ops: 2, remove: 1}, {number: 57, period: 2, side: 'C', name: 'Central Committee Reshuffle*', ops: 2, remove: 1}, {number: 58, period: 2, side: 'D', name: 'Austria-Hungary Border Reopened*', ops: 2, remove: 1}, {number: 59, period: 2, side: 'C', name: 'GrenzTruppen*', ops: 2, remove: 1}, {number: 60, period: 2, side: 'D', name: 'Toxic Waste*', ops: 2, remove: 1}, {number: 61, period: 2, side: 'D', name: 'The Monday Demonstrations*', ops: 4, remove: 1}, {number: 62, period: 2, side: 'D', name: 'Yakovlev Counsels Gorbachev*', ops: 2, remove: 1}, {number: 63, period: 2, side: 'D', name: 'Genscher*', ops: 2, remove: 1}, {number: 64, period: 2, side: 'D', name: 'Legacy of 1968*', ops: 4, remove: 1}, {number: 65, period: 2, side: 'D', name: 'Presidential Visit*', ops: 3, remove: 1}, {number: 66, period: 2, side: 'D', name: 'New Forum*', ops: 1, remove: 1}, {number: 67, period: 2, side: 'N', name: 'Reformer Rehabilitated*', ops: 2, remove: 1}, {number: 68, period: 2, side: 'D', name: 'Klaus and Komarek*', ops: 3, remove: 1}, {number: 69, period: 2, side: 'C', name: 'Systematization*', ops: 3, remove: 1}, {number: 70, period: 3, side: 'C', name: 'Securitate*', ops: 2, remove: 1}, {number: 71, period: 2, side: 'D', name: 'Kiss of Death*', ops: 3, remove: 1}, {number: 72, period: 2, side: 'D', name: 'Peasant Parties Revolt*', ops: 3, remove: 1}, {number: 73, period: 2, side: 'D', name: 'Laszlo Tokes*', ops: 2, remove: 1}, {number: 74, period: 2, side: 'D', name: 'FRG Embassies*', ops: 3, remove: 1}, {number: 75, period: 2, side: 'D', name: 'Exit Visas*', ops: 3, remove: 1}, {number: 76, period: 2, side: 'C', name: 'Warsaw Pact Summit*', ops: 2, remove: 1}, {number: 77, period: 2, side: 'D', name: 'Samizdat*', ops: 3, remove: 1}, {number: 78, period: 2, side: 'N', name: 'Workers Revolt', ops: 2, remove: 0}, {number: 79, period: 2, side: 'C', name: 'The Third Way*', ops: 2, remove: 1}, {number: 80, period: 2, side: 'C', name: 'Nepotism*', ops: 3, remove: 1}, {number: 81, period: 2, side: 'D', name: 'The Baltic Way*', ops: 3, remove: 1}, {number: 82, period: 3, side: 'C', name: 'Spitzel*', ops: 1, remove: 1}, {number: 83, period: 3, side: 'C', name: 'Modrow*', ops: 2, remove: 1}, {number: 84, period: 3, side: 'D', name: 'Breakaway Baltic Republics*', ops: 4, remove: 1}, {number: 85, period: 3, side: 'N', name: 'Tank Column/Tank Man*', ops: 2, remove: 1}, {number: 86, period: 3, side: 'D', name: '\"The Wall Must Go!*\"', ops: 3, remove: 0}, {number: 87, period: 3, side: 'D', name: 'Kohl Proposes Reunification*', ops: 3, remove: 1}, {number: 88, period: 3, side: 'C', name: 'Adamec*', ops: 2, remove: 1}, {number: 89, period: 3, side: 'D', name: 'Domino Theory*', ops: 3, remove: 1}, {number: 90, period: 3, side: 'D', name: 'Civic Forum*', ops: 4, remove: 1}, {number: 91, period: 3, side: 'D', name: 'My First Banana*', ops: 3, remove: 1}, {number: 92, period: 3, side: 'C', name: 'Betrayal*', ops: 3, remove: 1}, {number: 93, period: 3, side: 'D', name: 'Shock Therapy*', ops: 3, remove: 1}, {number: 94, period: 3, side: 'D', name: 'Union of Democratic Forces*', ops: 4, remove: 1}, {number: 95, period: 3, side: 'N', name: 'Power Struggle - Romania', ops: 0, remove: 0}, {number: 96, period: 3, side: 'C', name: 'The Chinese Solution*', ops: 1, remove: 1}, {number: 97, period: 3, side: 'D', name: 'The Tyrant is Gone*', ops: 2, remove: 1}, {number: 98, period: 3, side: 'C', name: 'Politburo Intrigue*', ops: 2, remove: 1}, {number: 99, period: 3, side: 'C', name: 'Ligachev*', ops: 3, remove: 1}, {number: 100, period: 3, side: 'N', name: 'Stand Fast*', ops: 3, remove: 1}, {number: 101, period: 3, side: 'C', name: 'Elena*', ops: 1, remove: 1}, {number: 102, period: 3, side: 'C', name: 'National Salvation Front*', ops: 3, remove: 1}, {number: 103, period: 3, side: 'D', name: 'Government Resigns*', ops: 3, remove: 1}, {number: 104, period: 3, side: 'C', name: 'New Year\'s Eve Party*', ops: 2, remove: 1}, {number: 105, period: 3, side: 'D', name: 'Public Against Violence*', ops: 3, remove: 1}, {number: 106, period: 3, side: 'C', name: 'Social Democratic Platform Adopted*', ops: 2, remove: 1}, {number: 107, period: 3, side: 'C', name: 'Massacre in Timisoara*', ops: 3, remove: 1}, {number: 108, period: 3, side: 'D', name: 'Army Backs Revolution*', ops: 3, remove: 1}, {number: 109, period: 3, side: 'C', name: 'Kremlin Coup!*', ops: 3, remove: 1}, {number: 110, period: 3, side: 'D', name: 'Malta Summit*', ops: 3, remove: 1}, ] exports.scenarios = [ "Standard" ] exports.roles = [ DEM, COM ] // --- SET UP --- exports.setup = function (seed, scenario, options) { console.log('setup ran') game = { seed: seed, log: [], undo: [], active: null, state: "com_init", played_card: [], available_ops: 0, starting_infl: { com_starting_infl: 0, dem_starting_infl: 0 }, turn: 0, round: 0, stability: 0, dem_TST: 0, com_TST: 0, vp: 0, pieces: [], strategy_deck: [], strategy_discard: [], democrat_hand: [], communist_hand: [], democrat_set_aside: [], } log_h1("1989 Dawn of Freedom") game.active = COM start_game() return game } function start_game() { //starting influence console.log('start_game called') // Draw cards game.strategy_deck = draw_deck(cards) console.log('starting deck: ', game.strategy_deck.length) draw_cards(game.strategy_deck, game.democrat_hand, game.communist_hand, hand_limit) console.log('democrat_hand: ', game.democrat_hand, 'communist hand: ', game.communist_hand) console.log('updated deck: ', game.strategy_deck.length) spaces.forEach(space => { game.pieces.push({ name_unique: space.name_unique, demInfl: space.demInfl, comInfl: space.comInfl, stability: space.stability }); }); //console.log('game.pieces: ', game.pieces) //Communist starts by placing 2 influence game.available_ops = 2 log_h1("Place starting influence") log_side() } exports.view = function(state, player) { game = state view = { log: game.log, active: game.active, prompt: null, actions: null, played_card: game.played_card, selected_space: game.selected_space, valid_spaces: [], pieces: game.pieces, turn: game.turn, round: game.round, vp: game.vp, stability: game.stability, dem_TST: game.dem_TST, com_TST: game.com_TST, strategy_deck: game.strategy_deck.length, democrat_hand: game.democrat_hand.length, communist_hand: game.communist_hand.length, hand: [], set_aside: [], } if (player === game.active && game.vm && game.vm.draw) view.drawn = game.vm.draw if (player === DEM) { view.hand = game.democrat_hand view.set_aside = game.democrat_set_aside } else if (player === COM) { view.hand = game.communist_hand } if (game.state === "game_over") { view.prompt = game.victory } else if (player === "Observer" || (game.active !== player && game.active !== "Both")) { if (states[game.state]) { let inactive = states[game.state].inactive if (typeof inactive === "function") view.prompt = `Waiting for ${game.active} ${inactive()}` else view.prompt = `Waiting for ${game.active} to ${inactive}` } else { view.prompt = "Unknown state: " + game.state } } else { view.actions = {} if (states[game.state]) states[game.state].prompt(player) else view.prompt = "Unknown state: " + game.state if (view.actions.undo === undefined) { if (game.undo && game.undo.length > 0) view.actions.undo = 1 else view.actions.undo = 0 } } return view } // === ACTIONS =========== function gen_action(action, argument) { //console.log('gen_action called with ', action, ' and ', argument) if (argument === undefined) { view.actions[action] = 1 } else { if (!(action in view.actions)) view.actions[action] = [] view.actions[action].push(argument) } //console.log('view.actions: ', view.actions, 'view.actions[action]: ', view.actions[action]) } function gen_action_infl(space){ gen_action("infl", space) } function gen_action_card(card){ gen_action("card", card) } exports.action = function (state, player, action, arg) { //console.log('exports.action called with state:' , state, 'player:', player, 'action: ', action, 'arg: ', arg) game = state if (states[game.state] && action in states[game.state]) { states[game.state][action](arg, player) } else { if (action === "undo" && game.undo && game.undo.length > 0) pop_undo() else throw new Error("Invalid action: " + action) } return game } // ============= GAME STATES ======================= states.com_init = { inactive: 'place starting influence', prompt() { if (game.available_ops == 0) { view.prompt = 'Place starting influence: done.'; gen_action("done"); return; } view.prompt = `Place ${game.available_ops} starting influence` let available_spaces = spaces.slice() for (let space of available_spaces) { //May not add where there is opposition influence const clicked_space = find_space_index(space.name_unique) if (game.pieces[clicked_space].demInfl === 0) { gen_action_infl(space.name_unique) } //console.log('state: com_init_1') //console.log('space: ', space) } }, infl(space) { add_infl(space) if (game.available_ops === 0) { view.prompt= 'Place starting influence: done.' gen_action("done") } }, done() { view.prompt='Influence added' game.starting_infl.com_starting_infl++ console.log('game.starting_infl.com_starting_infl: ', game.starting_infl.com_starting_infl) if (game.starting_infl.com_starting_infl == 1){ game.available_ops = 3 game.state = 'dem_init' next_player() log_side() } else if (game.starting_infl.com_starting_infl == 2) { game.available_ops = 4 game.state = 'dem_init' next_player() log_side() } else if (game.starting_infl.com_starting_infl == 3) { new_turn() clear_undo() game.state = 'choose_card' } } } states.dem_init = { inactive: 'place starting influence', prompt() { if (game.available_ops == 0) { view.prompt = 'Place starting influence: done.'; gen_action("done"); return; } view.prompt = `Place ${game.available_ops} starting influence` let available_spaces = spaces.slice() for (let space of available_spaces) { //May not add where there is opposition influence const clicked_space = find_space_index(space.name_unique) if (game.pieces[clicked_space].comInfl === 0) { gen_action_infl(space.name_unique) } //console.log('state: com_init_1') //console.log('space: ', space) } }, infl(space) { add_infl(space) /* if (game.available_ops === 0) { view.prompt= 'Place starting influence: done.' gen_action("done") } */ }, done() { view.prompt='Influence added' game.starting_infl.dem_starting_infl++ console.log('game.starting_infl.com_starting_infl: ', game.starting_infl.com_starting_infl) if (game.starting_infl.dem_starting_infl == 1){ game.available_ops = 3 } else if (game.starting_infl.dem_starting_infl == 2) { game.available_ops = 2 } next_player() log_side() game.state = 'com_init' } } /*states.start_new_turn = { inactive: 'to choose a card', prompt() { view.prompt = 'Choose a card', new_turn() game.state = 'select_card' }, }*/ states.choose_card = { inactive: 'choose a card', prompt() { if (game.played_card > 0) { view.prompt = 'Choose a card: done' gen_action("done"); return; } view.prompt = 'Choose a card' let available_cards if (game.active === DEM) { available_cards = game.democrat_hand } else { available_cards = game.communist_hand } console.log(available_cards) for (let card of available_cards) { gen_action_card(card) } }, card(card) { console.log('card number: ', card) log(`Played ${cards[card].name}`) game.played_card = card let find_card if (game.active === COM) { find_card = game.communist_hand.indexOf(card); const [playedCard] = game.communist_hand.splice(find_card, 1); } else { find_card = game.democrat_hand.indexOf(card); const [playedCard] = game.democrat_hand.splice(find_card, 1); } game.strategy_discard.push(card) console.log('discard: ', game.strategy_discard) game.available_ops = cards[card].ops console.log('game.available_ops: ', game.available_ops) view.prompt = 'Choose a card: done' gen_action("done") }, done () { game.state = 'play_card' } } states.play_card ={ inactive: 'play a card', prompt () { view.prompt = 'Play for:' clear_undo() gen_action('event') gen_action('influence') gen_action('tst') gen_action('support_check') }, event() { }, influence(influence) { console.log('influence called') game.state='add_influence' }, tst(tst) { console.log('tst called') }, support_check() { } } states.add_influence = { inactive: 'add influence', valid_spaces: [], prompt () { if (game.available_ops == 0) { view.prompt = 'Place starting influence: done.'; gen_action("done"); return; } view.prompt = `Add influence: ${game.available_ops} remaining` //Only do the influence check at the start. No chaining of placing influence if (this.valid_spaces.length === 0) { this.valid_spaces = this.get_valid_spaces(); } // Generate actions for initial valid spaces for (let space_id of this.valid_spaces) { const space = spaces.find(s => s.space_id === space_id); if (space) { gen_action_infl(space.name_unique); } } }, infl(space) { add_infl(space) }, get_valid_spaces() { return valid_spaces() }, done() { view.prompt = 'Influence added' game.state = 'test' } } states.test = { inactive: 'test', prompt () { view.prompt = "test" } } function add_infl(space) { log(`Added 1 influence in ${space}.`) push_undo() console.log('space clicked was: ', space) const clicked_space = find_space_index(space) const opponent_control = game.active === COM ? game.pieces[clicked_space].demCtrl : game.pieces[clicked_space].comCtrl console.log('clicked_space: ', clicked_space) console.log('game.pieces.space', game.pieces[clicked_space]) console.log('initial influence: ', game.pieces[clicked_space] ) if (game.active === COM) { game.pieces[clicked_space].comInfl++ } else { game.pieces[clicked_space].demInfl++ } if (opponent_control) { game.available_ops -= 2 } else { game.available_ops-- } console.log('new influence: ', game.pieces[clicked_space]) console.log('available_ops: ', game.available_ops) } function valid_spaces() { let valid_spaces_set = new Set(); // Iterate over all spaces to find the ones with the player's influence for (let space of spaces) { const player_influence = game.active === COM ? space.comInfl : space.demInfl; // If the space has the player's influence, add it and its adjacent spaces to the set if (player_influence > 0) { valid_spaces_set.add(space.space_id); for (let adj_space_id of space.adjacent) { if (adj_space_id) { const adj_space = spaces.find(s => s.space_id === adj_space_id); // Check if the adjacent space is controlled by the opponent const opponent_control = game.active === COM ? adj_space.demCtrl : adj_space.comCtrl; // Only add the adjacent space if the available_ops >= 2 or the space is not controlled by the opponent if (game.available_ops >= 2 || !opponent_control) { valid_spaces_set.add(adj_space.space_id); } } } } } // Convert the set to an array before returning view.valid_spaces = Array.from(valid_spaces_set) return Array.from(valid_spaces_set); } // =========== MOVING THROUGH TURNS ============ function new_turn() { game.turn ++ game.round = 1 log_h1("Turn " + game.turn) log_h2("Action Round " + game.round) log_side() } function next_player() { clear_undo() if (game.active === DEM) game.active = COM else game.active = DEM } function find_space_index(name_unique) { return game.pieces.findIndex(piece => piece && piece.name_unique === name_unique); } function find_card_index(card) { return cards.findIndex(card => card && card.number === card); } function draw_deck(deck) { return deck.filter(card => card && card.period === 1); } function draw_cards(deck, democrat_hand, communist_hand, hand_limit) { let turn = 'communist'; // Start with the communist player while (democrat_hand.length < hand_limit || communist_hand.length < hand_limit) { if (deck.length === 0) { console.log('No more cards in the deck.'); break; } if (turn === 'communist' && communist_hand.length < hand_limit) { communist_hand.push(draw_card(deck).number); turn = 'democrat'; // Switch turn } else if (turn === 'democrat' && democrat_hand.length < hand_limit) { democrat_hand.push(draw_card(deck).number); turn = 'communist'; // Switch turn } } } function draw_card(deck) { const randomIndex = Math.floor(Math.random() * deck.length); return deck.splice(randomIndex, 1)[0]; } // === COMMON LIBRARY === function shuffle(list) { // Fisher-Yates shuffle for (let i = list.length - 1; i > 0; --i) { let j = random(i + 1) let tmp = list[j] list[j] = list[i] list[i] = tmp } return list } // ======== LOG COMMANDS ============= function log(msg) { game.log.push(msg) } function log_br() { if (game.log.length > 0 && game.log[game.log.length - 1] !== "") game.log.push("") } function logi(msg) { game.log.push(">" + msg) } function log_h1(msg) { log_br() log(".h1 " + msg) log_br() } function log_h2(msg) { log_br() log(".h2 " + msg) log_br() } function log_h3(msg) { log_br() log(".h3 " + msg) } function log_side() { log_br() if (game.active === DEM) log(".h2d " + game.active) else log(".h2c " + game.active) log_br() } function log_sep() { log(".hr") } // ============ UNDO FUNCTIONS ================== function clear_undo() { if (game.undo.length > 0) game.undo = [] } function push_undo() { let copy = {} for (let k in game) { let v = game[k] if (k === "undo") continue else if (k === "log") v = v.length else if (typeof v === "object" && v !== null) v = object_copy(v) copy[k] = v } game.undo.push(copy) } function pop_undo() { let save_log = game.log let save_undo = game.undo game = save_undo.pop() save_log.length = game.log game.log = save_log game.undo = save_undo } // Fast deep copy for objects without cycles function object_copy(original) { if (Array.isArray(original)) { let n = original.length let copy = new Array(n) for (let i = 0; i < n; ++i) { let v = original[i] if (typeof v === "object" && v !== null) copy[i] = object_copy(v) else copy[i] = v } return copy } else { let copy = {} for (let i in original) { let v = original[i] if (typeof v === "object" && v !== null) copy[i] = object_copy(v) else copy[i] = v } return copy } }