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