powergrid-engine 1.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +31 -0
  3. package/dist/index.d.ts +6 -0
  4. package/dist/index.js +17 -0
  5. package/dist/src/available-moves.d.ts +24 -0
  6. package/dist/src/available-moves.js +363 -0
  7. package/dist/src/engine.d.ts +20 -0
  8. package/dist/src/engine.js +1937 -0
  9. package/dist/src/gamestate.d.ts +135 -0
  10. package/dist/src/gamestate.js +30 -0
  11. package/dist/src/log.d.ts +14 -0
  12. package/dist/src/log.js +2 -0
  13. package/dist/src/maps/america.d.ts +55 -0
  14. package/dist/src/maps/america.js +411 -0
  15. package/dist/src/maps/australia.d.ts +46 -0
  16. package/dist/src/maps/australia.js +138 -0
  17. package/dist/src/maps/badenwurttemberg.d.ts +46 -0
  18. package/dist/src/maps/badenwurttemberg.js +163 -0
  19. package/dist/src/maps/benelux.d.ts +46 -0
  20. package/dist/src/maps/benelux.js +210 -0
  21. package/dist/src/maps/brazil.d.ts +54 -0
  22. package/dist/src/maps/brazil.js +292 -0
  23. package/dist/src/maps/centraleurope.d.ts +54 -0
  24. package/dist/src/maps/centraleurope.js +236 -0
  25. package/dist/src/maps/china.d.ts +54 -0
  26. package/dist/src/maps/china.js +262 -0
  27. package/dist/src/maps/france.d.ts +54 -0
  28. package/dist/src/maps/france.js +290 -0
  29. package/dist/src/maps/germany.d.ts +57 -0
  30. package/dist/src/maps/germany.js +328 -0
  31. package/dist/src/maps/indian.d.ts +54 -0
  32. package/dist/src/maps/indian.js +283 -0
  33. package/dist/src/maps/italy.d.ts +54 -0
  34. package/dist/src/maps/italy.js +190 -0
  35. package/dist/src/maps/japan.d.ts +46 -0
  36. package/dist/src/maps/japan.js +144 -0
  37. package/dist/src/maps/korea.d.ts +54 -0
  38. package/dist/src/maps/korea.js +186 -0
  39. package/dist/src/maps/middleeast.d.ts +54 -0
  40. package/dist/src/maps/middleeast.js +225 -0
  41. package/dist/src/maps/northerneurope.d.ts +54 -0
  42. package/dist/src/maps/northerneurope.js +197 -0
  43. package/dist/src/maps/quebec.d.ts +54 -0
  44. package/dist/src/maps/quebec.js +283 -0
  45. package/dist/src/maps/russia.d.ts +54 -0
  46. package/dist/src/maps/russia.js +286 -0
  47. package/dist/src/maps/southafrica.d.ts +46 -0
  48. package/dist/src/maps/southafrica.js +152 -0
  49. package/dist/src/maps/spainportugal.d.ts +54 -0
  50. package/dist/src/maps/spainportugal.js +289 -0
  51. package/dist/src/maps/ukireland.d.ts +52 -0
  52. package/dist/src/maps/ukireland.js +176 -0
  53. package/dist/src/maps.d.ts +50 -0
  54. package/dist/src/maps.js +61 -0
  55. package/dist/src/move.d.ts +63 -0
  56. package/dist/src/move.js +15 -0
  57. package/dist/src/powerPlants.d.ts +4 -0
  58. package/dist/src/powerPlants.js +60 -0
  59. package/dist/src/prices.d.ts +7 -0
  60. package/dist/src/prices.js +10 -0
  61. package/dist/src/randomizeMap.d.ts +3 -0
  62. package/dist/src/randomizeMap.js +244 -0
  63. package/dist/src/utils.d.ts +2 -0
  64. package/dist/src/utils.js +24 -0
  65. package/dist/wrapper.d.ts +30 -0
  66. package/dist/wrapper.js +127 -0
  67. package/index.ts +6 -0
  68. package/package.json +51 -0
  69. package/src/available-moves.ts +450 -0
  70. package/src/engine.spec.ts +163 -0
  71. package/src/engine.ts +2270 -0
  72. package/src/fixtures/GermanyRecharged.json +6627 -0
  73. package/src/fixtures/USAOriginal.json +5216 -0
  74. package/src/fixtures/supply.json +5792 -0
  75. package/src/fixtures/undo.json +4102 -0
  76. package/src/gamestate.ts +164 -0
  77. package/src/log.ts +17 -0
  78. package/src/maps/america.ts +411 -0
  79. package/src/maps/australia.ts +137 -0
  80. package/src/maps/badenwurttemberg.ts +162 -0
  81. package/src/maps/benelux.ts +210 -0
  82. package/src/maps/brazil.ts +306 -0
  83. package/src/maps/centraleurope.ts +235 -0
  84. package/src/maps/china.ts +268 -0
  85. package/src/maps/france.ts +295 -0
  86. package/src/maps/germany.ts +328 -0
  87. package/src/maps/indian.ts +289 -0
  88. package/src/maps/italy.ts +189 -0
  89. package/src/maps/japan.ts +143 -0
  90. package/src/maps/korea.ts +185 -0
  91. package/src/maps/middleeast.ts +225 -0
  92. package/src/maps/northerneurope.ts +196 -0
  93. package/src/maps/quebec.ts +304 -0
  94. package/src/maps/russia.ts +292 -0
  95. package/src/maps/southafrica.ts +151 -0
  96. package/src/maps/spainportugal.ts +295 -0
  97. package/src/maps/ukireland.ts +175 -0
  98. package/src/maps.ts +123 -0
  99. package/src/move.ts +83 -0
  100. package/src/powerPlants.ts +59 -0
  101. package/src/prices.ts +10 -0
  102. package/src/randomizeMap.ts +288 -0
  103. package/src/rankings.spec.ts +18 -0
  104. package/src/utils.spec.ts +13 -0
  105. package/src/utils.ts +23 -0
  106. package/tsconfig.json +17 -0
  107. package/wrapper.ts +126 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 donkeytech
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # powergrid-engine
2
+
3
+ Typescript engine for Power Grid.
4
+
5
+ ## Setup
6
+
7
+ ### Requirements
8
+
9
+ Recent version of node / pnpm.
10
+
11
+ ### Dependencies
12
+
13
+ In the project's folder:
14
+
15
+ ```
16
+ pnpm
17
+ ```
18
+
19
+ ### Build
20
+
21
+ To compile Typescript into javascript:
22
+
23
+ ```
24
+ pnpm build
25
+ ```
26
+
27
+ ### Test
28
+
29
+ ```
30
+ pnpm test
31
+ ```
@@ -0,0 +1,6 @@
1
+ export { availableMoves, AvailableMoves } from './src/available-moves';
2
+ export { currentPlayers, ended, move, playersSortedByScore, reconstructState, setup, stripSecret } from './src/engine';
3
+ export { Phase } from './src/gamestate';
4
+ export type { GameState, Player } from './src/gamestate';
5
+ export { LogItem } from './src/log';
6
+ export { Move, MoveName, Moves } from './src/move';
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MoveName = exports.Phase = exports.stripSecret = exports.setup = exports.reconstructState = exports.playersSortedByScore = exports.move = exports.ended = exports.currentPlayers = exports.availableMoves = void 0;
4
+ var available_moves_1 = require("./src/available-moves");
5
+ Object.defineProperty(exports, "availableMoves", { enumerable: true, get: function () { return available_moves_1.availableMoves; } });
6
+ var engine_1 = require("./src/engine");
7
+ Object.defineProperty(exports, "currentPlayers", { enumerable: true, get: function () { return engine_1.currentPlayers; } });
8
+ Object.defineProperty(exports, "ended", { enumerable: true, get: function () { return engine_1.ended; } });
9
+ Object.defineProperty(exports, "move", { enumerable: true, get: function () { return engine_1.move; } });
10
+ Object.defineProperty(exports, "playersSortedByScore", { enumerable: true, get: function () { return engine_1.playersSortedByScore; } });
11
+ Object.defineProperty(exports, "reconstructState", { enumerable: true, get: function () { return engine_1.reconstructState; } });
12
+ Object.defineProperty(exports, "setup", { enumerable: true, get: function () { return engine_1.setup; } });
13
+ Object.defineProperty(exports, "stripSecret", { enumerable: true, get: function () { return engine_1.stripSecret; } });
14
+ var gamestate_1 = require("./src/gamestate");
15
+ Object.defineProperty(exports, "Phase", { enumerable: true, get: function () { return gamestate_1.Phase; } });
16
+ var move_1 = require("./src/move");
17
+ Object.defineProperty(exports, "MoveName", { enumerable: true, get: function () { return move_1.MoveName; } });
@@ -0,0 +1,24 @@
1
+ import { GameState, Player, ResourceType } from './gamestate';
2
+ import { MoveName } from './move';
3
+ export interface AvailableMoves {
4
+ [MoveName.ChoosePowerPlant]?: number[];
5
+ [MoveName.Bid]?: number[];
6
+ [MoveName.DiscardPowerPlant]?: number[];
7
+ [MoveName.DiscardResources]?: ResourceType[];
8
+ [MoveName.BuyResource]?: {
9
+ resource: ResourceType;
10
+ price: number;
11
+ }[];
12
+ [MoveName.Build]?: {
13
+ name: string;
14
+ price: number;
15
+ }[];
16
+ [MoveName.UsePowerPlant]?: {
17
+ powerPlant: number;
18
+ resourcesSpent: ResourceType[];
19
+ citiesPowered: number;
20
+ }[];
21
+ [MoveName.Pass]?: boolean[];
22
+ [MoveName.Undo]?: boolean[];
23
+ }
24
+ export declare function availableMoves(G: GameState, player: Player): AvailableMoves;
@@ -0,0 +1,363 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.availableMoves = void 0;
7
+ const lodash_1 = require("lodash");
8
+ const gamestate_1 = require("./gamestate");
9
+ const move_1 = require("./move");
10
+ const prices_1 = __importDefault(require("./prices"));
11
+ function availableMoves(G, player) {
12
+ var _a, _b, _c, _d, _e, _f;
13
+ const moves = {};
14
+ const lastLog = G.log[G.log.length - 1];
15
+ if (lastLog.type == 'move' && G.currentPlayers.includes(player.id)) {
16
+ if (lastLog.player == player.id && ((_a = player.lastMove) === null || _a === void 0 ? void 0 : _a.name) != move_1.MoveName.Pass) {
17
+ moves[move_1.MoveName.Undo] = [true, false];
18
+ }
19
+ else if (G.phase == gamestate_1.Phase.Bureaucracy && ((_b = player.lastMove) === null || _b === void 0 ? void 0 : _b.name) == move_1.MoveName.UsePowerPlant) {
20
+ moves[move_1.MoveName.Undo] = [true, false];
21
+ }
22
+ }
23
+ switch (G.phase) {
24
+ case gamestate_1.Phase.Auction: {
25
+ if (player.powerPlants.length > 4 || (G.players.length > 2 && player.powerPlants.length > 3)) {
26
+ moves[move_1.MoveName.DiscardPowerPlant] = player.powerPlants
27
+ .filter((_, i) => i != player.powerPlants.length - 1)
28
+ .map((pp) => pp.number);
29
+ }
30
+ else {
31
+ const toDiscard = [];
32
+ let hybridCapacityUsed = Math.max(0, player.oilLeft - player.oilCapacity);
33
+ if (player.coalCapacity + player.hybridCapacity < player.coalLeft + hybridCapacityUsed) {
34
+ toDiscard.push(gamestate_1.ResourceType.Coal);
35
+ }
36
+ hybridCapacityUsed = Math.max(0, player.coalLeft - player.coalCapacity);
37
+ if (player.oilCapacity + player.hybridCapacity < player.oilLeft + hybridCapacityUsed) {
38
+ toDiscard.push(gamestate_1.ResourceType.Oil);
39
+ }
40
+ if (player.garbageCapacity < player.garbageLeft) {
41
+ toDiscard.push(gamestate_1.ResourceType.Garbage);
42
+ }
43
+ if (player.uraniumCapacity < player.uraniumLeft) {
44
+ toDiscard.push(gamestate_1.ResourceType.Uranium);
45
+ }
46
+ if (toDiscard.length > 0) {
47
+ moves[move_1.MoveName.DiscardResources] = toDiscard;
48
+ }
49
+ else {
50
+ if (G.chosenPowerPlant == undefined) {
51
+ let canBid = G.actualMarket.filter((p) => player.money >= p.number);
52
+ // No nuclear plants for Portugal
53
+ if (G.map.name == 'Spain & Portugal') {
54
+ const playerCities = player.cities.map((c) => G.map.cities.find((c_) => c_.name == c.name));
55
+ if (playerCities.every((c) => c.region == 'yellow')) {
56
+ canBid = canBid.filter((p) => p.type != gamestate_1.PowerPlantType.Uranium);
57
+ }
58
+ }
59
+ // Nuclear plants for Central Europe are only allowed for players with cities in:
60
+ // Czechia (green), Slovakia (brown), Hungary (purple)
61
+ if (G.map.name == 'Central Europe') {
62
+ const validCities = player.cities
63
+ .map((c) => G.map.cities.find((c_) => c_.name == c.name))
64
+ .filter((c) => c.region == 'green' || c.region == 'brown' || c.region == 'purple');
65
+ if (validCities.length == 0) {
66
+ canBid = canBid.filter((p) => p.type != gamestate_1.PowerPlantType.Uranium);
67
+ }
68
+ }
69
+ if (canBid.length > 0) {
70
+ moves[move_1.MoveName.ChoosePowerPlant] = canBid.map((p) => p.number);
71
+ }
72
+ if (G.round > 1) {
73
+ moves[move_1.MoveName.Pass] = [true];
74
+ }
75
+ }
76
+ else {
77
+ if (G.options.fastBid) {
78
+ if (G.minimunBid <= player.money) {
79
+ moves[move_1.MoveName.Bid] = lodash_1.range(G.minimunBid, player.money + 1);
80
+ }
81
+ }
82
+ else {
83
+ if (G.currentBid) {
84
+ if (G.currentBid < player.money) {
85
+ moves[move_1.MoveName.Bid] = lodash_1.range(G.currentBid + 1, player.money + 1);
86
+ }
87
+ }
88
+ else {
89
+ moves[move_1.MoveName.Bid] = lodash_1.range(G.minimunBid, player.money + 1);
90
+ }
91
+ }
92
+ // No nuclear plants for Portugal
93
+ if (G.map.name == 'Spain & Portugal') {
94
+ const playerCities = player.cities.map((c) => G.map.cities.find((c_) => c_.name == c.name));
95
+ if (playerCities.every((c) => c.region == 'yellow') &&
96
+ G.chosenPowerPlant.type == gamestate_1.PowerPlantType.Uranium) {
97
+ moves[move_1.MoveName.Bid] = undefined;
98
+ }
99
+ }
100
+ // Nuclear plants for Central Europe are only allowed for players with cities in:
101
+ // Czechia (green), Slovakia (brown), Hungary (purple)
102
+ if (G.map.name == 'Central Europe') {
103
+ const validCities = player.cities
104
+ .map((c) => G.map.cities.find((c_) => c_.name == c.name))
105
+ .filter((c) => c.region == 'green' || c.region == 'brown' || c.region == 'purple');
106
+ if (validCities.length == 0 && G.chosenPowerPlant.type == gamestate_1.PowerPlantType.Uranium) {
107
+ moves[move_1.MoveName.Bid] = undefined;
108
+ }
109
+ }
110
+ if (G.options.fastBid) {
111
+ if (player.id != G.auctioningPlayer) {
112
+ moves[move_1.MoveName.Pass] = [true];
113
+ }
114
+ }
115
+ else {
116
+ if (G.currentBid != null) {
117
+ moves[move_1.MoveName.Pass] = [true];
118
+ }
119
+ }
120
+ }
121
+ }
122
+ }
123
+ break;
124
+ }
125
+ case gamestate_1.Phase.Resources: {
126
+ if (G.map.name == 'India' && G.chosenResource !== undefined) {
127
+ moves[move_1.MoveName.Pass] = [true];
128
+ break;
129
+ }
130
+ const toBuy = [];
131
+ let maxPriceAvailable;
132
+ if (G.map.maxPriceAvailable) {
133
+ maxPriceAvailable = G.map.maxPriceAvailable[G.step - 1];
134
+ }
135
+ else {
136
+ maxPriceAvailable = 16;
137
+ }
138
+ if (G.coalMarket > 0) {
139
+ const hybridCapacityUsed = player.hybridCapacity > 0 ? Math.max(0, player.oilLeft - player.oilCapacity) : 0;
140
+ const coalPrices = (_c = G.coalPrices) !== null && _c !== void 0 ? _c : prices_1.default[gamestate_1.ResourceType.Coal];
141
+ const price = coalPrices[coalPrices.length - G.coalMarket];
142
+ if (player.money >= price &&
143
+ player.coalCapacity + player.hybridCapacity > hybridCapacityUsed + player.coalLeft &&
144
+ price <= maxPriceAvailable) {
145
+ toBuy.push({ resource: gamestate_1.ResourceType.Coal });
146
+ }
147
+ }
148
+ else {
149
+ if (G.options.variant == 'recharged' && G.map.name == 'USA' && G.coalSupply > 0) {
150
+ const hybridCapacityUsed = player.hybridCapacity > 0 ? Math.max(0, player.oilLeft - player.oilCapacity) : 0;
151
+ if (player.money >= 8 &&
152
+ player.coalCapacity + player.hybridCapacity > hybridCapacityUsed + player.coalLeft) {
153
+ toBuy.push({ resource: gamestate_1.ResourceType.Coal });
154
+ }
155
+ }
156
+ }
157
+ if (G.oilMarket > 0) {
158
+ const hybridCapacityUsed = player.hybridCapacity > 0 ? Math.max(0, player.coalLeft - player.coalCapacity) : 0;
159
+ const oilPrices = (_d = G.oilPrices) !== null && _d !== void 0 ? _d : prices_1.default[gamestate_1.ResourceType.Oil];
160
+ const price = oilPrices[oilPrices.length - G.oilMarket];
161
+ if (player.money >= price &&
162
+ player.oilCapacity + player.hybridCapacity > hybridCapacityUsed + player.oilLeft &&
163
+ price <= maxPriceAvailable) {
164
+ toBuy.push({ resource: gamestate_1.ResourceType.Oil });
165
+ }
166
+ }
167
+ if (G.garbageMarket > 0) {
168
+ const garbagePrices = (_e = G.garbagePrices) !== null && _e !== void 0 ? _e : prices_1.default[gamestate_1.ResourceType.Garbage];
169
+ let price = garbagePrices[garbagePrices.length - G.garbageMarket];
170
+ // $1 cheaper for players in Wien in Central Europe
171
+ if (G.map.name == 'Central Europe') {
172
+ const wienCity = player.cities.filter((c) => c.name == 'Wien');
173
+ if ((wienCity === null || wienCity === void 0 ? void 0 : wienCity.length) > 0) {
174
+ price--;
175
+ }
176
+ }
177
+ if (player.money >= price &&
178
+ player.garbageCapacity > player.garbageLeft &&
179
+ price <= maxPriceAvailable) {
180
+ toBuy.push({ resource: gamestate_1.ResourceType.Garbage });
181
+ }
182
+ }
183
+ if (G.uraniumMarket > 0) {
184
+ const uraniumPrices = (_f = G.uraniumPrices) !== null && _f !== void 0 ? _f : prices_1.default[gamestate_1.ResourceType.Uranium];
185
+ const price = uraniumPrices[uraniumPrices.length - G.uraniumMarket];
186
+ if (player.money >= price &&
187
+ player.uraniumCapacity > player.uraniumLeft &&
188
+ price <= maxPriceAvailable) {
189
+ toBuy.push({ resource: gamestate_1.ResourceType.Uranium });
190
+ }
191
+ }
192
+ if (toBuy.length > 0) {
193
+ moves[move_1.MoveName.BuyResource] = toBuy;
194
+ }
195
+ moves[move_1.MoveName.Pass] = [true];
196
+ break;
197
+ }
198
+ case gamestate_1.Phase.Building: {
199
+ if (player.cities.length < 21) {
200
+ let toBuild = player.cities.length == 0
201
+ ? G.map.cities.map((c) => ({ name: c.name, price: 0 }))
202
+ : dijkstra(G, player).map((c) => ({ name: c.name, price: c.price }));
203
+ toBuild.forEach((city) => {
204
+ const othersCount = G.players.filter((p) => p.cities.find((c) => city.name == c.name)).length;
205
+ city.price += 10 + othersCount * 5;
206
+ if (othersCount == G.step) {
207
+ city.price = 9999;
208
+ }
209
+ if (player.cities.find((c) => c.name == city.name)) {
210
+ city.price = 9999;
211
+ }
212
+ });
213
+ toBuild = toBuild.filter((c) => c.price <= player.money);
214
+ if (toBuild.length > 0) {
215
+ moves[move_1.MoveName.Build] = toBuild;
216
+ }
217
+ }
218
+ moves[move_1.MoveName.Pass] = [true];
219
+ break;
220
+ }
221
+ case gamestate_1.Phase.Bureaucracy: {
222
+ const toUse = [];
223
+ player.powerPlants.forEach((powerPlant) => {
224
+ if (player.powerPlantsNotUsed.includes(powerPlant.number)) {
225
+ switch (powerPlant.type) {
226
+ case gamestate_1.PowerPlantType.Coal: {
227
+ if (player.coalLeft >= powerPlant.cost) {
228
+ toUse.push({
229
+ powerPlant: powerPlant.number,
230
+ resourcesSpent: new Array(powerPlant.cost).fill(gamestate_1.ResourceType.Coal),
231
+ citiesPowered: powerPlant.citiesPowered,
232
+ });
233
+ }
234
+ break;
235
+ }
236
+ case gamestate_1.PowerPlantType.Oil: {
237
+ if (player.oilLeft >= powerPlant.cost) {
238
+ toUse.push({
239
+ powerPlant: powerPlant.number,
240
+ resourcesSpent: new Array(powerPlant.cost).fill(gamestate_1.ResourceType.Oil),
241
+ citiesPowered: powerPlant.citiesPowered,
242
+ });
243
+ }
244
+ break;
245
+ }
246
+ case gamestate_1.PowerPlantType.Garbage: {
247
+ if (player.garbageLeft >= powerPlant.cost) {
248
+ toUse.push({
249
+ powerPlant: powerPlant.number,
250
+ resourcesSpent: new Array(powerPlant.cost).fill(gamestate_1.ResourceType.Garbage),
251
+ citiesPowered: powerPlant.citiesPowered,
252
+ });
253
+ }
254
+ break;
255
+ }
256
+ case gamestate_1.PowerPlantType.Uranium: {
257
+ if (player.uraniumLeft >= powerPlant.cost) {
258
+ toUse.push({
259
+ powerPlant: powerPlant.number,
260
+ resourcesSpent: new Array(powerPlant.cost).fill(gamestate_1.ResourceType.Uranium),
261
+ citiesPowered: powerPlant.citiesPowered,
262
+ });
263
+ }
264
+ break;
265
+ }
266
+ case gamestate_1.PowerPlantType.Wind:
267
+ case gamestate_1.PowerPlantType.Nuclear:
268
+ toUse.push({
269
+ powerPlant: powerPlant.number,
270
+ resourcesSpent: [],
271
+ citiesPowered: powerPlant.citiesPowered,
272
+ });
273
+ break;
274
+ case gamestate_1.PowerPlantType.Hybrid: {
275
+ if (player.coalLeft + player.oilLeft >= powerPlant.cost) {
276
+ let resourcesSpentArr;
277
+ if (powerPlant.cost == 1) {
278
+ resourcesSpentArr = [[gamestate_1.ResourceType.Coal], [gamestate_1.ResourceType.Oil]];
279
+ }
280
+ else if (powerPlant.cost == 2) {
281
+ resourcesSpentArr = [
282
+ [gamestate_1.ResourceType.Coal, gamestate_1.ResourceType.Coal],
283
+ [gamestate_1.ResourceType.Coal, gamestate_1.ResourceType.Oil],
284
+ [gamestate_1.ResourceType.Oil, gamestate_1.ResourceType.Oil],
285
+ ];
286
+ }
287
+ else {
288
+ resourcesSpentArr = [
289
+ [gamestate_1.ResourceType.Coal, gamestate_1.ResourceType.Coal, gamestate_1.ResourceType.Coal],
290
+ [gamestate_1.ResourceType.Coal, gamestate_1.ResourceType.Coal, gamestate_1.ResourceType.Oil],
291
+ [gamestate_1.ResourceType.Coal, gamestate_1.ResourceType.Oil, gamestate_1.ResourceType.Oil],
292
+ [gamestate_1.ResourceType.Oil, gamestate_1.ResourceType.Oil, gamestate_1.ResourceType.Oil],
293
+ ];
294
+ }
295
+ resourcesSpentArr.forEach((resourcesSpent) => {
296
+ if (resourcesSpent.filter((r) => r == gamestate_1.ResourceType.Coal).length <=
297
+ player.coalLeft &&
298
+ resourcesSpent.filter((r) => r == gamestate_1.ResourceType.Oil).length <= player.oilLeft) {
299
+ toUse.push({
300
+ powerPlant: powerPlant.number,
301
+ resourcesSpent: resourcesSpent,
302
+ citiesPowered: powerPlant.citiesPowered,
303
+ });
304
+ }
305
+ });
306
+ }
307
+ }
308
+ }
309
+ }
310
+ });
311
+ if (toUse.length > 0) {
312
+ moves[move_1.MoveName.UsePowerPlant] = toUse;
313
+ }
314
+ // For India map, players must power as many cities as possible.
315
+ if (G.map.name != 'India' || player.citiesPowered >= player.targetCitiesPowered || player.isAI) {
316
+ moves[move_1.MoveName.Pass] = [true];
317
+ }
318
+ break;
319
+ }
320
+ }
321
+ return moves;
322
+ }
323
+ exports.availableMoves = availableMoves;
324
+ function dijkstra(G, player) {
325
+ const nodes = G.map.cities.map((c) => ({
326
+ name: c.name,
327
+ price: player.cities.find((city) => city.name == c.name) ? 0 : 9999,
328
+ visited: false,
329
+ }));
330
+ let currentNode = nodes.find((n) => n.name == player.cities[0].name);
331
+ currentNode.price = 0;
332
+ while (nodes.some((n) => !n.visited)) {
333
+ const currentConnections = G.map.connections.filter((c) => c.nodes.includes(currentNode.name));
334
+ currentConnections.forEach((connection) => {
335
+ const otherName = connection.nodes.filter((n) => n != currentNode.name)[0];
336
+ const otherNode = nodes.find((n) => n.name == otherName);
337
+ const price = player.cities.find((c) => c.name == otherNode.name) ? 0 : currentNode.price + connection.cost;
338
+ if (!otherNode.visited && otherNode.price > price) {
339
+ otherNode.price = price;
340
+ }
341
+ });
342
+ currentNode.visited = true;
343
+ if (!nodes.some((n) => !n.visited)) {
344
+ break;
345
+ }
346
+ currentNode = nodes.reduce((a, b) => {
347
+ if (a.visited) {
348
+ return b;
349
+ }
350
+ if (b.visited) {
351
+ return a;
352
+ }
353
+ if (a.price <= b.price) {
354
+ return a;
355
+ }
356
+ return b;
357
+ });
358
+ if (currentNode.price > player.money) {
359
+ break;
360
+ }
361
+ }
362
+ return nodes;
363
+ }
@@ -0,0 +1,20 @@
1
+ import seedrandom from 'seedrandom';
2
+ import { GameOptions, GameState, Player, PowerPlant } from './gamestate';
3
+ import { GameMap } from './maps';
4
+ import { Move } from './move';
5
+ export declare const playerColors: string[];
6
+ export declare function defaultSetupDeck(numPlayers: number, variant: string, rng: seedrandom.prng, useNewRechargedSetup: boolean): {
7
+ actualMarket: PowerPlant[];
8
+ futureMarket: PowerPlant[];
9
+ powerPlantsDeck: PowerPlant[];
10
+ };
11
+ export declare function setup(numPlayers: number, { fastBid, map, variant, showMoney, useNewRechargedSetup, trackTotalSpent, randomizeMap, }: GameOptions, seed?: string, forceDeck?: PowerPlant[], forceMap?: GameMap): GameState;
12
+ export declare function stripSecret(G: GameState, player?: number): GameState;
13
+ export declare function currentPlayers(G: GameState): number[];
14
+ export declare function move(G: GameState, move: Move, playerNumber: number, isUndo?: boolean): GameState;
15
+ export declare function moveAI(G: GameState, playerNumber: number): GameState;
16
+ export declare function ended(G: GameState): boolean;
17
+ export declare function scores(G: GameState): number[];
18
+ export declare function reconstructState(gameState: GameState, to?: number): GameState;
19
+ export declare function getPowerPlant(num: number, mapName?: string): PowerPlant;
20
+ export declare function playersSortedByScore(G: GameState): Player[];