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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
|
"use strict"
let cards = require("./cards.js")
const Afghan = 'Afghan'
const British = 'British'
const Russian = 'Russian'
const Political = 'Political'
const Intelligence = 'Intelligence'
const Economic = 'Economic'
const Military = 'Military'
const Persia = 201
const Transcaspia = 202
const Herat = 203
const Kabul = 204
const Kandahar = 205
const Punjab = 206
const Persia_Transcaspia = 301
const Persia_Herat = 302
const Transcaspia_Herat = 303
const Transcaspia_Kabul = 304
const Herat_Kabul = 305
const Herat_Kandahar = 306
const Kabul_Kandahar = 307
const Kabul_Punjab = 308
const Kandahar_Punjab = 309
const Gift2 = 400
const Gift4 = 401
const Gift6 = 402
const Safe_House = 500
const first_region = 201
const last_region = 206
const PUBLIC_WITHDRAWAL = 111
const SAFE_HOUSE_1 = 41
const SAFE_HOUSE_2 = 72
const player_names = [
"Gray",
"Blue",
"Tan",
"Red",
"Black",
"None"
]
const player_names_by_scenario = {
"2P": player_names.slice(0, 2),
"3P": player_names.slice(0, 3),
"4P": player_names.slice(0, 4),
"5P": player_names.slice(0, 5),
}
const player_index = Object.fromEntries(Object.entries(player_names).map(([k,v])=>[v,k|0]))
const region_names = {
[Persia]: "Persia",
[Transcaspia]: "Transcaspia",
[Herat]: "Herat",
[Kabul]: "Kabul",
[Kandahar]: "Kandahar",
[Punjab]: "Punjab",
}
const region_index = {
"Persia": Persia,
"Transcaspia": Transcaspia,
"Herat": Herat,
"Kabul": Kabul,
"Kandahar": Kandahar,
"Punjab": Punjab,
}
cards.forEach(card => {
if (card) {
card.region = region_index[card.region]
if (card.name === 'EVENT')
card.name = card.if_discarded + " / " + card.if_purchased
}
})
const border_names = {
[Persia_Transcaspia]: "Persia/Transcaspia",
[Persia_Herat]: "Persia/Herat",
[Transcaspia_Herat]: "Transcaspia/Herat",
[Transcaspia_Kabul]: "Transcaspia/Kabul",
[Herat_Kabul]: "Herat/Kabul",
[Herat_Kandahar]: "Herat/Kandahar",
[Kabul_Kandahar]: "Kabul/Kandahar",
[Kabul_Punjab]: "Kabul/Punjab",
[Kandahar_Punjab]: "Kandahar/Punjab",
}
const borders = {
[Transcaspia]: [ Persia_Transcaspia, Transcaspia_Herat, Transcaspia_Kabul ],
[Kabul]: [ Transcaspia_Kabul, Herat_Kabul, Kabul_Kandahar, Kabul_Punjab ],
[Punjab]: [ Kabul_Punjab, Kandahar_Punjab ],
[Persia]: [ Persia_Transcaspia, Persia_Herat ],
[Herat]: [ Transcaspia_Herat, Persia_Herat, Herat_Kabul, Herat_Kandahar ],
[Kandahar]: [ Kabul_Kandahar, Herat_Kandahar, Kandahar_Punjab ],
}
const roads = {
[Transcaspia]: [ Persia, Herat, Kabul ],
[Kabul]: [ Transcaspia, Herat, Kandahar, Punjab ],
[Punjab]: [ Kabul, Kandahar ],
[Persia]: [ Transcaspia, Herat ],
[Herat]: [ Transcaspia, Persia, Kabul, Kandahar ],
[Kandahar]: [ Kabul, Herat, Punjab ],
}
function is_dominance_check(c) {
return c >= 101 && c <= 104
}
function is_event_card(c) {
return c > 100
}
let game = null
let player = null
let view = null
let states = {}
const scenario_player_count = { "2P": 2, "3P": 3, "4P": 4, "5P": 5 }
exports.scenarios = [ "3P", "4P", "5P", "2P" ]
exports.roles = function (scenario) {
return player_names_by_scenario[scenario]
}
function random(n) {
if (game.rng === 1)
return ((game.seed = game.seed * 69621 % 0x7fffffff) / 0x7fffffff) * n | 0
return (game.seed = game.seed * 200105 % 34359738337) % n
}
function shuffle(deck) {
for (let i = deck.length - 1; i > 0; --i) {
let j = random(i + 1)
let tmp = deck[j]
deck[j] = deck[i]
deck[i] = tmp
}
}
function remove_from_array(array, item) {
let i = array.indexOf(item)
if (i >= 0)
array.splice(i, 1)
}
function set_active(new_active) {
if (game.active !== new_active)
clear_undo()
game.active = new_active
update_aliases()
}
function update_aliases() {
player = game.players[game.active]
}
function find_card_in_market(c) {
for (let row = 0; row < 2; ++row)
for (let col = 0; col < 6; ++col)
if (c === game.market_cards[row][col])
return [row, col]
return null
}
function find_card_in_court(c) {
for (let p = 0; p < game.players.length; ++p) {
let court = game.players[p].court
for (let i = 0; i < court.length; ++i)
if (court[i] === c)
return p
}
return -1
}
function next_player(current) {
return (current + 1) % game.players.length
}
function a_coalition(s) {
switch (s) {
case Afghan: return "an Afghan"
case British: return "a British"
case Russian: return "a Russian"
}
}
function logbr() {
if (game.log.length > 0 && game.log[game.log.length-1] !== "")
game.log.push("")
}
function log(msg) {
game.log.push(msg)
}
function logi(msg) {
game.log.push(">" + msg)
}
function deep_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] = deep_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] = deep_copy(v)
else
copy[i] = v
}
return copy
}
}
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 = deep_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
}
function clear_undo() {
game.undo = []
}
function gen_action(action, argument=undefined) {
if (argument !== undefined) {
if (!(action in view.actions)) {
view.actions[action] = [ argument ]
} else {
if (!view.actions[action].includes(argument))
view.actions[action].push(argument)
}
} else {
view.actions[action] = 1
}
}
// STATE QUERIES
function active_has_court_card(c) {
let court = player.court
for (let i = 0; i < court.length; ++i)
if (court[i] === c)
return true
return false
}
function player_has_court_card(p, c) {
let court = game.players[p].court
for (let i = 0; i < court.length; ++i)
if (court[i] === c)
return true
return false
}
function which_player_has_court_card(c) {
for (let p = 0; p < game.players.length; ++p) {
let court = game.players[p].court
for (let i = 0; i < court.length; ++i)
if (court[i] === c)
return p
}
return -1
}
function active_has_russian_influence() { return active_has_court_card(70) }
function active_has_persian_influence() { return active_has_court_card(68) }
function active_has_herat_influence() { return active_has_court_card(66) }
function active_has_claim_of_ancient_lineage() { return active_has_court_card(5) }
function active_has_indian_supplies() { return active_has_court_card(51) }
function active_has_well_connected() { return active_has_court_card(56) }
function active_has_strange_bedfellows() { return active_has_court_card(21) }
function active_has_infrastructure() { return active_has_court_card(78) }
function active_has_civil_service_reforms() { return active_has_court_card(24) }
function active_has_charismatic_courtiers() { return active_has_court_card(42) }
function active_has_blackmail_kandahar() { return active_has_court_card(43) }
function active_has_blackmail_herat() { return active_has_court_card(54) }
function player_has_bodyguards(p) { return player_has_court_card(p, 15) || player_has_court_card(p, 83) }
function player_has_indispensable_advisors(p) { return player_has_court_card(p, 1) }
function player_has_citadel_in_kabul(p) { return player_has_court_card(p, 17) }
function player_has_citadel_in_transcaspia(p) { return player_has_court_card(p, 97) }
function player_has_safe_house(p) { return player_has_court_card(p, 41) || player_has_court_card(p, 72) }
function which_player_has_insurrection() { return which_player_has_court_card(3) }
function player_has_citadel(p, r) {
if (r === Kabul) return player_has_citadel_in_kabul(p)
if (r === Transcaspia) return player_has_citadel_in_transcaspia(p)
return false
}
function player_coalition_blocks(p) {
switch (game.players[p].loyalty) {
case Afghan: return 0
case British: return 12
case Russian: return 24
}
}
function active_coalition_blocks() {
switch (player.loyalty) {
case Afghan: return 0
case British: return 12
case Russian: return 24
}
}
function player_cylinders(p) {
return 36 + p * 10
}
function active_cylinders() {
return 36 + game.active * 10
}
function min_gift_cost() {
let x = active_cylinders()
let avail_2 = true, avail_4 = true, avail_6 = true
for (let i = x; i < x + 10; ++i) {
let s = game.pieces[i]
if (s === Gift2) avail_2 = false
else if (s === Gift4) avail_4 = false
else if (s === Gift6) avail_6 = false
}
if (avail_2) return 2
if (avail_4) return 4
if (avail_6) return 6
return 1000
}
function gen_place_gift() {
let x = active_cylinders()
let avail_2 = true, avail_4 = true, avail_6 = true
for (let i = x; i < x + 10; ++i) {
let s = game.pieces[i]
if (s === Gift2) avail_2 = false
else if (s === Gift4) avail_4 = false
else if (s === Gift6) avail_6 = false
}
if (avail_2 && player.coins >= 2) gen_action('place_gift', 2)
if (avail_4 && player.coins >= 4) gen_action('place_gift', 4)
if (avail_6 && player.coins >= 6) gen_action('place_gift', 6)
}
function ruler_of_region(r) {
let ruler = -1
let n_afghan = 0
let n_british = 0
let n_russian = 0
for (let i = 0; i < 12; ++i) {
if (game.pieces[i] === r)
n_afghan ++
if (game.pieces[i+12] === r)
n_british ++
if (game.pieces[i+24] === r)
n_russian ++
}
let max_ruling = Math.max(n_afghan, n_british, n_russian)
for (let p = 0; p < game.players.length; ++p) {
let n_tribes = 0
let x = player_cylinders(p)
for (let i = x; i < x + 10; ++i)
if (game.pieces[i] === r)
n_tribes++
let n_ruling = n_tribes
if (game.players[p].loyalty === Afghan)
n_ruling += n_afghan
if (game.players[p].loyalty === British)
n_ruling += n_british
if (game.players[p].loyalty === Russian)
n_ruling += n_russian
if (n_ruling === max_ruling) {
ruler = -1
} else if (n_ruling > max_ruling) {
max_ruling = n_ruling
if (n_tribes > 0)
ruler = p
else
ruler = -1
}
}
return ruler
}
function player_rules_region(p, r) {
return ruler_of_region(r) === p
}
function active_rules_region(r) {
return player_rules_region(game.active, r)
}
function player_rules_any_region(p) {
for (let r = first_region; r <= last_region; ++r)
if (player_rules_region(p, r))
return true
return false
}
function active_rules_any_region() {
return player_rules_any_region(game.active)
}
function active_can_betray() {
let x = active_cylinders()
for (let i = x; i < x + 10; ++i) {
if (game.pieces[i] >= 1 && game.pieces[i] <= 100) {
let c = game.pieces[i]
if (cards[c].suit !== Political)
return true
let p = find_card_in_court(c)
if (!player_has_bodyguards(p))
return true
}
}
return false
}
function card_has_no_spies(c) {
for (let p = 0; p < game.players.length; ++p) {
let x = player_cylinders(p)
for (let i = x; i < x + 10; ++i)
if (game.pieces[i] === c)
return false
}
return true
}
function market_cost(col, c) {
if (col === 0)
return 0
if (cards[c].patriot === Russian && active_has_russian_influence())
return 0
if (cards[c].region === Persia && active_has_persian_influence())
return 0
if (cards[c].region === Herat && active_has_herat_influence())
return 0
if (game.favored === Military)
return 2 * col
return col
}
function is_favored_suit(c) {
if (cards[c].suit === game.favored)
return true
if (player.events.new_tactics && cards[c].suit === Military)
return true
if (c === 91) return true // Savvy Operator
if (c === 99) return true // Irregulars
return false
}
function rightmost_card(row, i) {
while (i >= 0 && game.market_cards[row][i] === 0)
--i
return i
}
function pay_action_cost(cost, offset) {
player.coins -= cost
let ra = rightmost_card(0, 5)
let rb = rightmost_card(1, 5)
for (let i = 0; i < offset; ++i) {
ra = rightmost_card(0, ra-1)
rb = rightmost_card(1, rb-1)
}
for (let i = 0; i < cost; i += 2) {
if (ra >= 0) {
mark_card_used(game.market_cards[0][ra])
game.market_coins[0][ra] ++
}
if (rb >= 0) {
mark_card_used(game.market_cards[1][rb])
game.market_coins[1][rb] ++
}
ra = rightmost_card(0, ra-1)
rb = rightmost_card(1, rb-1)
}
check_public_withdrawal()
}
function remove_all_tribes_and_armies(where) {
logi(`Removed all tribes and armies in ${region_names[where]}.`)
for (let i = 0; i < 36; ++i)
if (game.pieces[i] === where)
game.pieces[i] = 0
for (let p = 0; p < game.players.length; ++p) {
let x = player_cylinders(p)
let maybe_overthrow = false
for (let i = x; i < x + 10; ++i) {
if (game.pieces[i] === where) {
game.pieces[i] = 0
maybe_overthrow = true
}
}
if (maybe_overthrow)
check_region_overthrow(p, where)
}
}
function player_with_most_spies(c) {
let who = -1
let max_spies = 0
for (let p = 0; p < game.players.length; ++p) {
let n_spies = count_player_cylinders(p, c)
if (n_spies === max_spies) {
who = -1
} else if (n_spies > max_spies) {
max_spies = n_spies
who = p
}
}
return who
}
function select_available_cylinder() {
let x = active_cylinders()
for (let i = x; i < x + 10; ++i)
if (game.pieces[i] === 0)
return i
return -1
}
function gen_select_cylinder() {
let x = active_cylinders()
for (let i = x; i < x + 10; ++i)
if (!game.used_pieces.includes(i))
gen_action('piece', i)
}
function gen_select_spy_to_move() {
let x = active_cylinders()
for (let i = x; i < x + 10; ++i)
if (game.pieces[i] > 0 && game.pieces[i] <= 100)
gen_action('piece', i)
}
function gen_select_tribe_to_move() {
let x = active_cylinders()
for (let i = x; i < x + 10; ++i)
if (game.pieces[i] >= first_region && game.pieces[i] <= last_region)
gen_action('piece', i)
}
function select_available_block() {
let b = active_coalition_blocks()
for (let i = b + 11; i >= b; --i)
if (game.pieces[i] === 0)
return i
return -1
}
function select_afghan_block() {
for (let i = 0; i < 12; ++i)
if (game.pieces[i] === 0)
return i
return -1
}
function gen_select_block() {
let b = active_coalition_blocks()
for (let i = b; i < b + 12; ++i)
if (!game.used_pieces.includes(i))
gen_action('piece', i)
}
function gen_select_army_to_move() {
let b = active_coalition_blocks()
for (let i = b; i < b + 12; ++i) {
let r = game.pieces[i]
if (r >= first_region && r <= last_region)
if (active_can_move_from_region(r))
gen_action('piece', i)
}
}
// DISCARD COURT CARD
function discard_court_card(c) {
let pidx = -1
// Remove card from court
for (let p = 0; p < game.players.length; ++p) {
let i = game.players[p].court.indexOf(c)
if (i >= 0) {
game.players[p].court.splice(i, 1)
pidx = p
break
}
}
if (pidx !== game.phasing)
log(`Discarded #${c} from ${player_names[pidx]} court.`)
else
log(`Discarded #${c} from court.`)
// Return all spies on card
for (let p = 0; p < game.players.length; ++p) {
let x = player_cylinders(p)
for (let i = x; i < x + 10; ++i) {
if (game.pieces[i] === c) {
log(`Returned ${player_names[p]} spy.`)
game.pieces[i] = 0
}
}
}
// Return rupees for leverage
if (cards[c].leveraged) {
if (pidx !== game.phasing)
log(`${player_names[pidx]} paid back leverage.`)
else
log(`Paid back leverage.`)
game.players[pidx].coins -= 2
}
if (cards[c].suit === Political)
check_court_overthrow(pidx, cards[c].region)
}
// CHANGE LOYALTY
function change_loyalty(new_loyalty) {
player.loyalty = new_loyalty
log(`Loyalty to ${player.loyalty}.`)
for (let i = 0; i < player.court.length;) {
let c = player.court[i]
let card = cards[c]
if (card.patriot && card.patriot !== new_loyalty) {
discard_court_card(c)
} else {
++i
}
}
let x = active_cylinders()
for (let i = x; i < x + 10; ++i) {
let s = game.pieces[i]
if (s === Gift2 || s === Gift4 || s === Gift6)
game.pieces[i] = 0
}
player.prizes = 0
}
// RETURN LEVERAGE
function check_leverage() {
let first = game.phasing
for (let p = first; p < game.players.length; ++p)
if (check_player_leverage(p))
return
for (let p = 0; p < first; ++p)
if (check_player_leverage(p))
return
check_safe_house()
}
function check_player_leverage(p) {
if (game.players[p].coins < 0) {
if (game.players[p].hand.length + game.players[p].court.length === 0) {
game.players[p].coins = 0
} else {
logbr()
set_active(p)
game.state = 'leverage'
return true
}
}
return false
}
states.leverage = {
prompt() {
if (player.coins < 0) {
view.prompt = `Discard cards from your hand or court to pay back leverage.`
for (let i = 0; i < player.hand.length; ++i)
gen_action('card', player.hand[i])
for (let i = 0; i < player.court.length; ++i)
gen_action('card', player.court[i])
} else {
view.prompt = `Discard cards from your hand or court to pay back leverage \u2014 done.`
gen_action('next')
}
},
card(c) {
push_undo()
player.coins ++
if (player.hand.includes(c)) {
log(`Discarded #${c} from hand.`)
remove_from_array(player.hand, c)
} else {
discard_court_card(c)
}
if (player.hand.length + player.court.length === 0)
player.coins = 0
},
next() {
push_undo()
check_leverage()
}
}
// OVERTHROW
function check_court_overthrow(p, r) {
let court = game.players[p].court
let x = player_cylinders(p)
let nc = 0
for (let i = 0; i < court.length; ++i) {
let info = cards[court[i]]
if (info.suit === Political && info.region === r)
++nc
}
let nt = 0
for (let i = x; i < x + 10; ++i)
if (game.pieces[i] === r)
++nt
if (nc === 0 && nt > 0) {
log(`${player_names[p]} overthrown in ${region_names[r]}.`)
for (let i = x; i < x + 10; ++i) {
if (game.pieces[i] === r) {
// log(`Removed ${player_names[p]} tribe.`)
game.pieces[i] = 0
}
}
}
}
function check_region_overthrow(p, r) {
let court = game.players[p].court
let x = player_cylinders(p)
let nc = 0
for (let i = 0; i < court.length; ++i) {
let info = cards[court[i]]
if (info.suit === Political && info.region === r)
++nc
}
let nt = 0
for (let i = x; i < x + 10; ++i)
if (game.pieces[i] === r)
++nt
if (nt === 0 && nc > 0) {
log(`${player_names[p]} overthrown in ${region_names[r]}.`)
for (let i = 0; i < court.length;) {
let info = cards[court[i]]
if (info.suit === Political && info.region === r)
discard_court_card(court[i])
else
++i
}
}
}
// BRIBES
states.bribe = {
prompt() {
let p = game.bribe
view.prompt = `Must pay ${game.count} rupee bribe to ${player_names[p]}.`
if (player.coins - game.reserve >= game.count)
gen_action('pay')
gen_action('beg')
if (player.events.courtly_manners)
gen_action('courtly_manners')
if (game.undo.length === 0)
gen_action('cancel')
},
courtly_manners() {
log(`Did not pay bribe.`)
end_bribe()
},
pay() {
let p = game.bribe
log(`Paid ${game.count} to ${player_names[p]}.`)
game.players[p].coins += game.count
game.players[game.active].coins -= game.count
end_bribe()
},
beg() {
let p = game.bribe
if (typeof game.where === 'string')
log(`Asked ${player_names[p]} to waive the bribe to use #${game.card} to ${game.where}.`)
else
log(`Asked ${player_names[p]} to waive the bribe to play #${game.card}.`)
game.state = 'waive'
set_active(p)
},
refuse() {
// for old replays
states.bribe.cancel()
},
cancel() {
game.card = 0
game.where = 0
resume_actions()
},
}
states.waive = {
prompt() {
if (typeof game.where === 'string')
view.prompt = `${player_names[game.phasing]} asks you to waive the bribe to use #${game.card} to ${game.where}.`
else
view.prompt = `${player_names[game.phasing]} asks you to waive the bribe to play #${game.card}.`
let max_cost = Math.min(game.players[game.phasing].coins - game.reserve, game.count)
gen_action('waive')
for (let i = 1; i <= max_cost; ++i)
gen_action('offer_' + i)
gen_action('refuse')
},
waive() {
log(`${player_names[game.active]} waived the bribe.`)
set_active(game.phasing)
end_bribe()
},
offer_1() { do_offer(1) },
offer_2() { do_offer(2) },
offer_3() { do_offer(3) },
offer_4() { do_offer(4) },
offer_5() { do_offer(5) },
offer_6() { do_offer(6) },
offer_7() { do_offer(7) },
offer_8() { do_offer(8) },
offer_9() { do_offer(9) },
refuse() {
log(`${player_names[game.active]} refused to waive the bribe.`)
game.state = 'bribe'
set_active(game.phasing)
},
}
function do_offer(n) {
log(`${player_names[game.active]} reduced the bribe to ${n}.`)
game.count = 1
game.state = 'bribe'
set_active(game.phasing)
}
function end_bribe() {
if (typeof game.where === 'string')
do_card_action_2()
else
do_play_2()
}
// STARTING LOYALTY
states.loyalty = {
prompt() {
view.prompt = `Choose your loyalty \u2014 Afghan, British, or Russian.`
gen_action('loyalty_afghan')
gen_action('loyalty_british')
gen_action('loyalty_russian')
},
loyalty_afghan() {
set_starting_loyalty(Afghan)
},
loyalty_british() {
set_starting_loyalty(British)
},
loyalty_russian() {
set_starting_loyalty(Russian)
},
}
function set_starting_loyalty(loyalty) {
log(`${player_names[game.active]} loyalty to ${loyalty}.`)
player.loyalty = loyalty
let next = next_player(game.active)
if (game.players[next].loyalty)
goto_actions()
else
set_active(next)
}
// ACTION PHASE
function goto_actions() {
game.phasing = game.active
game.actions = 2
game.used_cards = [] // track cards that have been used
game.used_pieces = []
game.selected = -1
game.where = 0
logbr()
log(`.turn ${player_names[game.phasing]}`)
logbr()
let bmh = active_can_blackmail(Herat)
let bmk = active_can_blackmail(Kandahar)
if (bmh || bmk) {
game.state = 'blackmail'
game.where = (bmh && bmk) ? -1 : (bmh ? Herat : Kandahar)
game.selected = select_available_cylinder()
} else {
resume_actions()
}
}
function end_action() {
check_leverage()
}
function resume_actions() {
set_active(game.phasing)
game.selected = -1
game.where = 0
game.state = 'actions'
}
function goto_next_player() {
game.phasing = next_player(game.phasing)
set_active(game.phasing)
goto_actions()
}
function mark_card_used(c) {
if (!game.used_cards.includes(c))
game.used_cards.push(c)
}
states.actions = {
prompt() {
// Pass / End turn
if (game.actions > 0) {
gen_action('end_turn_pass')
} else {
gen_action('end_turn')
}
// Purchase
if (game.actions > 0) {
for (let row = 0; row < 2; ++row) {
for (let col = 0; col < 6; ++col) {
let c = game.market_cards[row][col]
if (c && market_cost(col, c) <= player.coins && !game.used_cards.includes(c) && c !== PUBLIC_WITHDRAWAL)
gen_action('card', c)
}
}
}
// Play
if (game.actions > 0) {
for (let i = 0; i < player.hand.length; ++i) {
let c = player.hand[i]
gen_action('play_left', c)
gen_action('play_right', c)
}
}
// Card-based actions
let bonus = false
for (let i = 0; i < player.court.length; ++i) {
let c = player.court[i]
let card = cards[c]
if (game.used_cards.includes(c))
continue
let favored = is_favored_suit(c)
if (favored || game.actions > 0) {
let usable = false
if (card.tax && active_can_tax()) {
gen_action('tax', c)
usable = true
}
if (card.gift && player.coins >= min_gift_cost()) {
gen_action('gift', c)
usable = true
}
if (card.build && player.coins >= 2 && active_rules_any_region()) {
gen_action('build', c)
usable = true
}
if (card.move && active_can_move()) {
gen_action('move', c)
usable = true
}
if (card.betray && player.coins >= 2 && active_can_betray()) {
gen_action('betray', c)
usable = true
}
if (card.battle && active_can_battle()) {
gen_action('battle', c)
usable = true
}
if (usable && favored)
bonus = true
}
}
if (game.actions === 2)
view.prompt = `You may take two actions.`
else if (game.actions === 1)
view.prompt = `You may take one more action.`
else
view.prompt = `You have no more actions.`
if (bonus)
view.prompt += ` You may take bonus actions.`
},
// Purchase card from market
card(c) {
push_undo()
logbr()
let [row, col] = find_card_in_market(c)
game.actions --
let cost = market_cost(col, c)
let cost_per_card = cost / col
if (cost_per_card > 0) {
for (let i = 0; i < col; ++i) {
if (game.market_cards[row][i] > 0) {
game.market_coins[row][i] += cost_per_card
mark_card_used(game.market_cards[row][i])
} else {
game.market_coins[1-row][i] += cost_per_card
mark_card_used(game.market_cards[1-row][i])
}
}
}
check_public_withdrawal()
logbr()
if (cost > 0)
player.coins -= cost
let took = game.market_coins[row][col]
if (took > 0)
player.coins += took
game.market_coins[row][col] = 0
game.market_cards[row][col] = 0
log(`Purchased #${c}.`)
if (cost > 0 && took > 0)
logi(`Paid ${cost} and took ${took}.`)
else if (cost > 0)
logi(`Paid ${cost}.`)
else if (took > 0)
logi(`Took ${took}.`)
if (is_dominance_check(c)) {
do_dominance_check('purchase')
} else if (is_event_card(c)) {
events_if_purchased[cards[c].if_purchased]()
} else {
player.hand.push(c)
resume_actions()
}
},
// Play card to court
play_left(c) { do_play_1(c, 0) },
play_right(c) { do_play_1(c, 1) },
// Use card based ability
tax(c) { do_card_action_1(c, "Tax", 0) },
gift(c) { do_card_action_1(c, "Gift", min_gift_cost()) },
build(c) { do_card_action_1(c, "Build", 2) },
move(c) { do_card_action_1(c, "Move", 0) },
betray(c) { do_card_action_1(c, "Betray", 2) },
battle(c) { do_card_action_1(c, "Battle", 0) },
end_turn_pass() {
logbr()
log(`Passed.`)
goto_cleanup_court()
},
end_turn() {
goto_cleanup_court()
},
}
// PLAY CARD
function do_play_1(c, side) {
push_undo()
game.card = c
game.where = side
if (!active_has_charismatic_courtiers() && !game.events.disregard_for_customs) {
let ruler = ruler_of_region(cards[c].region)
if (ruler >= 0 && ruler !== game.active) {
logbr()
game.state = 'bribe'
game.count = count_player_cylinders(ruler, cards[c].region)
game.reserve = 0
game.bribe = ruler
return
}
}
do_play_2()
}
function do_play_2() {
let c = game.card
let side = game.where
game.actions --
logbr()
log(`Played #${c}.`)
let idx = player.hand.indexOf(c)
player.hand.splice(idx, 1)
if (side)
player.court.push(c)
else
player.court.unshift(c)
goto_play_patriot()
}
function goto_play_patriot() {
let card = cards[game.card]
if (card.patriot && card.patriot !== player.loyalty)
change_loyalty(card.patriot)
goto_play_tribes()
}
function goto_play_tribes() {
let card = cards[game.card]
if (card.tribes) {
game.count = card.tribes
game.state = 'place_tribe'
game.where = card.region
game.selected = select_available_cylinder()
} else {
goto_play_roads()
}
}
states.place_tribe = {
inactive: "place tribe",
prompt() {
if (game.selected < 0) {
view.prompt = `Place tribe in ${region_names[game.where]} \u2014 select a cylinder.`
gen_select_cylinder()
} else {
view.prompt = `Place tribe in ${region_names[game.where]}.`
gen_action('space', game.where)
}
},
piece(x) {
push_undo()
game.selected = x
},
space(s) {
push_undo()
logi(`Tribe to ${region_names[s]}.`)
game.pieces[game.selected] = s
game.used_pieces.push(game.selected)
game.selected = -1
if (--game.count === 0)
goto_play_roads()
else
game.selected = select_available_cylinder()
},
}
function goto_play_roads() {
let card = cards[game.card]
if (card.roads) {
game.count = card.roads
game.state = 'place_road'
game.where = card.region
game.selected = select_available_block()
} else {
goto_play_armies()
}
}
states.place_road = {
inactive: "place road",
prompt() {
if (game.selected < 0) {
view.prompt = `Place ${player.loyalty} road in ${region_names[game.where]} \u2014 select a block to move.`
gen_select_block()
} else {
view.prompt = `Place ${player.loyalty} road in ${region_names[game.where]}.`
for (let s of borders[game.where])
gen_action('space', s)
}
},
piece(x) {
push_undo()
game.selected = x
},
space(s) {
push_undo()
logi(`${player.loyalty} road to ${border_names[s]}.`)
game.pieces[game.selected] = s
game.used_pieces.push(game.selected)
game.selected = -1
if (--game.count === 0)
goto_play_armies()
else
game.selected = select_available_block()
},
}
function goto_play_armies() {
let card = cards[game.card]
if (card.armies) {
game.count = card.armies
game.state = 'place_army'
game.where = card.region
game.selected = select_available_block()
} else {
goto_play_spies()
}
}
states.place_army = {
inactive: "place army",
prompt() {
if (game.selected < 0) {
view.prompt = `Place ${player.loyalty} army in ${region_names[game.where]} \u2014 select a block to move.`
gen_select_block()
} else {
view.prompt = `Place ${player.loyalty} army in ${region_names[game.where]}.`
gen_action('space', game.where)
}
},
piece(x) {
push_undo()
game.selected = x
},
space(s) {
push_undo()
logi(`${player.loyalty} army to ${region_names[s]}.`)
game.pieces[game.selected] = s
game.used_pieces.push(game.selected)
game.selected = -1
if (--game.count === 0)
goto_play_spies()
else
game.selected = select_available_block()
},
}
function goto_play_spies() {
let card = cards[game.card]
if (card.spies) {
game.count = card.spies
game.state = 'place_spy'
game.where = card.region
game.selected = select_available_cylinder()
} else {
goto_play_leveraged()
}
}
states.place_spy = {
inactive: "place spy",
prompt() {
if (game.selected < 0) {
view.prompt = `Place spy on a court card in ${region_names[game.where]} \u2014 select a cylinder.`
gen_select_cylinder()
} else {
view.prompt = `Place spy on a court card in ${region_names[game.where]}.`
for (let p = 0; p < game.players.length; ++p) {
let court = game.players[p].court
for (let i = 0; i < court.length; ++i) {
let card = cards[court[i]]
if (card.region === game.where) {
gen_action('card', court[i])
}
}
}
}
},
piece(x) {
push_undo()
game.selected = x
},
card(c) {
push_undo()
let p = find_card_in_court(c)
if (p !== game.active)
logi(`Spy to #${c} in ${player_names[p]} court.`)
else
logi(`Spy to #${c}.`)
game.pieces[game.selected] = c
game.used_pieces.push(game.selected)
game.selected = -1
if (--game.count === 0)
goto_play_leveraged()
else
game.selected = select_available_cylinder()
},
}
function goto_play_leveraged() {
let card = cards[game.card]
if (card.leveraged) {
logi(`Leveraged.`)
player.coins += 2
}
goto_play_favored_suit_impact()
}
function goto_play_favored_suit_impact() {
let card = cards[game.card]
if (card.climate && !game.events.pashtunwali_values) {
game.state = 'favored_suit_impact'
game.where = card.climate
} else {
end_action()
}
}
states.favored_suit_impact = {
inactive: "favored suit",
prompt() {
view.prompt = `Change the favored suit to ${game.where}.`
gen_action('suit', game.where)
},
suit(suit) {
push_undo()
logi(`Favored suit to ${suit}.`)
game.favored = suit
end_action()
},
}
// CARD-BASED ACTION (COMMON)
const card_action_table = {
Tax() {
game.state = 'tax'
},
Gift() {
game.selected = select_available_cylinder()
game.state = 'gift'
},
Build() {
game.count = Math.min(3, Math.floor(player.coins / 2))
if (player.events.nation_building)
game.count *= 2
game.selected = select_available_block()
game.reserve = 0
game.state = 'build'
},
Move() {
game.selected = -1
game.state = 'move'
},
Betray() {
pay_action_cost(2, 0)
game.state = 'betray'
},
Battle() {
game.state = 'battle'
game.where = 0
},
}
function do_card_action_1(c, what, reserve) {
push_undo()
game.card = c
game.where = what
if (!active_has_civil_service_reforms() && !game.events.disregard_for_customs) {
let who = player_with_most_spies(c)
if (who >= 0 && who !== game.active) {
logbr()
game.state = 'bribe'
game.count = count_player_cylinders(who, c)
game.reserve = reserve
game.bribe = who
return
}
}
do_card_action_2()
}
const past_what = {
Tax: "Taxed",
Gift: "Gifted",
Build: "Built",
Move: "Moved",
Betray: "Betrayed",
Battle: "Battled",
}
function do_card_action_2() {
let c = game.card
let what = game.where
game.used_cards.push(c)
if (!is_favored_suit(c))
game.actions --
game.count = cards[c].rank
logbr()
log(`${past_what[what]} with #${c}.`)
card_action_table[what]()
}
// CARD-BASED ACTION: TAX
function can_tax_player(active, p, claim) {
let okay = claim
let shelter = 0
let court = game.players[p].court
if (court.length === 0)
return false
for (let i = 0; i < court.length; ++i) {
let c = court[i]
if (!okay && player_rules_region(active, cards[c].region))
okay = true
if (cards[c].suit === Economic)
shelter += cards[c].rank
}
return okay && game.players[p].coins > shelter
}
function do_tax_player(p) {
push_undo()
logi(`Taxed ${player_names[p]} player.`)
game.players[p].coins --
player.coins ++
if (--game.count === 0)
end_action()
}
function active_can_tax() {
for (let row = 0; row < 2; ++row)
for (let col = 0; col < 6; ++col)
if (game.market_coins[row][col] > 0)
return true
let claim = active_has_claim_of_ancient_lineage()
for (let p = 0; p < game.players.length; ++p)
if (p !== game.active && can_tax_player(game.active, p, claim))
return true
return false
}
states.tax = {
prompt() {
if (game.count === 1)
view.prompt = `Tax \u2014 take up to ${game.count} rupee from market cards or players.`
else
view.prompt = `Tax \u2014 take up to ${game.count} rupees from market cards or players.`
for (let row = 0; row < 2; ++row) {
for (let col = 0; col < 6; ++col) {
if (game.market_coins[row][col] > 0)
gen_action('card', game.market_cards[row][col])
}
}
let claim = active_has_claim_of_ancient_lineage()
for (let p = 0; p < game.players.length; ++p) {
if (p !== game.active && can_tax_player(game.active, p, claim)) {
gen_action('player_' + p)
}
}
gen_action('pass')
},
pass() {
push_undo()
end_action()
},
card(c) {
push_undo()
let [row, col] = find_card_in_market(c)
logi(`Taxed market.`)
game.market_coins[row][col] --
player.coins ++
if (--game.count === 0)
end_action()
},
player_0() { do_tax_player(0) },
player_1() { do_tax_player(1) },
player_2() { do_tax_player(2) },
player_3() { do_tax_player(3) },
player_4() { do_tax_player(4) },
}
// CARD-BASED ACTION: GIFT
states.gift = {
prompt() {
if (game.selected < 0) {
view.prompt = `Select cylinder to place as Gift.`
gen_select_cylinder()
} else {
view.prompt = `Place cylinder as Gift.`
gen_place_gift()
}
},
piece(x) {
push_undo()
game.selected = x
},
place_gift(cost) {
push_undo()
logi(`Paid ${cost}.`)
pay_action_cost(cost, 0)
if (cost === 2)
game.pieces[game.selected] = Gift2
else if (cost === 4)
game.pieces[game.selected] = Gift4
else if (cost === 6)
game.pieces[game.selected] = Gift6
game.used_pieces.push(game.selected)
game.selected = -1
end_action()
}
}
// CARD-BASED ACTION: BUILD
states.build = {
prompt() {
view.prompt = `Build up to ${game.count} armies and/or roads.`
gen_action('next')
let must_pay = !player.events.nation_building || (game.count & 1) === 0
if (!must_pay || player.coins >= 2) {
if (game.selected < 0) {
gen_select_block()
} else {
for (let r = first_region; r <= last_region; ++r) {
if (active_rules_region(r)) {
gen_action('space', r)
for (let s of borders[r])
gen_action('space', s)
}
}
}
}
},
piece(x) {
push_undo()
game.selected = x
},
space(s) {
push_undo()
let must_pay = !player.events.nation_building || (game.count & 1) === 0
if (must_pay)
pay_action_cost(2, game.reserve++)
if (s <= last_region)
logi(`${player.loyalty} army to ${region_names[s]}.`)
else
logi(`${player.loyalty} road to ${border_names[s]}.`)
game.pieces[game.selected] = s
game.used_pieces.push(game.selected)
game.selected = -1
--game.count
must_pay = !player.events.nation_building || (game.count & 1) === 0
if (game.count === 0 || (must_pay && player.coins < 2))
end_build_action()
else
game.selected = select_available_block()
},
next() {
push_undo()
end_build_action()
},
}
states.infrastructure = {
prompt() {
view.prompt = `Place an additional block.`
if (game.selected < 0) {
gen_select_block()
} else {
for (let r = first_region; r <= last_region; ++r) {
if (active_rules_region(r)) {
gen_action('space', r)
for (let s of borders[r])
gen_action('space', s)
}
}
}
},
piece(x) {
push_undo()
game.selected = x
},
space(s) {
push_undo()
if (s <= last_region)
logi(`${player.loyalty} army to ${region_names[s]}.`)
else
logi(`${player.loyalty} road to ${border_names[s]}.`)
game.pieces[game.selected] = s
game.used_pieces.push(game.selected)
game.selected = -1
end_action()
},
}
function end_build_action() {
if (active_has_infrastructure()) {
game.state = 'infrastructure'
game.selected = select_available_block()
} else {
end_action()
}
}
// CARD-BASED ACTION: MOVE
function last_court_position() {
let n = 0
for (let p = 0; p < game.players.length; ++p)
n += game.players[p].court.length
return n - 1
}
function court_card_from_position(y) {
let x = 0
for (let p = 0; p < game.players.length; ++p) {
let court = game.players[p].court
if (y < x + court.length)
return court[y - x]
x += court.length
}
return 0
}
function court_position_from_card(c) {
let x = 0
for (let p = 0; p < game.players.length; ++p) {
let court = game.players[p].court
for (let i = 0; i < court.length; ++i) {
if (c === court[i])
return x + i
}
x += court.length
}
return -1
}
function find_border(a, b) {
if (a > b) {
let c = a; a = b; b = c
}
if (a === Persia && b === Transcaspia) return Persia_Transcaspia
if (a === Persia && b === Herat) return Persia_Herat
if (a === Transcaspia && b === Herat) return Transcaspia_Herat
if (a === Transcaspia && b === Kabul) return Transcaspia_Kabul
if (a === Herat && b === Kabul) return Herat_Kabul
if (a === Herat && b === Kandahar) return Herat_Kandahar
if (a === Kabul && b === Kandahar) return Kabul_Kandahar
if (a === Kabul && b === Punjab) return Kabul_Punjab
if (a === Kandahar && b === Punjab) return Kandahar_Punjab
throw new Error(`bad border ${a} ${b}`)
}
function can_army_move_across_border(here, next) {
let border = find_border(here, next)
let b = active_coalition_blocks()
for (let i = b; i < b + 12; ++i)
if (game.pieces[i] === border)
return true
return false
}
function active_can_move_from_region(here) {
let supplies = active_has_indian_supplies()
for (let next of roads[here])
if (supplies || can_army_move_across_border(here, next))
return true
return false
}
function active_can_move() {
let b = active_coalition_blocks()
let x = active_cylinders()
for (let i = b; i < b + 12; ++i) {
let r = game.pieces[i]
if (r >= first_region && r <= last_region)
if (active_can_move_from_region(r))
return true
}
for (let i = x; i < x + 10; ++i) {
let r = game.pieces[i]
if (r > 0 && r <= 100)
return true
}
if (player.events.nationalism) {
for (let i = x; i < x + 10; ++i) {
let r = game.pieces[i]
if (r >= first_region && r <= last_region)
if (active_can_move_from_region(r))
return true
}
}
return false
}
states.move = {
prompt() {
if (game.selected >= 0) {
let here = game.pieces[game.selected]
// Spy on a court card
if (here <= 100) {
let c = here
here = court_position_from_card(here)
view.prompt = `Move spy from #${c}.`
let last = last_court_position()
let prev = here > 0 ? here - 1 : last
let next = here < last ? here + 1 : 0
gen_action('card', court_card_from_position(prev))
gen_action('card', court_card_from_position(next))
if (active_has_well_connected()) {
let pprev = prev > 0 ? prev - 1 : last
let nnext = next < last ? next + 1 : 0
gen_action('card', court_card_from_position(pprev))
gen_action('card', court_card_from_position(nnext))
}
if (active_has_strange_bedfellows()) {
let r = cards[c].region
for (let p = 0; p < game.players.length; ++p) {
let court = game.players[p].court
for (let i = 0; i < court.length; ++i)
if (cards[court[i]].region === r)
gen_action('card', court[i])
}
}
}
// Army or tribe in a region
else {
if (game.selected < 36)
view.prompt = `Move ${player.loyalty} army from ${region_names[here]}.`
else
view.prompt = `Move ${player_names[game.active]} tribe from ${region_names[here]}.`
let supplies = active_has_indian_supplies()
for (let next of roads[here])
if (supplies || can_army_move_across_border(here, next))
gen_action('space', next)
}
} else {
if (player.events.nationalism) {
if (game.count === 1)
view.prompt = `Move up to ${game.count} spy, army, or tribe \u2014 select a spy, army, or tribe to move.`
else
view.prompt = `Move up to ${game.count} spies, armies, and/or tribes \u2014 select a spy, army, or tribe to move.`
} else {
if (game.count === 1)
view.prompt = `Move up to ${game.count} spy or army \u2014 select a spy or army to move.`
else
view.prompt = `Move up to ${game.count} spies and/or armies \u2014 select a spy or army to move.`
}
gen_action('next')
gen_select_army_to_move()
gen_select_spy_to_move()
if (player.events.nationalism)
gen_select_tribe_to_move()
}
},
piece(x) {
push_undo()
game.selected = x
},
card(c) {
push_undo()
let old = game.pieces[game.selected]
let pold = find_card_in_court(old)
let p = find_card_in_court(c)
if (pold !== p)
logi(`Spy from #${old} in ${player_names[pold]} court to #${c} in ${player_names[p]} court.`)
else
logi(`Spy from #${old} to #${c} in ${player_names[p]} court.`)
game.pieces[game.selected] = c
game.selected = -1
if (--game.count === 0)
end_action()
},
space(s) {
push_undo()
let old = game.pieces[game.selected]
game.pieces[game.selected] = s
if (game.selected < 36) {
logi(`${player.loyalty} army from ${region_names[old]} to ${region_names[s]}.`)
} else {
logi(`Tribe from ${region_names[old]} to ${region_names[s]}.`)
check_region_overthrow(game.active, old)
}
game.selected = -1
if (--game.count === 0)
end_action()
},
next() {
push_undo()
end_action()
},
}
// CARD-BASED ACTION: BETRAY
states.betray = {
prompt() {
view.prompt = `Discard one court card where you have a spy.`
let x = active_cylinders()
for (let i = x; i < x + 10; ++i) {
if (game.pieces[i] > 0 && game.pieces[i] <= 100) {
let c = game.pieces[i]
if (cards[c].suit !== Political) {
gen_action('card', c)
} else {
let p = find_card_in_court(c)
if (!player_has_bodyguards(p))
gen_action('card', c)
}
}
}
},
card(c) {
push_undo()
discard_court_card(c)
if (cards[c].prize) {
game.card = c
game.state = 'accept_prize'
} else {
end_action()
}
},
}
states.accept_prize = {
inactive: "accept prize",
prompt() {
view.prompt = `You may accept #${game.card} as ${a_coalition(cards[game.card].prize)} prize.`
gen_action('accept')
gen_action('refuse')
},
accept() {
log(`Accepted ${cards[game.card].prize} prize.`)
if (cards[game.card].prize !== player.loyalty)
change_loyalty(cards[game.card].prize)
player.prizes ++
end_action()
},
refuse() {
end_action()
},
}
// CARD-BASED ACTION: BATTLE
function gen_battle_blocks(where) {
if (player.loyalty !== Afghan)
for (let i = 0; i < 12; ++i)
if (game.pieces[i] === where)
gen_action('piece', i)
if (player.loyalty !== British)
for (let i = 12; i < 24; ++i)
if (game.pieces[i] === where)
gen_action('piece', i)
if (player.loyalty !== Russian)
for (let i = 24; i < 36; ++i)
if (game.pieces[i] === where)
gen_action('piece', i)
}
function count_active_spies_on_card(where) {
let n = 0
let x = active_cylinders()
for (let i = x; i < x + 10; ++i)
if (game.pieces[i] === where)
++n
return n
}
function count_enemy_spies_on_card(where) {
let n = 0
for (let p = 0; p < game.players.length; ++p) {
if (p === game.active)
continue
if (player_has_indispensable_advisors(p))
continue
let x = player_cylinders(p)
for (let i = x; i < x + 10; ++i) {
if (game.pieces[i] === where)
++n
}
}
return n
}
function count_player_armies_in_region(p, where) {
let n = 0
let b = player_coalition_blocks(p)
for (let i = b; i < b + 12; ++i)
if (game.pieces[i] === where)
++n
return n
}
function count_player_cylinders(p, r) {
let x = player_cylinders(p)
let n = 0
for (let i = x; i < x + 10; ++i)
if (game.pieces[i] === r)
++n
return n
}
function count_active_armies_in_region(where) {
let n = count_player_armies_in_region(game.active, where)
if (player.events.nationalism)
n += count_player_cylinders(game.active, where)
return n
}
function count_enemy_blocks_on_border(where) {
let n = 0
if (player.loyalty !== Afghan)
for (let i = 0; i < 12; ++i)
if (game.pieces[i] === where)
++n
if (player.loyalty !== British)
for (let i = 12; i < 24; ++i)
if (game.pieces[i] === where)
++n
if (player.loyalty !== Russian)
for (let i = 24; i < 36; ++i)
if (game.pieces[i] === where)
++n
return n
}
function count_enemy_tribes_and_blocks_in_region(where) {
let n = 0
for (let p = 0; p < game.players.length; ++p) {
if (game.players[p].loyalty === player.loyalty)
continue
if (player_has_citadel(p, where))
continue
let x = player_cylinders(p)
for (let i = x; i < x + 10; ++i)
if (game.pieces[i] === where)
++n
}
if (player.loyalty !== Afghan)
for (let i = 0; i < 12; ++i)
if (game.pieces[i] === where)
++n
if (player.loyalty !== British)
for (let i = 12; i < 24; ++i)
if (game.pieces[i] === where)
++n
if (player.loyalty !== Russian)
for (let i = 24; i < 36; ++i)
if (game.pieces[i] === where)
++n
for (let b of borders[where])
n += count_enemy_blocks_on_border(b)
return n
}
function is_battle_card(where) {
return count_active_spies_on_card(where) > 0 && count_enemy_spies_on_card(where) > 0
}
function is_battle_region(where) {
return count_active_armies_in_region(where) > 0 && count_enemy_tribes_and_blocks_in_region(where) > 0
}
function piece_owner(x) {
if (x < 12) return "Afghan"
if (x < 24) return "British"
if (x < 36) return "Russian"
if (x < 36+10) return player_names[0]
if (x < 36+20) return player_names[1]
if (x < 36+30) return player_names[2]
if (x < 36+40) return player_names[3]
if (x < 36+50) return player_names[4]
return "undefined"
}
function active_can_battle() {
for (let r = first_region; r <= last_region; ++r) {
if (is_battle_region(r))
return true
}
for (let p = 0; p < game.players.length; ++p) {
let court = game.players[p].court
for (let i = 0; i < court.length; ++i)
if (is_battle_card(court[i]))
return true
}
return false
}
function is_safe_house_in_play() {
for (let x = 36; x < game.pieces.length; ++x)
if (game.pieces[x] === Safe_House)
return true
return false
}
states.battle = {
prompt() {
if (game.where <= 0) {
view.prompt = `Start a battle in a single region or on a court card.`
for (let p = 0; p < game.players.length; ++p) {
let court = game.players[p].court
for (let i = 0; i < court.length; ++i) {
if (is_battle_card(court[i]))
gen_action('card', court[i])
}
}
for (let r = first_region; r <= last_region; ++r) {
if (is_battle_region(r))
gen_action('space', r)
}
} else {
let where = game.where
if (where >= first_region && where <= last_region) {
view.prompt = `Remove up to ${game.count} tribes, roads, or armies from ${region_names[where]}.`
gen_battle_blocks(where)
for (let border of borders[where])
gen_battle_blocks(border)
for (let p = 0; p < game.players.length; ++p) {
if (p !== game.active && game.players[p].loyalty !== player.loyalty && !player_has_citadel(p, where)) {
let x = player_cylinders(p)
for (let i = x; i < x + 10; ++i)
if (game.pieces[i] === where)
gen_action('piece', i)
}
}
} else {
if (game.count > 0) {
view.prompt = `Remove up to ${game.count} spies on #${where}.`
for (let p = 0; p < game.players.length; ++p) {
if (p !== game.active && !player_has_indispensable_advisors(p)) {
let x = player_cylinders(p)
for (let i = x; i < x + 10; ++i)
if (game.pieces[i] === where)
gen_action('piece', i)
}
}
} else {
view.prompt = `Battle on #${game.where} is over \u2014 undo will not be possible.`
}
}
gen_action('next')
}
},
card(where) {
push_undo()
//logi(`Battle on #${where}.`)
game.where = where
game.count = Math.min(game.count, count_active_spies_on_card(where))
},
space(s) {
push_undo()
//logi(`Battle in ${region_names[s]}.`)
game.where = s
game.count = Math.min(game.count, count_active_armies_in_region(s))
},
piece(x) {
push_undo()
let where = game.pieces[x]
game.pieces[x] = 0
if (x < 36) {
if (where >= first_region && where <= last_region)
logi(`Removed ${piece_owner(x)} army from ${region_names[where]}.`)
else
logi(`Removed ${piece_owner(x)} road from ${border_names[where]}.`)
} else {
let p = Math.floor((x - 36) / 10)
if (where <= 100) {
let pp = find_card_in_court(where)
logi(`Removed ${piece_owner(x)} spy from #${where} in ${player_names[pp]} court.`)
if (player_has_safe_house(p))
game.pieces[x] = Safe_House
} else {
logi(`Removed ${piece_owner(x)} tribe from ${region_names[where]}.`)
check_region_overthrow(p, where)
}
}
if (--game.count === 0 && !is_safe_house_in_play())
end_action()
},
next() {
push_undo()
end_action()
}
}
// PASSIVE: BLACKMAIL
function active_can_blackmail(r) {
if ((r === Herat && active_has_blackmail_herat()) || (r === Kandahar && active_has_blackmail_kandahar())) {
for (let p = 0; p < game.players.length; ++p) {
let court = game.players[p].court
for (let i = 0; i < court.length; ++i) {
let c = court[i]
if (cards[c].region === r && card_has_no_spies(c))
return true
}
}
}
return false
}
states.blackmail = {
prompt() {
let bmh = game.where !== Kandahar && active_can_blackmail(Herat)
let bmk = game.where !== Herat && active_can_blackmail(Kandahar)
let msg = ""
if (bmh && bmk)
msg = "any Herat and/or Kandahar court card without a spy"
else if (bmh)
msg = "any Herat court card without a spy"
else
msg = "any Kandahar court card without a spy"
if (game.selected < 0) {
view.prompt = `Blackmail \u2014 select a spy to place on ${msg}.`
gen_select_cylinder()
} else {
let bmh = game.where !== Kandahar && active_can_blackmail(Herat)
let bmk = game.where !== Herat && active_can_blackmail(Kandahar)
view.prompt = `Blackmail \u2014 place a spy on ${msg}.`
for (let p = 0; p < game.players.length; ++p) {
let court = game.players[p].court
for (let i = 0; i < court.length; ++i) {
let c = court[i]
if (bmh && cards[c].region === Herat && card_has_no_spies(c))
gen_action('card', c)
if (bmk && cards[c].region === Kandahar && card_has_no_spies(c))
gen_action('card', c)
}
}
}
gen_action('pass')
},
piece(x) {
push_undo()
game.selected = x
},
card(c) {
push_undo()
log(`Blackmail spy to #${c}.`)
game.pieces[game.selected] = c
game.used_pieces.push(game.selected)
if (game.where < 0) {
game.where = (cards[c].region === Herat) ? Kandahar : Herat
game.selected = select_available_cylinder()
} else {
resume_actions()
}
},
pass() {
push_undo()
resume_actions()
},
}
// PASSIVE: SAFEHOUSE
function check_safe_house() {
let first = game.phasing
for (let p = first; p < game.players.length; ++p)
if (check_player_safe_house(p))
return
for (let p = 0; p < first; ++p)
if (check_player_safe_house(p))
return
if (game.actions >= 0)
resume_actions()
else if (game.where === 'riot')
goto_discard_events()
else
goto_cleanup_hand()
}
function check_player_safe_house(p) {
let x = player_cylinders(p)
for (let i = x; i < x + 10; ++i) {
if (game.pieces[i] === Safe_House) {
if (player_has_safe_house(p)) {
set_active(p)
logbr()
game.state = 'safe_house'
game.selected = i
return true
} else {
game.pieces[i] = 0
}
}
}
return false
}
states.safe_house = {
inactive: "safe house",
prompt() {
view.prompt = `Safe House \u2014 you may place your killed spy on a Safe House.`
if (player.court.indexOf(SAFE_HOUSE_1) >= 0)
gen_action('card', SAFE_HOUSE_1)
if (player.court.indexOf(SAFE_HOUSE_2) >= 0)
gen_action('card', SAFE_HOUSE_2)
gen_action('pass')
},
card(c) {
push_undo()
log(`${player_names[game.active]} spy to #${c}.`)
game.pieces[game.selected] = c
game.selected = -1
check_safe_house()
},
pass() {
push_undo()
game.pieces[game.selected] = 0
game.selected = -1
check_safe_house()
},
}
// PASSIVE: INSURRECTION
function count_available_afghan_blocks() {
let n = 0
for (let i = 0; i < 12; ++i)
if (game.pieces[i] === 0)
n ++
return n
}
function check_insurrection() {
let prince = which_player_has_insurrection()
if (prince >= 0) {
logbr()
log(`Prince Akbar Khan`)
game.count = 2
game.selected = select_afghan_block()
if (prince === game.active || count_available_afghan_blocks() >= 2)
game.state = 'insurrection'
else
game.state = 'insurrection_pause'
} else {
end_dominance_check()
}
}
states.insurrection_pause = {
prompt() {
let prince = which_player_has_insurrection()
view.prompt = `Insurrection \u2014 pass control to ${player_names[prince]}.`
gen_action('player_' + prince)
},
player_0() { set_active(0); game.state = "insurrection" },
player_1() { set_active(1); game.state = "insurrection" },
player_2() { set_active(2); game.state = "insurrection" },
player_3() { set_active(3); game.state = "insurrection" },
player_4() { set_active(4); game.state = "insurrection" },
}
states.insurrection = {
prompt() {
if (game.count > 0) {
if (game.selected < 0) {
view.prompt = `Insurrection \u2014 select an Afghan block to move.`
gen_select_block()
} else {
view.prompt = `Insurrection \u2014 place Afghan army in Kabul.`
gen_action('space', Kabul)
}
} else {
view.prompt = `Insurrection \u2014 done.`
gen_action('next')
}
},
piece(x) {
push_undo()
game.selected = x
},
space() {
push_undo()
logi(`Afghan army to Kabul.`)
game.pieces[game.selected] = Kabul
game.selected = -1
if (--game.count > 0)
game.selected = select_afghan_block()
},
next() {
push_undo()
end_dominance_check()
}
}
// CLEANUP
function player_court_size() {
let stars = 3
for (let i = 0; i < player.court.length; ++i) {
let c = player.court[i]
if (cards[c].suit === Political)
stars += cards[c].rank
}
return stars
}
function player_hand_size() {
let stars = 2
for (let i = 0; i < player.court.length; ++i) {
let c = player.court[i]
if (cards[c].suit === Intelligence)
stars += cards[c].rank
}
return stars
}
function goto_cleanup_court() {
game.actions = -1
logbr()
if (player.court.length > player_court_size()) {
game.state = 'cleanup_court'
} else {
goto_cleanup_hand()
}
}
states.cleanup_court = {
inactive: "cleanup court",
prompt() {
let size = player_court_size()
if (player.court.length <= size) {
view.prompt = `Discard cards in your court until you are within your limit \u2014 done.`
gen_action('next')
} else {
view.prompt = `Discard cards in your court until you are within your limit (${size}).`
for (let i = 0; i < player.court.length; ++i)
gen_action('card', player.court[i])
}
},
card(c) {
push_undo()
discard_court_card(c)
},
next() {
push_undo()
check_leverage()
}
}
function goto_cleanup_hand() {
if (player.hand.length > player_hand_size()) {
game.state = 'cleanup_hand'
} else {
goto_discard_events()
}
}
states.cleanup_hand = {
inactive: "cleanup hand",
prompt() {
let size = player_hand_size()
if (player.hand.length <= size) {
view.prompt = `Discard cards in your hand until you are within your limit \u2014 done.`
gen_action('next')
} else {
view.prompt = `Discard cards in your hand until you are within your limit (${size}).`
for (let i = 0; i < player.hand.length; ++i)
gen_action('card', player.hand[i])
}
},
card(c) {
push_undo()
log(`Discarded #${c} from hand.`)
remove_from_array(player.hand, c)
},
next() {
push_undo()
goto_discard_events()
}
}
function goto_discard_events() {
if (is_event_card(game.market_cards[0][0]) || is_event_card(game.market_cards[1][0])) {
game.state = 'discard_events'
} else {
goto_refill_market()
}
}
function do_discard_event(row, c) {
game.market_cards[row][0] = 0
logbr()
log(`Discarded #${c}.`)
if (is_dominance_check(c)) {
do_dominance_check('discard')
} else {
events_if_discarded[cards[c].if_discarded](row)
}
}
states.discard_events = {
inactive: "discard event cards",
prompt() {
view.prompt = `Discard any event cards in the leftmost column of the market.`
if (is_event_card(game.market_cards[0][0]))
gen_action('card', game.market_cards[0][0])
else if (is_event_card(game.market_cards[1][0]))
gen_action('card', game.market_cards[1][0])
},
card(c) {
push_undo()
if (c === game.market_cards[0][0])
do_discard_event(0, c)
else
do_discard_event(1, c)
},
}
function discard_instability_cards() {
for (let row = 0; row < 2; ++row) {
for (let col = 0; col < 6; ++col) {
let c = game.market_cards[row][col]
if (is_dominance_check(c))
game.market_cards[row][col] = 0
}
}
}
function goto_refill_market() {
// Move all cards (and their rupees) to the left.
for (let row = 0; row < 2; ++row) {
let row_cards = game.market_cards[row]
let row_coins = game.market_coins[row]
for (let to = 0; to < 6; ++to) {
if (row_cards[to] === 0) {
for (let from = to + 1; from < 6; ++from) {
if (row_cards[from] > 0) {
row_cards[to] = row_cards[from]
row_cards[from] = 0
row_coins[to] += row_coins[from]
row_coins[from] = 0
break
}
}
}
}
}
// Instability ...
let instability = 0
for (let row = 0; row < 2; ++row) {
for (let col = 0; col < 6; ++col) {
let c = game.market_cards[row][col]
if (is_dominance_check(c))
++instability
}
}
clear_undo()
// Fill with new cards from left (top row in each column first)
for (let col = 0; col < 6; ++col) {
for (let row = 0; row < 2; ++row) {
if (game.deck.length > 0) {
if (game.market_cards[row][col] === 0) {
let c = game.deck.pop()
game.market_cards[row][col] = c
if (is_dominance_check(c)) {
if (++instability > 1) {
game.state = 'instability'
return
}
}
}
}
}
}
goto_next_player()
}
states.instability = {
prompt() {
view.prompt = "Instability \u2014 perform a Dominance Check immediately."
for (let row = 0; row < 2; ++row) {
for (let col = 0; col < 6; ++col) {
let c = game.market_cards[row][col]
if (is_dominance_check(c))
gen_action('card', c)
}
}
},
card() {
logbr()
log(`Instability!`)
discard_instability_cards()
do_dominance_check('instability')
}
}
// EVENTS: IF DISCARDED
const events_if_discarded = {
"Military" () {
goto_favored_suit_event(Military)
},
"Embarrassment of Riches" () {
game.events.embarrassment_of_riches = 1
goto_discard_events()
},
"Disregard for Customs" () {
game.events.disregard_for_customs = 1
goto_discard_events()
},
"Failure to Impress" () {
logi("Discarded all loyalty prizes.")
for (let p = 0; p < game.players.length; ++p)
game.players[p].prizes = 0
goto_discard_events()
},
"Riots in Punjab" () {
goto_riots(Punjab)
},
"Riots in Herat" () {
goto_riots(Herat)
},
"No effect" () {
logi("No effect.")
goto_discard_events()
},
"Riots in Kabul" () {
goto_riots(Kabul)
},
"Riots in Persia" () {
goto_riots(Persia)
},
"Confidence Failure" () {
game.state = 'confidence_failure'
if (player.hand.length === 0)
next_confidence_failure()
},
"Intelligence" () {
goto_favored_suit_event(Intelligence)
},
"Political" () {
goto_favored_suit_event(Political)
},
}
function goto_favored_suit_event(suit) {
if (!game.events.pashtunwali_values) {
game.state = 'favored_suit'
game.where = suit
} else {
goto_discard_events()
}
}
states.favored_suit = {
inactive: "favored suit",
prompt() {
view.prompt = `Change the favored suit to ${game.where}.`
gen_action('suit', game.where)
},
suit(suit) {
logi(`Favored suit to ${suit}.`)
game.favored = suit
goto_discard_events()
},
}
function goto_riots(where) {
game.state = 'riots'
game.where = where
}
states.riots = {
prompt() {
view.prompt = `Riot in ${region_names[game.where]}.`
gen_action('space', game.where)
},
space(s) {
remove_all_tribes_and_armies(s)
game.where = 'riot'
check_leverage()
},
}
states.confidence_failure = {
inactive: "confidence failure",
prompt() {
view.prompt = "Confidence Failure \u2014 discard a card from your hand."
for (let i = 0; i < player.hand.length; ++i)
gen_action('card', player.hand[i])
},
card(c) {
log(`${player_names[game.active]} discarded #${c} from hand.`)
remove_from_array(player.hand, c)
next_confidence_failure()
},
}
function next_confidence_failure() {
let next = game.active
for (let i = 0; i < 10; ++i) {
next = next_player(next)
if (next === game.phasing)
return goto_discard_events()
if (game.players[next].hand.length > 0)
return set_active(next)
}
throw new Error("FAIL")
}
// EVENTS: IF PURCHASED
const events_if_purchased = {
"New Tactics" () {
player.events.new_tactics = 1
end_action()
},
"Koh-i-noor Recovered" () {
player.events.koh_i_noor = 1
end_action()
},
"Courtly Manners" () {
player.events.courtly_manners = 1
end_action()
},
"Rumor" () {
game.state = 'rumor'
},
"Conflict Fatigue" () {
game.events.conflict_fatigue = 1
end_action()
},
"Nationalism" () {
player.events.nationalism = 1
end_action()
},
"Public Withdrawal" () {
throw new Error("cannot purchase")
},
"Nation Building" () {
player.events.nation_building = 1
end_action()
},
"Backing of Persian Aristocracy" () {
player.coins += 3
end_action()
},
"Other Persuasive Methods" () {
game.state = 'other_persuasive_methods'
},
"Pashtunwali Values" () {
game.state = 'pashtunwali_values'
},
"Rebuke" () {
game.state = 'rebuke'
},
}
function check_public_withdrawal() {
// Remove any money placed on card "Public Withdrawal" from the game.
for (let row = 0; row < 2; ++row)
for (let col = 0; col < 6; ++col)
if (game.market_cards[row][col] === PUBLIC_WITHDRAWAL)
game.market_coins[row][col] = 0
}
states.rumor = {
prompt() {
view.prompt = `Rumor \u2014 choose a player.`
for (let p = 0; p < game.players.length; ++p)
if (p !== game.active)
gen_action('player_' + p)
},
player_0() { do_rumor(0) },
player_1() { do_rumor(1) },
player_2() { do_rumor(2) },
player_3() { do_rumor(3) },
player_4() { do_rumor(4) },
}
function do_rumor(p) {
push_undo()
log(`${player_names[game.active]} chose ${player_names[p]} for Rumor.`)
game.players[p].events.rumor = 1
end_action()
}
states.other_persuasive_methods = {
inactive: "other persuasive methods",
prompt() {
view.prompt = `Other Persuasive Methods \u2014 exchange your hand with another player.`
for (let p = 0; p < game.players.length; ++p)
if (p !== game.active)
gen_action('player_' + p)
},
player_0() { do_other_persuasive_methods(0) },
player_1() { do_other_persuasive_methods(1) },
player_2() { do_other_persuasive_methods(2) },
player_3() { do_other_persuasive_methods(3) },
player_4() { do_other_persuasive_methods(4) },
}
function do_other_persuasive_methods(p) {
if (game.open)
push_undo()
else
clear_undo() // No undo if closed hands.
log(`${player_names[game.active]} exchanged hands with ${player_names[p]}.`)
let swap = game.players[game.active].hand
game.players[game.active].hand = game.players[p].hand
game.players[p].hand = swap
end_action()
}
states.pashtunwali_values = {
inactive: "Pastunwali values",
prompt() {
view.prompt = `Pashtunwali Values \u2014 choose a suit to favor.`
gen_action('suit', Political)
gen_action('suit', Intelligence)
gen_action('suit', Economic)
gen_action('suit', Military)
},
suit(suit) {
log(`Favored suit to ${suit}.`)
game.favored = suit
game.events.pashtunwali_values = 1
end_action()
},
}
states.rebuke = {
prompt() {
view.prompt = `Rebuke \u2014 remove all tribes and armies in a single region.`
for (let s = first_region; s <= last_region; ++s)
// TODO: can pick empty region?
gen_action('space', s)
},
space(s) {
push_undo()
remove_all_tribes_and_armies(s)
end_action()
},
}
// DOMINANCE CHECK
function count_cylinders_in_play(p) {
let n = 0
let x = player_cylinders(p)
for (let i = x; i < x + 10; ++i)
if (game.pieces[i] > 0)
++n
return n
}
function count_influence_points(p) {
let n = 1 + game.players[p].prizes
let x = player_cylinders(p)
if (!game.events.embarrassment_of_riches) {
let gv = game.players[p].events.koh_i_noor ? 2 : 1
for (let i = x; i < x + 10; ++i) {
let s = game.pieces[i]
if (s === Gift2 || s === Gift4 || s === Gift6)
n += gv
}
}
if (!game.players[p].events.rumor) {
let court = game.players[p].court
for (let i = 0; i < court.length; ++i)
if (cards[court[i]].patriot)
++n
}
return n
}
function assign_vp(points, score, sorted) {
const PLACE = [ "1st", "2nd", "3rd" ]
let place = 0
sorted.sort((a,b) => b-a)
while (points.length > 0 && sorted.length > 0) {
let n = 0
for (let p = 0; p < game.players.length; ++p)
if (score[p] === sorted[0])
++n
let v = 0
for (let i = 0; i < n; ++i)
v += points[i] | 0
v = Math.floor(v / n)
let msg = `${PLACE[place]} place:`
for (let p = 0; p < game.players.length; ++p) {
if (score[p] === sorted[0]) {
msg += "\n" + player_names[p] + " scored " + v + " vp."
game.players[p].vp += v
}
}
log(msg)
points = points.slice(n)
sorted = sorted.slice(n)
place += n
}
}
function count_dominance_cards() {
let n = 0
for (let row = 0; row < 2; ++row)
for (let col = 0; col < 6; ++col)
if (is_dominance_check(game.market_cards[row][col]))
++n
for (let i = 0; i < game.deck.length; ++i)
if (is_dominance_check(game.deck[i]))
++n
return n
}
function is_final_dominance_check() {
for (let row = 0; row < 2; ++row)
for (let col = 0; col < 6; ++col)
if (is_dominance_check(game.market_cards[row][col]))
return false
for (let i = 0; i < game.deck.length; ++i)
if (is_dominance_check(game.deck[i]))
return false
return true
}
function rank_score(a, b) {
return parseInt(b) - parseInt(a)
}
function do_dominance_check(reason) {
let n_afghan = 0
let n_british = 0
let n_russian = 0
let success = null
for (let i = 0; i < 12; ++i) {
if (game.pieces[i] > 0)
n_afghan ++
if (game.pieces[i+12] > 0)
n_british ++
if (game.pieces[i+24] > 0)
n_russian ++
}
logi(n_afghan + " Afghan block" + (n_afghan !== 1 ? "s," : ","))
logi(n_british + " British block" + (n_british !== 1 ? "s," : ","))
logi(n_russian + " Russian block" + (n_russian !== 1 ? "s." : "."))
let limit = game.events.conflict_fatigue ? 2 : 4
if (n_afghan >= n_british+limit && n_afghan >= n_russian+limit)
success = Afghan
else if (n_british >= n_afghan+limit && n_british >= n_russian+limit)
success = British
else if (n_russian >= n_british+limit && n_russian >= n_afghan+limit)
success = Russian
let final = is_final_dominance_check()
let score = new Array(game.players.length).fill(0)
if (success) {
logbr()
log(`.dc.${success} Dominant ${success} Coalition`)
logbr()
if (final)
log(`Final Dominance Check.`)
let list = []
for (let p = 0; p < game.players.length; ++p) {
if (game.players[p].loyalty === success) {
score[p] = count_influence_points(p)
list.push(`${score[p]} ${player_names[p]} influence`)
}
}
list.sort(rank_score)
log("Ranking:\n" + list.join(",\n") + ".")
if (final)
assign_vp([10, 6, 2], score, score.filter(x=>x>0))
else
assign_vp([5, 3, 1], score, score.filter(x=>x>0))
} else {
logbr()
log(`.dc.unsuccessful Unsuccessful Check`)
logbr()
if (final)
log(`Final Dominance Check.`)
let list = []
for (let p = 0; p < game.players.length; ++p) {
score[p] = count_cylinders_in_play(p)
if (score[p] !== 1)
list.push(`${score[p]} ${player_names[p]} cylinders`)
else
list.push(`${score[p]} ${player_names[p]} cylinder`)
}
list.sort(rank_score)
log("Ranking:\n" + list.join(",\n") + ".")
if (final)
assign_vp([6, 2], score, score.slice())
else
assign_vp([3, 1], score, score.slice())
}
// Check instant victory
let vps = game.players.map(pp => pp.vp).sort((a,b)=>b-a)
if (vps[0] >= vps[1] + 4)
return goto_pause_game_over()
if (final)
return goto_pause_game_over()
// Clear the board.
if (success) {
for (let i = 0; i < 36; ++i)
game.pieces[i] = 0
}
game.events = {}
for (let p = 0; p < game.players.length; ++p)
game.players[p].events = {}
game.where = reason
check_insurrection()
}
function end_dominance_check() {
set_active(game.phasing)
if (game.state === 'game_over')
return
switch (game.where) {
case 'discard':
return goto_discard_events()
case 'purchase':
return resume_actions()
case 'instability':
return goto_refill_market()
}
}
function vp_tie(pp) {
let court = pp.court
let stars = 0
for (let i = 0; i < court.length; ++i) {
let c = court[i]
if (cards[c].suit === Military)
stars += cards[c].rank
}
return pp.vp * 10000 + stars * 100 + pp.coins
}
function compute_victory() {
let vps = game.players.map((pp,i) => [vp_tie(pp),i]).sort((a,b)=>b[0]-a[0])
let is_winner = false
let result = []
for (let i = 0; i < vps.length; ++i) {
if (vps[i][0] === vps[0][0]) {
result.push(player_names[vps[i][1]])
if (vps[i][1] === game.active)
is_winner = true
}
}
game.result = result.join(", ")
game.victory = result.join(" and ") + " won!"
logbr()
log(game.victory)
return is_winner
}
function goto_pause_game_over() {
let is_winner = compute_victory()
if (game.undo && game.undo.length > 0 && !is_winner) {
game.state = 'pause_game_over'
} else {
game.state = 'game_over'
game.active = 5
}
}
states.pause_game_over = {
inactive: "game over",
prompt() {
view.prompt = game.victory
gen_action('end_game')
},
end_game() {
game.state = 'game_over'
game.active = 5
}
}
// SETUP
function prepare_deck() {
let court_cards = []
for (let i = 1; i <= 100; ++i)
court_cards.push(i)
let event_cards = []
for (let i = 105; i <= 116; ++i)
event_cards.push(i)
let piles = [ [], [], [], [], [], [] ]
shuffle(court_cards)
for (let i = 0; i < 6; ++i)
for (let k = 0; k < 5 + game.players.length; ++k)
piles[i].push(court_cards.pop())
// Leftmost pile is 5, rightmost pile is 0
piles[3].push(101)
piles[2].push(102)
piles[1].push(103)
piles[0].push(104)
shuffle(event_cards)
piles[4].push(event_cards.pop())
piles[4].push(event_cards.pop())
piles[3].push(event_cards.pop())
piles[2].push(event_cards.pop())
piles[1].push(event_cards.pop())
piles[0].push(event_cards.pop())
for (let i = 0; i < 6; ++i)
shuffle(piles[i])
game.deck = piles.flat()
}
exports.setup = function (seed, scenario, options) {
let player_count = scenario_player_count[scenario]
game = {
seed: seed,
log: [],
undo: [],
open: options.open_hands ? 1 : 0,
active: 0,
state: "none",
used_cards: [],
used_pieces: [],
count: 0,
reserve: 0,
bribe: -1,
selected: -1,
region: 0,
card: 0,
where: 0,
phasing: null,
actions: 0,
deck: [],
favored: Political,
events: {},
pieces: new Array(36 + player_count * 10).fill(0),
market_cards: [
[0,0,0,0,0,0],
[0,0,0,0,0,0],
],
market_coins: [
[0,0,0,0,0,0],
[0,0,0,0,0,0],
],
players: [],
}
for (let i = 0; i < player_count; ++i) {
game.players[i] = {
vp: 0,
loyalty: null,
prizes: 0,
coins: 4,
hand: [],
court: [],
events: {},
}
}
// Old RNG for ancient replays
if (options.rng)
game.rng = options.rng
prepare_deck()
for (let col = 0; col < 6; ++col)
for (let row = 0; row < 2; ++row)
game.market_cards[row][col] = game.deck.pop()
// Starting loyalty, starting with a random player.
game.state = 'loyalty'
game.active = random(player_count)
return save_game()
}
function load_game(state) {
game = state
game.active = player_index[game.active]
update_aliases()
}
function save_game() {
game.active = player_names[game.active]
return game
}
exports.action = function (state, current, action, arg) {
load_game(state)
let S = states[game.state]
if (action in S) {
S[action](arg)
} else {
if (action === 'undo' && game.undo && game.undo.length > 0)
pop_undo()
else
throw new Error("Invalid action: " + action)
}
return save_game()
}
exports.view = function (state, current) {
current = player_index[current]
load_game(state)
view = {
log: game.log,
active: player_names[game.active],
prompt: null,
favored: game.favored,
events: game.events,
pieces: game.pieces,
market_cards: game.market_cards,
market_coins: game.market_coins,
players: game.players,
selected: game.selected,
cards: [ game.deck.length, count_dominance_cards() ],
open: game.open,
}
if (game.state === 'game_over') {
view.prompt = game.victory
} else if (current === 'Observer' || game.active !== current) {
let inactive = states[game.state].inactive || game.state
view.prompt = `Waiting for ${player_names[game.active]} \u2014 ${inactive}...`
} else {
view.actions = {}
states[game.state].prompt()
view.prompt = player_names[game.active] + ": " + view.prompt
if (game.undo && game.undo.length > 0)
view.actions.undo = 1
else
view.actions.undo = 0
}
save_game()
return view
}
|