@gamepark/its-a-wonderful-world 2.8.0 → 2.9.0
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.
- package/dist/GameState.js +1 -2
- package/dist/GameView.js +1 -2
- package/dist/ItsAWonderfulWorld.js +300 -543
- package/dist/Options.js +38 -66
- package/dist/Phase.js +1 -3
- package/dist/Player.js +1 -2
- package/dist/PlayerView.js +1 -2
- package/dist/Production.js +12 -24
- package/dist/Scoring.js +35 -108
- package/dist/canUndo.js +36 -42
- package/dist/index.js +2 -10
- package/dist/material/AscensionDevelopments.js +146 -153
- package/dist/material/Character.js +6 -10
- package/dist/material/Construction.js +1 -2
- package/dist/material/DeckType.js +1 -3
- package/dist/material/Development.js +121 -125
- package/dist/material/DevelopmentDetails.js +6 -14
- package/dist/material/DevelopmentType.js +5 -9
- package/dist/material/Developments.js +280 -290
- package/dist/material/Empire.js +1 -2
- package/dist/material/EmpireName.js +3 -6
- package/dist/material/EmpireSide.js +3 -6
- package/dist/material/Empires.js +206 -212
- package/dist/material/Resource.js +6 -10
- package/dist/moves/ChooseDevelopmentCard.js +15 -29
- package/dist/moves/CompleteConstruction.js +13 -46
- package/dist/moves/Concede.js +7 -16
- package/dist/moves/DealDevelopmentCards.js +43 -111
- package/dist/moves/DiscardLeftoverCards.js +12 -51
- package/dist/moves/Move.js +1 -2
- package/dist/moves/MoveType.js +1 -3
- package/dist/moves/MoveView.js +1 -2
- package/dist/moves/PassCards.js +28 -39
- package/dist/moves/PlaceCharacter.js +9 -22
- package/dist/moves/PlaceResource.js +17 -34
- package/dist/moves/Produce.js +45 -144
- package/dist/moves/ReceiveCharacter.js +11 -22
- package/dist/moves/Recycle.js +12 -23
- package/dist/moves/RevealChosenCards.js +23 -34
- package/dist/moves/SlateForConstruction.js +12 -23
- package/dist/moves/StartPhase.js +9 -40
- package/dist/moves/TellYouAreReady.js +8 -18
- package/dist/moves/TransformIntoKrystallium.js +10 -19
- package/dist/typeguards.js +3 -9
- package/package.json +3 -2
|
@@ -1,731 +1,488 @@
|
|
|
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
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
40
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
41
|
-
}) : function(o, v) {
|
|
42
|
-
o["default"] = v;
|
|
43
|
-
});
|
|
44
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
45
|
-
if (mod && mod.__esModule) return mod;
|
|
46
|
-
var result = {};
|
|
47
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
48
|
-
__setModuleDefault(result, mod);
|
|
49
|
-
return result;
|
|
50
|
-
};
|
|
51
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
52
|
-
var t = {};
|
|
53
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
54
|
-
t[p] = s[p];
|
|
55
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
56
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
57
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
58
|
-
t[p[i]] = s[p[i]];
|
|
59
|
-
}
|
|
60
|
-
return t;
|
|
61
|
-
};
|
|
62
|
-
var __values = (this && this.__values) || function(o) {
|
|
63
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
64
|
-
if (m) return m.call(o);
|
|
65
|
-
if (o && typeof o.length === "number") return {
|
|
66
|
-
next: function () {
|
|
67
|
-
if (o && i >= o.length) o = void 0;
|
|
68
|
-
return { value: o && o[i++], done: !o };
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
72
|
-
};
|
|
73
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
74
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
75
|
-
if (!m) return o;
|
|
76
|
-
var i = m.call(o), r, ar = [], e;
|
|
77
|
-
try {
|
|
78
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
79
|
-
}
|
|
80
|
-
catch (error) { e = { error: error }; }
|
|
81
|
-
finally {
|
|
82
|
-
try {
|
|
83
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
84
|
-
}
|
|
85
|
-
finally { if (e) throw e.error; }
|
|
86
|
-
}
|
|
87
|
-
return ar;
|
|
88
|
-
};
|
|
89
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
90
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
91
|
-
if (ar || !(i in from)) {
|
|
92
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
93
|
-
ar[i] = from[i];
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
97
|
-
};
|
|
98
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
99
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
100
|
-
};
|
|
101
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
102
|
-
exports.isTurnToPlay = exports.placeAvailableCubesMoves = exports.constructionsThatMayReceiveCubes = exports.isOver = exports.countCharacters = exports.isActive = exports.isPlaceItemOnCard = exports.getMovesToBuild = exports.canPay = exports.canBuild = exports.getNextProductionStep = exports.couldPlaceResource = exports.getSpacesMissingItem = exports.getRemainingCost = exports.getCost = exports.getLegalMoves = exports.getPredictableAutomaticMoves = exports.setupPlayers = exports.numberOfRounds = exports.numberOfCardsToDraft = void 0;
|
|
103
|
-
var rules_api_1 = require("@gamepark/rules-api");
|
|
104
|
-
var lodash_1 = require("lodash");
|
|
105
|
-
var canUndo_1 = __importDefault(require("./canUndo"));
|
|
106
|
-
var Character_1 = __importStar(require("./material/Character"));
|
|
107
|
-
var DevelopmentDetails_1 = require("./material/DevelopmentDetails");
|
|
108
|
-
var Developments_1 = require("./material/Developments");
|
|
109
|
-
var EmpireName_1 = __importDefault(require("./material/EmpireName"));
|
|
110
|
-
var Empires_1 = __importDefault(require("./material/Empires"));
|
|
111
|
-
var EmpireSide_1 = __importDefault(require("./material/EmpireSide"));
|
|
112
|
-
var Resource_1 = __importStar(require("./material/Resource"));
|
|
113
|
-
var ChooseDevelopmentCard_1 = require("./moves/ChooseDevelopmentCard");
|
|
114
|
-
var CompleteConstruction_1 = require("./moves/CompleteConstruction");
|
|
115
|
-
var Concede_1 = require("./moves/Concede");
|
|
116
|
-
var DealDevelopmentCards_1 = require("./moves/DealDevelopmentCards");
|
|
117
|
-
var DiscardLeftoverCards_1 = require("./moves/DiscardLeftoverCards");
|
|
118
|
-
var MoveType_1 = __importDefault(require("./moves/MoveType"));
|
|
119
|
-
var PassCards_1 = require("./moves/PassCards");
|
|
120
|
-
var PlaceCharacter_1 = require("./moves/PlaceCharacter");
|
|
121
|
-
var PlaceResource_1 = require("./moves/PlaceResource");
|
|
122
|
-
var Produce_1 = require("./moves/Produce");
|
|
123
|
-
var ReceiveCharacter_1 = require("./moves/ReceiveCharacter");
|
|
124
|
-
var Recycle_1 = require("./moves/Recycle");
|
|
125
|
-
var RevealChosenCards_1 = require("./moves/RevealChosenCards");
|
|
126
|
-
var SlateForConstruction_1 = require("./moves/SlateForConstruction");
|
|
127
|
-
var StartPhase_1 = require("./moves/StartPhase");
|
|
128
|
-
var TellYouAreReady_1 = require("./moves/TellYouAreReady");
|
|
129
|
-
var TransformIntoKrystallium_1 = require("./moves/TransformIntoKrystallium");
|
|
130
|
-
var Options_1 = require("./Options");
|
|
131
|
-
var Phase_1 = __importDefault(require("./Phase"));
|
|
132
|
-
var Scoring_1 = require("./Scoring");
|
|
133
|
-
var typeguards_1 = require("./typeguards");
|
|
134
|
-
exports.numberOfCardsToDraft = 7;
|
|
135
|
-
exports.numberOfRounds = 4;
|
|
136
|
-
var defaultEmpireCardsSide = EmpireSide_1.default.A;
|
|
137
|
-
var ItsAWonderfulWorld = (function (_super) {
|
|
138
|
-
__extends(ItsAWonderfulWorld, _super);
|
|
139
|
-
function ItsAWonderfulWorld(arg) {
|
|
140
|
-
var _this = this;
|
|
141
|
-
if ((0, Options_1.isGameOptions)(arg)) {
|
|
142
|
-
var setup = {
|
|
1
|
+
import { Rules } from '@gamepark/rules-api';
|
|
2
|
+
import { shuffle } from 'lodash';
|
|
3
|
+
import canUndo from './canUndo';
|
|
4
|
+
import Character, { characters, ChooseCharacter, isCharacter } from './material/Character';
|
|
5
|
+
import { totalCost } from './material/DevelopmentDetails';
|
|
6
|
+
import { ascensionDevelopmentCardIds, baseDevelopmentCardIds, getCardDetails, getCardType } from './material/Developments';
|
|
7
|
+
import EmpireName from './material/EmpireName';
|
|
8
|
+
import Empires from './material/Empires';
|
|
9
|
+
import EmpireSide from './material/EmpireSide';
|
|
10
|
+
import Resource, { isResource, resources } from './material/Resource';
|
|
11
|
+
import { chooseDevelopmentCard, chooseDevelopmentCardMove } from './moves/ChooseDevelopmentCard';
|
|
12
|
+
import { completeConstruction, completeConstructionMove } from './moves/CompleteConstruction';
|
|
13
|
+
import { concede, concedeMove } from './moves/Concede';
|
|
14
|
+
import { dealDevelopmentCards, dealDevelopmentCardsMove, getDealDevelopmentCardsView } from './moves/DealDevelopmentCards';
|
|
15
|
+
import { discardLeftOverCards, discardLeftOverCardsMove, getDiscardLeftoverCardsView } from './moves/DiscardLeftoverCards';
|
|
16
|
+
import MoveType from './moves/MoveType';
|
|
17
|
+
import { getPassCardsView, passCards, passCardsMove } from './moves/PassCards';
|
|
18
|
+
import { isPlaceCharacter, placeCharacter, placeCharacterMove } from './moves/PlaceCharacter';
|
|
19
|
+
import { isPlaceResourceOnConstruction, placeResource, placeResourceOnConstructionMove, placeResourceOnEmpireMove } from './moves/PlaceResource';
|
|
20
|
+
import { produce, produceMove } from './moves/Produce';
|
|
21
|
+
import { receiveCharacter, receiveCharacterMove } from './moves/ReceiveCharacter';
|
|
22
|
+
import { recycle, recycleMove } from './moves/Recycle';
|
|
23
|
+
import { getRevealChosenCardsView, revealChosenCards, revealChosenCardsMove } from './moves/RevealChosenCards';
|
|
24
|
+
import { slateForConstruction, slateForConstructionMove } from './moves/SlateForConstruction';
|
|
25
|
+
import { startPhase, startPhaseMove } from './moves/StartPhase';
|
|
26
|
+
import { tellYouAreReady, tellYouAreReadyMove } from './moves/TellYouAreReady';
|
|
27
|
+
import { transformIntoKrystallium, transformIntoKrystalliumMove } from './moves/TransformIntoKrystallium';
|
|
28
|
+
import { isGameOptions } from './Options';
|
|
29
|
+
import Phase from './Phase';
|
|
30
|
+
import { getPlayerScore } from './Scoring';
|
|
31
|
+
import { isPlayerView } from './typeguards';
|
|
32
|
+
export const numberOfCardsToDraft = 7;
|
|
33
|
+
export const numberOfRounds = 4;
|
|
34
|
+
const defaultEmpireCardsSide = EmpireSide.A;
|
|
35
|
+
export default class ItsAWonderfulWorld extends Rules {
|
|
36
|
+
constructor(arg) {
|
|
37
|
+
if (isGameOptions(arg)) {
|
|
38
|
+
const setup = {
|
|
143
39
|
players: setupPlayers(arg),
|
|
144
|
-
deck:
|
|
40
|
+
deck: shuffle(baseDevelopmentCardIds),
|
|
145
41
|
discard: [],
|
|
146
42
|
round: 1,
|
|
147
|
-
phase:
|
|
43
|
+
phase: Phase.Draft
|
|
148
44
|
};
|
|
149
45
|
if (arg.corruptionAndAscension) {
|
|
150
|
-
setup.ascensionDeck =
|
|
46
|
+
setup.ascensionDeck = shuffle(ascensionDevelopmentCardIds);
|
|
151
47
|
}
|
|
152
|
-
|
|
48
|
+
super(setup);
|
|
153
49
|
}
|
|
154
50
|
else {
|
|
155
|
-
|
|
51
|
+
super(arg);
|
|
156
52
|
}
|
|
157
|
-
return _this;
|
|
158
53
|
}
|
|
159
|
-
|
|
54
|
+
isTurnToPlay(playerId) {
|
|
160
55
|
return isTurnToPlay(this.state, playerId);
|
|
161
|
-
}
|
|
162
|
-
|
|
56
|
+
}
|
|
57
|
+
isOver() {
|
|
163
58
|
return isOver(this.state);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
59
|
+
}
|
|
60
|
+
getAutomaticMoves() {
|
|
61
|
+
const move = this.getAutomaticMove();
|
|
167
62
|
return move ? [move] : [];
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
var e_1, _a;
|
|
63
|
+
}
|
|
64
|
+
getAutomaticMove() {
|
|
171
65
|
switch (this.state.phase) {
|
|
172
|
-
case
|
|
173
|
-
|
|
66
|
+
case Phase.Draft:
|
|
67
|
+
const anyPlayer = this.state.players.filter(player => !player.eliminated)[0];
|
|
174
68
|
if (anyPlayer && !anyPlayer.hand.length && !anyPlayer.draftArea.length) {
|
|
175
|
-
return
|
|
69
|
+
return dealDevelopmentCardsMove;
|
|
176
70
|
}
|
|
177
|
-
else if (this.state.players.every(
|
|
178
|
-
return
|
|
71
|
+
else if (this.state.players.every(player => player.chosenCard !== undefined || (player.eliminated && !player.hand.length))) {
|
|
72
|
+
return revealChosenCardsMove;
|
|
179
73
|
}
|
|
180
74
|
else if (anyPlayer && anyPlayer.cardsToPass) {
|
|
181
|
-
return
|
|
75
|
+
return passCardsMove;
|
|
182
76
|
}
|
|
183
|
-
else if (anyPlayer && anyPlayer.draftArea.length ===
|
|
77
|
+
else if (anyPlayer && anyPlayer.draftArea.length === numberOfCardsToDraft) {
|
|
184
78
|
if (anyPlayer.hand.length) {
|
|
185
|
-
return
|
|
79
|
+
return discardLeftOverCardsMove;
|
|
186
80
|
}
|
|
187
81
|
else {
|
|
188
|
-
return
|
|
82
|
+
return startPhaseMove(Phase.Planning);
|
|
189
83
|
}
|
|
190
84
|
}
|
|
191
85
|
else {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
if (player.chosenCard === undefined && player.hand.length === 1) {
|
|
196
|
-
return (0, ChooseDevelopmentCard_1.chooseDevelopmentCardMove)(player.empire, player.hand[0]);
|
|
197
|
-
}
|
|
86
|
+
for (const player of this.state.players) {
|
|
87
|
+
if (player.chosenCard === undefined && player.hand.length === 1) {
|
|
88
|
+
return chooseDevelopmentCardMove(player.empire, player.hand[0]);
|
|
198
89
|
}
|
|
199
90
|
}
|
|
200
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
201
|
-
finally {
|
|
202
|
-
try {
|
|
203
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
204
|
-
}
|
|
205
|
-
finally { if (e_1) throw e_1.error; }
|
|
206
|
-
}
|
|
207
91
|
}
|
|
208
92
|
break;
|
|
209
|
-
case
|
|
210
|
-
if (this.state.players.every(
|
|
211
|
-
return
|
|
93
|
+
case Phase.Planning:
|
|
94
|
+
if (this.state.players.every(player => player.ready)) {
|
|
95
|
+
return startPhaseMove(Phase.Production);
|
|
212
96
|
}
|
|
213
97
|
break;
|
|
214
|
-
case
|
|
98
|
+
case Phase.Production:
|
|
215
99
|
if (!this.state.productionStep) {
|
|
216
|
-
return
|
|
100
|
+
return produceMove(Resource.Materials);
|
|
217
101
|
}
|
|
218
|
-
else if (this.state.players.every(
|
|
219
|
-
|
|
102
|
+
else if (this.state.players.every(player => player.ready)) {
|
|
103
|
+
const nextProductionStep = getNextProductionStep(this.state);
|
|
220
104
|
if (nextProductionStep) {
|
|
221
|
-
return
|
|
105
|
+
return produceMove(nextProductionStep);
|
|
222
106
|
}
|
|
223
|
-
else if (this.state.round <
|
|
224
|
-
return
|
|
107
|
+
else if (this.state.round < numberOfRounds) {
|
|
108
|
+
return startPhaseMove(Phase.Draft);
|
|
225
109
|
}
|
|
226
110
|
}
|
|
227
111
|
break;
|
|
228
112
|
}
|
|
229
113
|
return getPredictableAutomaticMoves(this.state);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
if (!player || (this.state.round ===
|
|
114
|
+
}
|
|
115
|
+
getLegalMoves(empire) {
|
|
116
|
+
const player = this.state.players.find(player => player.empire === empire);
|
|
117
|
+
if (!player || (this.state.round === numberOfRounds && this.state.productionStep === Resource.Exploration && player.ready)) {
|
|
234
118
|
return [];
|
|
235
119
|
}
|
|
236
120
|
return getLegalMoves(player, this.state.phase);
|
|
237
|
-
}
|
|
238
|
-
|
|
121
|
+
}
|
|
122
|
+
play(move) {
|
|
239
123
|
switch (move.type) {
|
|
240
|
-
case
|
|
241
|
-
|
|
124
|
+
case MoveType.DealDevelopmentCards:
|
|
125
|
+
dealDevelopmentCards(this.state);
|
|
242
126
|
break;
|
|
243
|
-
case
|
|
244
|
-
|
|
127
|
+
case MoveType.ChooseDevelopmentCard:
|
|
128
|
+
chooseDevelopmentCard(this.state, move);
|
|
245
129
|
break;
|
|
246
|
-
case
|
|
247
|
-
|
|
130
|
+
case MoveType.RevealChosenCards:
|
|
131
|
+
revealChosenCards(this.state);
|
|
248
132
|
break;
|
|
249
|
-
case
|
|
250
|
-
|
|
133
|
+
case MoveType.PassCards:
|
|
134
|
+
passCards(this.state);
|
|
251
135
|
break;
|
|
252
|
-
case
|
|
253
|
-
|
|
136
|
+
case MoveType.DiscardLeftoverCards:
|
|
137
|
+
discardLeftOverCards(this.state);
|
|
254
138
|
break;
|
|
255
|
-
case
|
|
256
|
-
|
|
139
|
+
case MoveType.StartPhase:
|
|
140
|
+
startPhase(this.state, move);
|
|
257
141
|
break;
|
|
258
|
-
case
|
|
259
|
-
|
|
142
|
+
case MoveType.SlateForConstruction:
|
|
143
|
+
slateForConstruction(this.state, move);
|
|
260
144
|
break;
|
|
261
|
-
case
|
|
262
|
-
|
|
145
|
+
case MoveType.Recycle:
|
|
146
|
+
recycle(this.state, move);
|
|
263
147
|
break;
|
|
264
|
-
case
|
|
265
|
-
|
|
148
|
+
case MoveType.PlaceResource:
|
|
149
|
+
placeResource(this.state, move);
|
|
266
150
|
break;
|
|
267
|
-
case
|
|
268
|
-
|
|
151
|
+
case MoveType.CompleteConstruction:
|
|
152
|
+
completeConstruction(this.state, move);
|
|
269
153
|
break;
|
|
270
|
-
case
|
|
271
|
-
|
|
154
|
+
case MoveType.TransformIntoKrystallium:
|
|
155
|
+
transformIntoKrystallium(this.state, move);
|
|
272
156
|
break;
|
|
273
|
-
case
|
|
274
|
-
|
|
157
|
+
case MoveType.TellYouAreReady:
|
|
158
|
+
tellYouAreReady(this.state, move);
|
|
275
159
|
break;
|
|
276
|
-
case
|
|
277
|
-
|
|
160
|
+
case MoveType.Produce:
|
|
161
|
+
produce(this.state, move);
|
|
278
162
|
break;
|
|
279
|
-
case
|
|
280
|
-
|
|
163
|
+
case MoveType.ReceiveCharacter:
|
|
164
|
+
receiveCharacter(this.state, move);
|
|
281
165
|
break;
|
|
282
|
-
case
|
|
283
|
-
|
|
166
|
+
case MoveType.PlaceCharacter:
|
|
167
|
+
placeCharacter(this.state, move);
|
|
284
168
|
break;
|
|
285
|
-
case
|
|
286
|
-
|
|
169
|
+
case MoveType.Concede:
|
|
170
|
+
concede(this.state, move);
|
|
287
171
|
break;
|
|
288
172
|
}
|
|
289
173
|
return [];
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
return
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
|
|
174
|
+
}
|
|
175
|
+
getScore(empire) {
|
|
176
|
+
return getPlayerScore(this.getPlayer(empire));
|
|
177
|
+
}
|
|
178
|
+
getPlayer(playerId) {
|
|
179
|
+
const player = this.state.players.find(player => player.empire === playerId);
|
|
296
180
|
if (!player)
|
|
297
|
-
throw new Error(
|
|
181
|
+
throw new Error(`${playerId} is expected on ${this.state}`);
|
|
298
182
|
return player;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
|
|
183
|
+
}
|
|
184
|
+
rankPlayers(empireA, empireB) {
|
|
185
|
+
const playerA = this.getPlayer(empireA), playerB = this.getPlayer(empireB);
|
|
302
186
|
if (playerA.eliminated || playerB.eliminated) {
|
|
303
187
|
return playerA.eliminated ? playerB.eliminated ? playerB.eliminated - playerA.eliminated : 1 : -1;
|
|
304
188
|
}
|
|
305
|
-
|
|
189
|
+
const scoreA = getPlayerScore(playerA), scoreB = getPlayerScore(playerB);
|
|
306
190
|
if (scoreA !== scoreB) {
|
|
307
191
|
return scoreB - scoreA;
|
|
308
192
|
}
|
|
309
|
-
|
|
193
|
+
const buildingsA = playerA.constructedDevelopments.length, buildingsB = playerB.constructedDevelopments.length;
|
|
310
194
|
if (buildingsA !== buildingsB) {
|
|
311
195
|
return buildingsB - buildingsA;
|
|
312
196
|
}
|
|
313
197
|
return countCharacters(playerB) - countCharacters(playerA);
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
return (
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
198
|
+
}
|
|
199
|
+
canUndo(action, consecutiveActions) {
|
|
200
|
+
return canUndo(this.state, action, consecutiveActions);
|
|
201
|
+
}
|
|
202
|
+
getView(playerId) {
|
|
203
|
+
return {
|
|
204
|
+
...this.state, deck: this.state.deck.length, ascensionDeck: this.state.ascensionDeck?.length,
|
|
205
|
+
players: this.state.players.map(player => {
|
|
321
206
|
if (player.empire === playerId) {
|
|
322
207
|
return player;
|
|
323
208
|
}
|
|
324
209
|
else {
|
|
325
|
-
|
|
326
|
-
|
|
210
|
+
const { hand, chosenCard, ...visible } = player;
|
|
211
|
+
const playerView = { ...visible, hiddenHand: hand.map(getCardType) };
|
|
327
212
|
if (chosenCard !== undefined) {
|
|
328
213
|
playerView.ready = true;
|
|
329
214
|
}
|
|
330
215
|
return playerView;
|
|
331
216
|
}
|
|
332
|
-
})
|
|
333
|
-
|
|
334
|
-
|
|
217
|
+
})
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
getPlayerView(playerId) {
|
|
335
221
|
return this.getView(playerId);
|
|
336
|
-
}
|
|
337
|
-
|
|
222
|
+
}
|
|
223
|
+
getMoveView(move, playerId) {
|
|
338
224
|
switch (move.type) {
|
|
339
|
-
case
|
|
340
|
-
return playerId ?
|
|
341
|
-
case
|
|
225
|
+
case MoveType.DealDevelopmentCards:
|
|
226
|
+
return playerId ? getDealDevelopmentCardsView(this.state, playerId) : move;
|
|
227
|
+
case MoveType.ChooseDevelopmentCard:
|
|
342
228
|
if (playerId !== move.playerId) {
|
|
343
|
-
|
|
344
|
-
return
|
|
229
|
+
const { card, ...moveView } = move;
|
|
230
|
+
return { ...moveView };
|
|
345
231
|
}
|
|
346
232
|
break;
|
|
347
|
-
case
|
|
348
|
-
return
|
|
349
|
-
case
|
|
350
|
-
return playerId ?
|
|
351
|
-
case
|
|
352
|
-
return
|
|
233
|
+
case MoveType.RevealChosenCards:
|
|
234
|
+
return getRevealChosenCardsView(this.state);
|
|
235
|
+
case MoveType.PassCards:
|
|
236
|
+
return playerId ? getPassCardsView(this.state, playerId) : move;
|
|
237
|
+
case MoveType.DiscardLeftoverCards:
|
|
238
|
+
return getDiscardLeftoverCardsView(this.state);
|
|
353
239
|
}
|
|
354
240
|
return move;
|
|
355
|
-
}
|
|
356
|
-
|
|
241
|
+
}
|
|
242
|
+
getPlayerMoveView(move, playerId) {
|
|
357
243
|
return this.getMoveView(move, playerId);
|
|
358
|
-
}
|
|
359
|
-
|
|
244
|
+
}
|
|
245
|
+
isEliminated(playerId) {
|
|
360
246
|
return !!this.getPlayer(playerId).eliminated;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
return
|
|
364
|
-
}
|
|
365
|
-
|
|
247
|
+
}
|
|
248
|
+
giveUpMove(playerId) {
|
|
249
|
+
return concedeMove(playerId);
|
|
250
|
+
}
|
|
251
|
+
giveTime(playerId) {
|
|
366
252
|
switch (this.state.phase) {
|
|
367
|
-
case
|
|
368
|
-
return (
|
|
369
|
-
case
|
|
253
|
+
case Phase.Draft:
|
|
254
|
+
return (numberOfCardsToDraft - this.getPlayer(playerId).draftArea.length - 1) * 10;
|
|
255
|
+
case Phase.Planning:
|
|
370
256
|
return 20 + this.state.round * 40;
|
|
371
|
-
case
|
|
257
|
+
case Phase.Production:
|
|
372
258
|
return 10;
|
|
373
259
|
}
|
|
374
|
-
}
|
|
375
|
-
return ItsAWonderfulWorld;
|
|
376
|
-
}(rules_api_1.Rules));
|
|
377
|
-
exports.default = ItsAWonderfulWorld;
|
|
378
|
-
function setupPlayers(options) {
|
|
379
|
-
var players = options.players;
|
|
380
|
-
var empireSide = options.empiresSide;
|
|
381
|
-
var empiresLeft = (0, lodash_1.shuffle)(Object.values(EmpireName_1.default).filter(function (empire) { return players.some(function (player) { return player.id === empire; }); }));
|
|
382
|
-
return players.map(function (player) { return setupPlayer(player.id || empiresLeft.pop(), empireSide); });
|
|
260
|
+
}
|
|
383
261
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
262
|
+
export function setupPlayers(options) {
|
|
263
|
+
const players = options.players;
|
|
264
|
+
const empireSide = options.empiresSide;
|
|
265
|
+
const empiresLeft = shuffle(Object.values(EmpireName).filter(empire => players.some(player => player.id === empire)));
|
|
266
|
+
return players.map(player => setupPlayer(player.id || empiresLeft.pop(), empireSide));
|
|
267
|
+
}
|
|
268
|
+
function setupPlayer(empire, empireSide = defaultEmpireCardsSide) {
|
|
389
269
|
return {
|
|
390
|
-
empire:
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
empireCardResources: Array((_b = Empires_1.default[empire][empireSide].krystallium) !== null && _b !== void 0 ? _b : 0).fill(Resource_1.default.Krystallium),
|
|
394
|
-
constructedDevelopments: [], ready: false, characters: (_a = {}, _a[Character_1.default.Financier] = 0, _a[Character_1.default.General] = 0, _a), bonuses: []
|
|
270
|
+
empire, empireSide, hand: [], draftArea: [], constructionArea: [], availableResources: [],
|
|
271
|
+
empireCardResources: Array(Empires[empire][empireSide].krystallium ?? 0).fill(Resource.Krystallium),
|
|
272
|
+
constructedDevelopments: [], ready: false, characters: { [Character.Financier]: 0, [Character.General]: 0 }, bonuses: []
|
|
395
273
|
};
|
|
396
274
|
}
|
|
397
|
-
function getPredictableAutomaticMoves(state) {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
try {
|
|
403
|
-
for (var _f = (e_3 = void 0, __values(player.constructionArea)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
404
|
-
var construction = _g.value;
|
|
405
|
-
if (construction.costSpaces.every(function (space) { return space !== null; })) {
|
|
406
|
-
return (0, CompleteConstruction_1.completeConstructionMove)(player.empire, construction.card);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
411
|
-
finally {
|
|
412
|
-
try {
|
|
413
|
-
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
414
|
-
}
|
|
415
|
-
finally { if (e_3) throw e_3.error; }
|
|
416
|
-
}
|
|
417
|
-
if (player.empireCardResources.filter(function (resource) { return resource !== Resource_1.default.Krystallium; }).length >= 5) {
|
|
418
|
-
return (0, TransformIntoKrystallium_1.transformIntoKrystalliumMove)(player.empire);
|
|
419
|
-
}
|
|
420
|
-
var bonus = player.bonuses.find(function (bonus) { return bonus !== Character_1.ChooseCharacter; });
|
|
421
|
-
if ((0, Resource_1.isResource)(bonus)) {
|
|
422
|
-
return (0, PlaceResource_1.placeResourceOnEmpireMove)(player.empire, bonus);
|
|
423
|
-
}
|
|
424
|
-
else if ((0, Character_1.isCharacter)(bonus)) {
|
|
425
|
-
return (0, ReceiveCharacter_1.receiveCharacterMove)(player.empire, bonus);
|
|
426
|
-
}
|
|
427
|
-
var _loop_1 = function (resource) {
|
|
428
|
-
if (!player.draftArea.some(function (card) { return (0, Developments_1.getCardDetails)(card).constructionCost[resource]; })
|
|
429
|
-
&& !player.constructionArea.some(function (construction) { return couldPlaceResource(construction, resource); })) {
|
|
430
|
-
return { value: (0, PlaceResource_1.placeResourceOnEmpireMove)(player.empire, resource) };
|
|
431
|
-
}
|
|
432
|
-
};
|
|
433
|
-
try {
|
|
434
|
-
for (var _h = (e_4 = void 0, __values(__spreadArray([], __read(new Set(player.availableResources)), false))), _j = _h.next(); !_j.done; _j = _h.next()) {
|
|
435
|
-
var resource = _j.value;
|
|
436
|
-
var state_1 = _loop_1(resource);
|
|
437
|
-
if (typeof state_1 === "object")
|
|
438
|
-
return state_1.value;
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
442
|
-
finally {
|
|
443
|
-
try {
|
|
444
|
-
if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
|
|
445
|
-
}
|
|
446
|
-
finally { if (e_4) throw e_4.error; }
|
|
275
|
+
export function getPredictableAutomaticMoves(state) {
|
|
276
|
+
for (const player of state.players) {
|
|
277
|
+
for (const construction of player.constructionArea) {
|
|
278
|
+
if (construction.costSpaces.every(space => space !== null)) {
|
|
279
|
+
return completeConstructionMove(player.empire, construction.card);
|
|
447
280
|
}
|
|
448
281
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
282
|
+
if (player.empireCardResources.filter(resource => resource !== Resource.Krystallium).length >= 5) {
|
|
283
|
+
return transformIntoKrystalliumMove(player.empire);
|
|
284
|
+
}
|
|
285
|
+
const bonus = player.bonuses.find(bonus => bonus !== ChooseCharacter);
|
|
286
|
+
if (isResource(bonus)) {
|
|
287
|
+
return placeResourceOnEmpireMove(player.empire, bonus);
|
|
288
|
+
}
|
|
289
|
+
else if (isCharacter(bonus)) {
|
|
290
|
+
return receiveCharacterMove(player.empire, bonus);
|
|
291
|
+
}
|
|
292
|
+
for (const resource of [...new Set(player.availableResources)]) {
|
|
293
|
+
if (!player.draftArea.some(card => getCardDetails(card).constructionCost[resource])
|
|
294
|
+
&& !player.constructionArea.some(construction => couldPlaceResource(construction, resource))) {
|
|
295
|
+
return placeResourceOnEmpireMove(player.empire, resource);
|
|
296
|
+
}
|
|
454
297
|
}
|
|
455
|
-
finally { if (e_2) throw e_2.error; }
|
|
456
298
|
}
|
|
457
299
|
return;
|
|
458
300
|
}
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
var moves = [];
|
|
301
|
+
export function getLegalMoves(player, phase) {
|
|
302
|
+
const moves = [];
|
|
462
303
|
switch (phase) {
|
|
463
|
-
case
|
|
304
|
+
case Phase.Draft:
|
|
464
305
|
if (player.chosenCard === undefined) {
|
|
465
|
-
player.hand.forEach(
|
|
306
|
+
player.hand.forEach(card => moves.push(chooseDevelopmentCardMove(player.empire, card)));
|
|
466
307
|
}
|
|
467
308
|
break;
|
|
468
|
-
case
|
|
469
|
-
player.draftArea.forEach(
|
|
309
|
+
case Phase.Planning:
|
|
310
|
+
player.draftArea.forEach(card => moves.push(slateForConstructionMove(player.empire, card), recycleMove(player.empire, card)));
|
|
470
311
|
if (!player.draftArea.length && !player.availableResources.length && !player.ready) {
|
|
471
|
-
moves.push(
|
|
312
|
+
moves.push(tellYouAreReadyMove(player.empire));
|
|
472
313
|
}
|
|
473
314
|
break;
|
|
474
|
-
case
|
|
315
|
+
case Phase.Production:
|
|
475
316
|
if (!player.bonuses.length && !player.availableResources.length && !player.ready) {
|
|
476
|
-
moves.push(
|
|
317
|
+
moves.push(tellYouAreReadyMove(player.empire));
|
|
477
318
|
}
|
|
478
319
|
break;
|
|
479
320
|
}
|
|
480
|
-
|
|
481
|
-
player.constructionArea.forEach(
|
|
482
|
-
getSpacesMissingItem(construction,
|
|
483
|
-
.forEach(
|
|
321
|
+
[...new Set(player.availableResources)].forEach(resource => {
|
|
322
|
+
player.constructionArea.forEach(construction => {
|
|
323
|
+
getSpacesMissingItem(construction, item => item === resource)
|
|
324
|
+
.forEach(space => moves.push(placeResourceOnConstructionMove(player.empire, resource, construction.card, space)));
|
|
484
325
|
});
|
|
485
|
-
moves.push(
|
|
326
|
+
moves.push(placeResourceOnEmpireMove(player.empire, resource));
|
|
486
327
|
});
|
|
487
|
-
if (player.bonuses.some(
|
|
488
|
-
|
|
328
|
+
if (player.bonuses.some(bonus => bonus === ChooseCharacter)) {
|
|
329
|
+
characters.forEach(character => moves.push(receiveCharacterMove(player.empire, character)));
|
|
489
330
|
}
|
|
490
|
-
player.constructionArea.forEach(
|
|
491
|
-
moves.push(
|
|
331
|
+
player.constructionArea.forEach(construction => {
|
|
332
|
+
moves.push(recycleMove(player.empire, construction.card));
|
|
492
333
|
});
|
|
493
|
-
if (player.empireCardResources.some(
|
|
494
|
-
player.constructionArea.forEach(
|
|
495
|
-
getSpacesMissingItem(construction,
|
|
496
|
-
.forEach(
|
|
334
|
+
if (player.empireCardResources.some(resource => resource === Resource.Krystallium)) {
|
|
335
|
+
player.constructionArea.forEach(construction => {
|
|
336
|
+
getSpacesMissingItem(construction, item => isResource(item))
|
|
337
|
+
.forEach(space => moves.push(placeResourceOnConstructionMove(player.empire, Resource.Krystallium, construction.card, space)));
|
|
497
338
|
});
|
|
498
339
|
}
|
|
499
|
-
|
|
340
|
+
characters.forEach(character => {
|
|
500
341
|
if (player.characters[character]) {
|
|
501
|
-
player.constructionArea.forEach(
|
|
502
|
-
getSpacesMissingItem(construction,
|
|
503
|
-
.forEach(
|
|
342
|
+
player.constructionArea.forEach(construction => {
|
|
343
|
+
getSpacesMissingItem(construction, item => item === character)
|
|
344
|
+
.forEach(space => moves.push(placeCharacterMove(player.empire, character, construction.card, space)));
|
|
504
345
|
});
|
|
505
346
|
}
|
|
506
347
|
});
|
|
507
348
|
return moves;
|
|
508
349
|
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
350
|
+
export function getCost(card) {
|
|
351
|
+
const development = getCardDetails(card);
|
|
352
|
+
return Array.of(...resources, ...characters)
|
|
353
|
+
.flatMap(item => Array(development.constructionCost[item] || 0).fill(item));
|
|
513
354
|
}
|
|
514
|
-
|
|
515
|
-
function getRemainingCost(construction) {
|
|
355
|
+
export function getRemainingCost(construction) {
|
|
516
356
|
return getCost(construction.card)
|
|
517
|
-
.map(
|
|
518
|
-
.filter(
|
|
357
|
+
.map((item, index) => ({ item, space: index }))
|
|
358
|
+
.filter(item => !construction.costSpaces[item.space]);
|
|
519
359
|
}
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
return getRemainingCost(construction).filter(function (cost) { return predicate(cost.item); }).map(function (cost) { return cost.space; });
|
|
360
|
+
export function getSpacesMissingItem(construction, predicate) {
|
|
361
|
+
return getRemainingCost(construction).filter(cost => predicate(cost.item)).map(cost => cost.space);
|
|
523
362
|
}
|
|
524
|
-
|
|
525
|
-
function couldPlaceResource(construction, resource) {
|
|
363
|
+
export function couldPlaceResource(construction, resource) {
|
|
526
364
|
return Array.from(getCost(construction.card).entries())
|
|
527
|
-
.some(
|
|
528
|
-
var _b = __read(_a, 2), space = _b[0], item = _b[1];
|
|
529
|
-
return resource === item && (!construction.costSpaces[space] || construction.costSpaces[space] === Resource_1.default.Krystallium);
|
|
530
|
-
});
|
|
365
|
+
.some(([space, item]) => resource === item && (!construction.costSpaces[space] || construction.costSpaces[space] === Resource.Krystallium));
|
|
531
366
|
}
|
|
532
|
-
|
|
533
|
-
function getNextProductionStep(game) {
|
|
367
|
+
export function getNextProductionStep(game) {
|
|
534
368
|
switch (game.productionStep) {
|
|
535
|
-
case
|
|
536
|
-
return
|
|
537
|
-
case
|
|
538
|
-
return
|
|
539
|
-
case
|
|
540
|
-
return
|
|
541
|
-
case
|
|
542
|
-
return
|
|
369
|
+
case Resource.Materials:
|
|
370
|
+
return Resource.Energy;
|
|
371
|
+
case Resource.Energy:
|
|
372
|
+
return Resource.Science;
|
|
373
|
+
case Resource.Science:
|
|
374
|
+
return Resource.Gold;
|
|
375
|
+
case Resource.Gold:
|
|
376
|
+
return Resource.Exploration;
|
|
543
377
|
default:
|
|
544
378
|
return undefined;
|
|
545
379
|
}
|
|
546
380
|
}
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
var construction = player.constructionArea.find(function (construction) { return construction.card === card; });
|
|
381
|
+
export function canBuild(player, card) {
|
|
382
|
+
const construction = player.constructionArea.find(construction => construction.card === card);
|
|
550
383
|
if (!construction) {
|
|
551
384
|
return false;
|
|
552
385
|
}
|
|
553
|
-
return canPay(player, getRemainingCost(construction).map(
|
|
386
|
+
return canPay(player, getRemainingCost(construction).map(cost => cost.item));
|
|
554
387
|
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
if (player.characters[character] < cost.filter(function (item) { return item === character; }).length) {
|
|
560
|
-
return { value: false };
|
|
561
|
-
}
|
|
562
|
-
};
|
|
563
|
-
try {
|
|
564
|
-
for (var characters_1 = __values(Character_1.characters), characters_1_1 = characters_1.next(); !characters_1_1.done; characters_1_1 = characters_1.next()) {
|
|
565
|
-
var character = characters_1_1.value;
|
|
566
|
-
var state_2 = _loop_2(character);
|
|
567
|
-
if (typeof state_2 === "object")
|
|
568
|
-
return state_2.value;
|
|
388
|
+
export function canPay(player, cost) {
|
|
389
|
+
for (const character of characters) {
|
|
390
|
+
if (player.characters[character] < cost.filter(item => item === character).length) {
|
|
391
|
+
return false;
|
|
569
392
|
}
|
|
570
393
|
}
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
var krystalliumLeft = player.empireCardResources.filter(function (resource) { return resource === Resource_1.default.Krystallium; }).length;
|
|
579
|
-
var _loop_3 = function (resource) {
|
|
580
|
-
var resourceCost = cost.filter(function (item) { return item === resource; }).length;
|
|
581
|
-
var resources_2 = player.availableResources.filter(function (r) { return r === resource; }).length;
|
|
582
|
-
if (resources_2 < resourceCost) {
|
|
583
|
-
if (krystalliumLeft + resources_2 < resourceCost) {
|
|
584
|
-
return { value: false };
|
|
394
|
+
let krystalliumLeft = player.empireCardResources.filter(resource => resource === Resource.Krystallium).length;
|
|
395
|
+
for (const resource of resources) {
|
|
396
|
+
const resourceCost = cost.filter(item => item === resource).length;
|
|
397
|
+
const resources = player.availableResources.filter(r => r === resource).length;
|
|
398
|
+
if (resources < resourceCost) {
|
|
399
|
+
if (krystalliumLeft + resources < resourceCost) {
|
|
400
|
+
return false;
|
|
585
401
|
}
|
|
586
|
-
krystalliumLeft -= resourceCost -
|
|
402
|
+
krystalliumLeft -= resourceCost - resources;
|
|
587
403
|
}
|
|
588
|
-
};
|
|
589
|
-
try {
|
|
590
|
-
for (var resources_1 = __values(Resource_1.resources), resources_1_1 = resources_1.next(); !resources_1_1.done; resources_1_1 = resources_1.next()) {
|
|
591
|
-
var resource = resources_1_1.value;
|
|
592
|
-
var state_3 = _loop_3(resource);
|
|
593
|
-
if (typeof state_3 === "object")
|
|
594
|
-
return state_3.value;
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
598
|
-
finally {
|
|
599
|
-
try {
|
|
600
|
-
if (resources_1_1 && !resources_1_1.done && (_b = resources_1.return)) _b.call(resources_1);
|
|
601
|
-
}
|
|
602
|
-
finally { if (e_6) throw e_6.error; }
|
|
603
404
|
}
|
|
604
405
|
return true;
|
|
605
406
|
}
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
for (var resourceCosts_1 = (e_9 = void 0, __values(resourceCosts)), resourceCosts_1_1 = resourceCosts_1.next(); !resourceCosts_1_1.done; resourceCosts_1_1 = resourceCosts_1.next()) {
|
|
619
|
-
var cost = resourceCosts_1_1.value;
|
|
620
|
-
if (resources_4 > 0) {
|
|
621
|
-
moves.push((0, PlaceResource_1.placeResourceOnConstructionMove)(player.empire, resource, card, cost.space));
|
|
622
|
-
resources_4--;
|
|
623
|
-
}
|
|
624
|
-
else {
|
|
625
|
-
moves.push((0, PlaceResource_1.placeResourceOnConstructionMove)(player.empire, Resource_1.default.Krystallium, card, cost.space));
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
630
|
-
finally {
|
|
631
|
-
try {
|
|
632
|
-
if (resourceCosts_1_1 && !resourceCosts_1_1.done && (_c = resourceCosts_1.return)) _c.call(resourceCosts_1);
|
|
407
|
+
export function getMovesToBuild(player, card) {
|
|
408
|
+
const moves = [];
|
|
409
|
+
const construction = player.constructionArea.find(construction => construction.card === card)
|
|
410
|
+
|| { card, costSpaces: Array(totalCost(getCardDetails(card))).fill(null) };
|
|
411
|
+
const remainingCost = getRemainingCost(construction);
|
|
412
|
+
for (const resource of resources) {
|
|
413
|
+
const resourceCosts = remainingCost.filter(cost => cost.item === resource);
|
|
414
|
+
let resources = player.availableResources.filter(r => r === resource).length;
|
|
415
|
+
for (const cost of resourceCosts) {
|
|
416
|
+
if (resources > 0) {
|
|
417
|
+
moves.push(placeResourceOnConstructionMove(player.empire, resource, card, cost.space));
|
|
418
|
+
resources--;
|
|
633
419
|
}
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
};
|
|
637
|
-
try {
|
|
638
|
-
for (var resources_3 = __values(Resource_1.resources), resources_3_1 = resources_3.next(); !resources_3_1.done; resources_3_1 = resources_3.next()) {
|
|
639
|
-
var resource = resources_3_1.value;
|
|
640
|
-
_loop_4(resource);
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
644
|
-
finally {
|
|
645
|
-
try {
|
|
646
|
-
if (resources_3_1 && !resources_3_1.done && (_a = resources_3.return)) _a.call(resources_3);
|
|
647
|
-
}
|
|
648
|
-
finally { if (e_7) throw e_7.error; }
|
|
649
|
-
}
|
|
650
|
-
try {
|
|
651
|
-
for (var remainingCost_1 = __values(remainingCost), remainingCost_1_1 = remainingCost_1.next(); !remainingCost_1_1.done; remainingCost_1_1 = remainingCost_1.next()) {
|
|
652
|
-
var cost = remainingCost_1_1.value;
|
|
653
|
-
if ((0, Character_1.isCharacter)(cost.item)) {
|
|
654
|
-
moves.push((0, PlaceCharacter_1.placeCharacterMove)(player.empire, cost.item, card, cost.space));
|
|
420
|
+
else {
|
|
421
|
+
moves.push(placeResourceOnConstructionMove(player.empire, Resource.Krystallium, card, cost.space));
|
|
655
422
|
}
|
|
656
423
|
}
|
|
657
424
|
}
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
if (remainingCost_1_1 && !remainingCost_1_1.done && (_b = remainingCost_1.return)) _b.call(remainingCost_1);
|
|
425
|
+
for (const cost of remainingCost) {
|
|
426
|
+
if (isCharacter(cost.item)) {
|
|
427
|
+
moves.push(placeCharacterMove(player.empire, cost.item, card, cost.space));
|
|
662
428
|
}
|
|
663
|
-
finally { if (e_8) throw e_8.error; }
|
|
664
429
|
}
|
|
665
430
|
return moves;
|
|
666
431
|
}
|
|
667
|
-
|
|
668
|
-
function isPlaceItemOnCard(move, card) {
|
|
432
|
+
export function isPlaceItemOnCard(move, card) {
|
|
669
433
|
if (card !== undefined) {
|
|
670
434
|
return isPlaceItemOnCard(move) && move.card === card;
|
|
671
435
|
}
|
|
672
436
|
else {
|
|
673
|
-
return
|
|
437
|
+
return isPlaceResourceOnConstruction(move) || isPlaceCharacter(move);
|
|
674
438
|
}
|
|
675
439
|
}
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
var player = game.players.find(function (player) { return player.empire === playerId; });
|
|
440
|
+
export function isActive(game, playerId) {
|
|
441
|
+
const player = game.players.find(player => player.empire === playerId);
|
|
679
442
|
switch (game.phase) {
|
|
680
|
-
case
|
|
681
|
-
return
|
|
682
|
-
case
|
|
683
|
-
case
|
|
443
|
+
case Phase.Draft:
|
|
444
|
+
return isPlayerView(player) ? !player.ready : player.chosenCard === undefined;
|
|
445
|
+
case Phase.Planning:
|
|
446
|
+
case Phase.Production:
|
|
684
447
|
return !player.ready;
|
|
685
448
|
}
|
|
686
449
|
}
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
return player.characters[Character_1.default.Financier] + player.characters[Character_1.default.General];
|
|
450
|
+
export function countCharacters(player) {
|
|
451
|
+
return player.characters[Character.Financier] + player.characters[Character.General];
|
|
690
452
|
}
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
return game.round === exports.numberOfRounds && game.phase === Phase_1.default.Production && game.productionStep === Resource_1.default.Exploration && game.players.every(function (player) { return player.ready; });
|
|
453
|
+
export function isOver(game) {
|
|
454
|
+
return game.round === numberOfRounds && game.phase === Phase.Production && game.productionStep === Resource.Exploration && game.players.every(player => player.ready);
|
|
694
455
|
}
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
return player.constructionArea.filter(function (construction) { return getRemainingCost(construction).some(function (cost) { return (0, Resource_1.isResource)(cost.item) && player.availableResources.includes(cost.item); }); });
|
|
456
|
+
export function constructionsThatMayReceiveCubes(player) {
|
|
457
|
+
return player.constructionArea.filter(construction => getRemainingCost(construction).some(cost => isResource(cost.item) && player.availableResources.includes(cost.item)));
|
|
698
458
|
}
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
availableResource.splice(availableResource.findIndex(function (resource) { return resource === cost.item; }), 1);
|
|
459
|
+
export function placeAvailableCubesMoves(player, construction) {
|
|
460
|
+
const moves = [];
|
|
461
|
+
const availableResource = JSON.parse(JSON.stringify(player.availableResources));
|
|
462
|
+
getRemainingCost(construction).forEach(cost => {
|
|
463
|
+
if (isResource(cost.item)) {
|
|
464
|
+
if (availableResource.some(resource => resource === cost.item)) {
|
|
465
|
+
moves.push(placeResourceOnConstructionMove(player.empire, cost.item, construction.card, cost.space));
|
|
466
|
+
availableResource.splice(availableResource.findIndex(resource => resource === cost.item), 1);
|
|
708
467
|
}
|
|
709
468
|
}
|
|
710
469
|
});
|
|
711
470
|
return moves;
|
|
712
471
|
}
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
var player = state.players.find(function (player) { return player.empire === playerId; });
|
|
472
|
+
export function isTurnToPlay(state, playerId) {
|
|
473
|
+
const player = state.players.find(player => player.empire === playerId);
|
|
716
474
|
if (!player)
|
|
717
475
|
return false;
|
|
718
476
|
switch (state.phase) {
|
|
719
|
-
case
|
|
720
|
-
if (
|
|
477
|
+
case Phase.Draft:
|
|
478
|
+
if (isPlayerView(player)) {
|
|
721
479
|
return !player.ready;
|
|
722
480
|
}
|
|
723
481
|
else {
|
|
724
482
|
return player.chosenCard === undefined && player.hand.length > 0;
|
|
725
483
|
}
|
|
726
|
-
case
|
|
727
|
-
case
|
|
484
|
+
case Phase.Planning:
|
|
485
|
+
case Phase.Production:
|
|
728
486
|
return !player.ready;
|
|
729
487
|
}
|
|
730
488
|
}
|
|
731
|
-
exports.isTurnToPlay = isTurnToPlay;
|