@gamepark/odin 1.0.0 → 1.1.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/OdinOptions.js +1 -4
- package/dist/OdinRules.js +47 -73
- package/dist/OdinSetup.js +18 -43
- package/dist/PlayerId.js +1 -2
- package/dist/index.js +3 -9
- package/dist/material/Card.js +6 -11
- package/dist/material/LocationType.js +4 -7
- package/dist/material/MaterialType.js +2 -5
- package/dist/rules/BasePlayerTurn.js +15 -51
- package/dist/rules/ChangePlayerRule.js +21 -53
- package/dist/rules/CustomMoveType.js +2 -5
- package/dist/rules/DealCardsRule.js +40 -119
- package/dist/rules/EndOfRoundRule.js +48 -145
- package/dist/rules/Memory.js +2 -5
- package/dist/rules/PickCardRule.js +30 -87
- package/dist/rules/PlayCardsRule.js +110 -243
- package/dist/rules/RuleId.js +2 -5
- package/dist/rules/Sort.js +2 -5
- package/dist/rules/helper/EndHelper.js +6 -35
- package/dist/rules/helper/ScoreHelper.js +17 -46
- package/dist/rules/helper/SortHelper.js +6 -34
- package/package.json +3 -2
|
@@ -1,286 +1,153 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (!m) return o;
|
|
20
|
-
var i = m.call(o), r, ar = [], e;
|
|
21
|
-
try {
|
|
22
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
23
|
-
}
|
|
24
|
-
catch (error) { e = { error: error }; }
|
|
25
|
-
finally {
|
|
26
|
-
try {
|
|
27
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
28
|
-
}
|
|
29
|
-
finally { if (e) throw e.error; }
|
|
30
|
-
}
|
|
31
|
-
return ar;
|
|
32
|
-
};
|
|
33
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
34
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
35
|
-
if (ar || !(i in from)) {
|
|
36
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
37
|
-
ar[i] = from[i];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
41
|
-
};
|
|
42
|
-
var __values = (this && this.__values) || function(o) {
|
|
43
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
44
|
-
if (m) return m.call(o);
|
|
45
|
-
if (o && typeof o.length === "number") return {
|
|
46
|
-
next: function () {
|
|
47
|
-
if (o && i >= o.length) o = void 0;
|
|
48
|
-
return { value: o && o[i++], done: !o };
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
52
|
-
};
|
|
53
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
|
-
};
|
|
56
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
-
exports.PlayCardsRule = void 0;
|
|
58
|
-
var rules_api_1 = require("@gamepark/rules-api");
|
|
59
|
-
var groupBy_1 = __importDefault(require("lodash/groupBy"));
|
|
60
|
-
var isEqual_1 = __importDefault(require("lodash/isEqual"));
|
|
61
|
-
var orderBy_1 = __importDefault(require("lodash/orderBy"));
|
|
62
|
-
var uniqWith_1 = __importDefault(require("lodash/uniqWith"));
|
|
63
|
-
var Card_1 = require("../material/Card");
|
|
64
|
-
var LocationType_1 = require("../material/LocationType");
|
|
65
|
-
var MaterialType_1 = require("../material/MaterialType");
|
|
66
|
-
var BasePlayerTurn_1 = require("./BasePlayerTurn");
|
|
67
|
-
var CustomMoveType_1 = require("./CustomMoveType");
|
|
68
|
-
var SortHelper_1 = require("./helper/SortHelper");
|
|
69
|
-
var Memory_1 = require("./Memory");
|
|
70
|
-
var RuleId_1 = require("./RuleId");
|
|
71
|
-
var PlayCardsRule = (function (_super) {
|
|
72
|
-
__extends(PlayCardsRule, _super);
|
|
73
|
-
function PlayCardsRule() {
|
|
74
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
75
|
-
}
|
|
76
|
-
PlayCardsRule.prototype.onRuleStart = function () {
|
|
77
|
-
var table = this.table;
|
|
78
|
-
var tableSize = table.length;
|
|
79
|
-
var hand = this.playableCards;
|
|
1
|
+
import { isCustomMoveType, isMoveItemTypeAtOnce } from '@gamepark/rules-api';
|
|
2
|
+
import groupBy from 'lodash/groupBy';
|
|
3
|
+
import isEqual from 'lodash/isEqual';
|
|
4
|
+
import orderBy from 'lodash/orderBy';
|
|
5
|
+
import uniqWith from 'lodash/uniqWith';
|
|
6
|
+
import { getCardValue } from '../material/Card';
|
|
7
|
+
import { LocationType, MiddleOfTable } from '../material/LocationType';
|
|
8
|
+
import { MaterialType } from '../material/MaterialType';
|
|
9
|
+
import { BasePlayerTurn } from './BasePlayerTurn';
|
|
10
|
+
import { CustomMoveType } from './CustomMoveType';
|
|
11
|
+
import { SortHelper } from './helper/SortHelper';
|
|
12
|
+
import { Memory } from './Memory';
|
|
13
|
+
import { RuleId } from './RuleId';
|
|
14
|
+
export class PlayCardsRule extends BasePlayerTurn {
|
|
15
|
+
onRuleStart() {
|
|
16
|
+
const table = this.table;
|
|
17
|
+
const tableSize = table.length;
|
|
18
|
+
const hand = this.playableCards;
|
|
80
19
|
if (hand.length < tableSize) {
|
|
81
|
-
return [this.customMove(
|
|
20
|
+
return [this.customMove(CustomMoveType.Pass)];
|
|
82
21
|
}
|
|
83
22
|
return [];
|
|
84
|
-
}
|
|
85
|
-
|
|
23
|
+
}
|
|
24
|
+
getPlayerMoves() {
|
|
86
25
|
return this.getAvailableMoves();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
26
|
+
}
|
|
27
|
+
getAvailableMoves() {
|
|
28
|
+
const playableCards = this.playableCards;
|
|
29
|
+
const table = this.table;
|
|
30
|
+
const tableSize = table.length;
|
|
31
|
+
const moves = [];
|
|
32
|
+
const combinations = this.getPlayableCombinations(playableCards.getItems().map((item) => item.id), tableSize, this.tableValue);
|
|
33
|
+
const allHandCombination = this.getPlayableCombinations(playableCards.getItems().map((item) => item.id), playableCards.length, this.tableValue);
|
|
34
|
+
const sortHelper = new SortHelper(this.game);
|
|
96
35
|
if (allHandCombination.length) {
|
|
97
|
-
moves.push
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
});
|
|
105
|
-
})), false));
|
|
36
|
+
moves.push(...allHandCombination.map((c) => playableCards
|
|
37
|
+
.id((id) => c.includes(id))
|
|
38
|
+
.sort(...sortHelper.sortByValue)
|
|
39
|
+
.moveItemsAtOnce({
|
|
40
|
+
type: LocationType.MiddleOfTable,
|
|
41
|
+
id: MiddleOfTable.Next
|
|
42
|
+
})));
|
|
106
43
|
}
|
|
107
|
-
moves.push
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
});
|
|
115
|
-
})), false));
|
|
44
|
+
moves.push(...combinations.map((c) => playableCards
|
|
45
|
+
.id((id) => c.includes(id))
|
|
46
|
+
.sort(...sortHelper.sortByValue)
|
|
47
|
+
.moveItemsAtOnce({
|
|
48
|
+
type: LocationType.MiddleOfTable,
|
|
49
|
+
id: MiddleOfTable.Next
|
|
50
|
+
})));
|
|
116
51
|
if (table.length) {
|
|
117
|
-
moves.push(this.customMove(
|
|
52
|
+
moves.push(this.customMove(CustomMoveType.Pass));
|
|
118
53
|
}
|
|
119
54
|
return moves;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
configurable: true
|
|
128
|
-
});
|
|
129
|
-
PlayCardsRule.prototype.onCustomMove = function (move) {
|
|
130
|
-
if (!(0, rules_api_1.isCustomMoveType)(CustomMoveType_1.CustomMoveType.Pass)(move))
|
|
55
|
+
}
|
|
56
|
+
get tableValue() {
|
|
57
|
+
const table = this.table;
|
|
58
|
+
return !table.length ? 0 : this.concatCardValue(table.getItems().map((item) => item.id));
|
|
59
|
+
}
|
|
60
|
+
onCustomMove(move) {
|
|
61
|
+
if (!isCustomMoveType(CustomMoveType.Pass)(move))
|
|
131
62
|
return [];
|
|
132
|
-
|
|
133
|
-
|
|
63
|
+
const moves = [];
|
|
64
|
+
const nextTable = this.nextTable;
|
|
134
65
|
if (nextTable.length) {
|
|
135
66
|
moves.push(nextTable.moveItemsAtOnce({
|
|
136
|
-
type:
|
|
67
|
+
type: LocationType.Hand,
|
|
137
68
|
player: this.player
|
|
138
69
|
}));
|
|
139
70
|
}
|
|
140
|
-
moves.push
|
|
71
|
+
moves.push(...this.goToNextPlayer());
|
|
141
72
|
return moves;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if (!
|
|
73
|
+
}
|
|
74
|
+
afterItemMove(move) {
|
|
75
|
+
if (!isMoveItemTypeAtOnce(MaterialType.Card)(move) || move.location.type !== LocationType.MiddleOfTable)
|
|
145
76
|
return [];
|
|
146
|
-
|
|
147
|
-
this.memorize(
|
|
77
|
+
const moves = [];
|
|
78
|
+
this.memorize(Memory.LastPlayerThatPlay, this.player);
|
|
148
79
|
if (this.hand.length > 0) {
|
|
149
|
-
moves.push(this.customMove(
|
|
80
|
+
moves.push(this.customMove(CustomMoveType.TurnTempo));
|
|
150
81
|
}
|
|
151
|
-
moves.push(this.startRule(
|
|
82
|
+
moves.push(this.startRule(RuleId.PickCard));
|
|
152
83
|
return moves;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
84
|
+
}
|
|
85
|
+
goToNextPlayer() {
|
|
86
|
+
const next = this.nextPlayer;
|
|
87
|
+
const moves = [];
|
|
88
|
+
const lastPlayerThatPlay = this.remind(Memory.LastPlayerThatPlay);
|
|
158
89
|
if (lastPlayerThatPlay && next === lastPlayerThatPlay) {
|
|
159
|
-
this.forget(
|
|
160
|
-
|
|
90
|
+
this.forget(Memory.LastPlayerThatPlay);
|
|
91
|
+
const table = this.table;
|
|
161
92
|
if (table.length) {
|
|
162
93
|
moves.push(this.table.moveItemsAtOnce({
|
|
163
|
-
type:
|
|
94
|
+
type: LocationType.Discard
|
|
164
95
|
}));
|
|
165
96
|
}
|
|
166
|
-
moves.push(this.startRule(
|
|
97
|
+
moves.push(this.startRule(RuleId.ChangePlayer));
|
|
167
98
|
}
|
|
168
99
|
else {
|
|
169
|
-
moves.push(this.startPlayerTurn(
|
|
100
|
+
moves.push(this.startPlayerTurn(RuleId.PlayCards, this.nextPlayer));
|
|
170
101
|
}
|
|
171
102
|
return moves;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
return this.material(MaterialType_1.MaterialType.Card).location(LocationType_1.LocationType.MiddleOfTable).locationId(LocationType_1.MiddleOfTable.Next);
|
|
190
|
-
},
|
|
191
|
-
enumerable: false,
|
|
192
|
-
configurable: true
|
|
193
|
-
});
|
|
194
|
-
Object.defineProperty(PlayCardsRule.prototype, "playableCards", {
|
|
195
|
-
get: function () {
|
|
196
|
-
var _this = this;
|
|
197
|
-
return this.material(MaterialType_1.MaterialType.Card).location(function (l) { return (l.type === LocationType_1.LocationType.Hand && l.player === _this.player) || (l.type === LocationType_1.LocationType.MiddleOfTable && l.id === LocationType_1.MiddleOfTable.Next); });
|
|
198
|
-
},
|
|
199
|
-
enumerable: false,
|
|
200
|
-
configurable: true
|
|
201
|
-
});
|
|
202
|
-
Object.defineProperty(PlayCardsRule.prototype, "hand", {
|
|
203
|
-
get: function () {
|
|
204
|
-
return this.material(MaterialType_1.MaterialType.Card).location(LocationType_1.LocationType.Hand).player(this.player);
|
|
205
|
-
},
|
|
206
|
-
enumerable: false,
|
|
207
|
-
configurable: true
|
|
208
|
-
});
|
|
209
|
-
PlayCardsRule.prototype.kCombinations = function (arr, k) {
|
|
103
|
+
}
|
|
104
|
+
get firstPlayer() {
|
|
105
|
+
return this.remind(Memory.FirstPlayer);
|
|
106
|
+
}
|
|
107
|
+
get table() {
|
|
108
|
+
return this.material(MaterialType.Card).location(LocationType.MiddleOfTable).locationId(MiddleOfTable.Current);
|
|
109
|
+
}
|
|
110
|
+
get nextTable() {
|
|
111
|
+
return this.material(MaterialType.Card).location(LocationType.MiddleOfTable).locationId(MiddleOfTable.Next);
|
|
112
|
+
}
|
|
113
|
+
get playableCards() {
|
|
114
|
+
return this.material(MaterialType.Card).location((l) => (l.type === LocationType.Hand && l.player === this.player) || (l.type === LocationType.MiddleOfTable && l.id === MiddleOfTable.Next));
|
|
115
|
+
}
|
|
116
|
+
get hand() {
|
|
117
|
+
return this.material(MaterialType.Card).location(LocationType.Hand).player(this.player);
|
|
118
|
+
}
|
|
119
|
+
kCombinations(arr, k) {
|
|
210
120
|
if (k === 0)
|
|
211
121
|
return [[]];
|
|
212
122
|
if (arr.length < k)
|
|
213
123
|
return [];
|
|
214
124
|
if (arr.length === k)
|
|
215
125
|
return [arr];
|
|
216
|
-
|
|
217
|
-
return
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
|
|
126
|
+
const [first, ...rest] = arr;
|
|
127
|
+
return [...this.kCombinations(rest, k), ...this.kCombinations(rest, k - 1).map((comb) => [first, ...comb])];
|
|
128
|
+
}
|
|
129
|
+
concatCardValue(cards) {
|
|
130
|
+
const values = cards.map((card) => getCardValue(card)).sort((a, b) => getCardValue(b) - getCardValue(a));
|
|
221
131
|
return parseInt(values.join(''), 10);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
try {
|
|
235
|
-
for (var _j = (e_3 = void 0, __values([tableCount, tableCount + 1])), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
236
|
-
var count = _k.value;
|
|
237
|
-
if (cards.length >= count) {
|
|
238
|
-
try {
|
|
239
|
-
for (var _l = (e_4 = void 0, __values(this.kCombinations(cards, count))), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
240
|
-
var comb = _m.value;
|
|
241
|
-
if (this.concatCardValue(comb) > tableValue) {
|
|
242
|
-
results.push(comb);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
247
|
-
finally {
|
|
248
|
-
try {
|
|
249
|
-
if (_m && !_m.done && (_d = _l.return)) _d.call(_l);
|
|
250
|
-
}
|
|
251
|
-
finally { if (e_4) throw e_4.error; }
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
257
|
-
finally {
|
|
258
|
-
try {
|
|
259
|
-
if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
|
|
132
|
+
}
|
|
133
|
+
getPlayableCombinations(hand, tableCount, tableValue) {
|
|
134
|
+
const results = [];
|
|
135
|
+
const byColor = groupBy(hand, (card) => card % 10);
|
|
136
|
+
const byValue = groupBy(hand, (card) => Math.floor(card / 10));
|
|
137
|
+
for (const group of [byColor, byValue]) {
|
|
138
|
+
for (const cards of Object.values(group)) {
|
|
139
|
+
for (const count of [tableCount, tableCount + 1]) {
|
|
140
|
+
if (cards.length >= count) {
|
|
141
|
+
for (const comb of this.kCombinations(cards, count)) {
|
|
142
|
+
if (this.concatCardValue(comb) > tableValue) {
|
|
143
|
+
results.push(comb);
|
|
260
144
|
}
|
|
261
|
-
finally { if (e_3) throw e_3.error; }
|
|
262
145
|
}
|
|
263
146
|
}
|
|
264
147
|
}
|
|
265
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
266
|
-
finally {
|
|
267
|
-
try {
|
|
268
|
-
if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
|
|
269
|
-
}
|
|
270
|
-
finally { if (e_2) throw e_2.error; }
|
|
271
|
-
}
|
|
272
148
|
}
|
|
273
149
|
}
|
|
274
|
-
|
|
275
|
-
finally {
|
|
276
|
-
try {
|
|
277
|
-
if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
|
|
278
|
-
}
|
|
279
|
-
finally { if (e_1) throw e_1.error; }
|
|
280
|
-
}
|
|
281
|
-
var unique = (0, uniqWith_1.default)(results, function (a, b) { return (0, isEqual_1.default)((0, orderBy_1.default)(a), (0, orderBy_1.default)(b)); });
|
|
150
|
+
const unique = uniqWith(results, (a, b) => isEqual(orderBy(a), orderBy(b)));
|
|
282
151
|
return unique;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
}(BasePlayerTurn_1.BasePlayerTurn));
|
|
286
|
-
exports.PlayCardsRule = PlayCardsRule;
|
|
152
|
+
}
|
|
153
|
+
}
|
package/dist/rules/RuleId.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RuleId = void 0;
|
|
4
|
-
var RuleId;
|
|
1
|
+
export var RuleId;
|
|
5
2
|
(function (RuleId) {
|
|
6
3
|
RuleId[RuleId["PlayCards"] = 1] = "PlayCards";
|
|
7
4
|
RuleId[RuleId["PickCard"] = 2] = "PickCard";
|
|
8
5
|
RuleId[RuleId["EndOfRound"] = 3] = "EndOfRound";
|
|
9
6
|
RuleId[RuleId["DealCards"] = 4] = "DealCards";
|
|
10
7
|
RuleId[RuleId["ChangePlayer"] = 5] = "ChangePlayer";
|
|
11
|
-
})(RuleId
|
|
8
|
+
})(RuleId || (RuleId = {}));
|
package/dist/rules/Sort.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Sort = void 0;
|
|
4
|
-
var Sort;
|
|
1
|
+
export var Sort;
|
|
5
2
|
(function (Sort) {
|
|
6
3
|
Sort[Sort["Color"] = 1] = "Color";
|
|
7
4
|
Sort[Sort["ValueAsc"] = 2] = "ValueAsc";
|
|
8
5
|
Sort[Sort["ValueDesc"] = 3] = "ValueDesc";
|
|
9
|
-
})(Sort
|
|
6
|
+
})(Sort || (Sort = {}));
|
|
@@ -1,36 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.EndHelper = void 0;
|
|
19
|
-
var rules_api_1 = require("@gamepark/rules-api");
|
|
20
|
-
var ScoreHelper_1 = require("./ScoreHelper");
|
|
21
|
-
var EndHelper = (function (_super) {
|
|
22
|
-
__extends(EndHelper, _super);
|
|
23
|
-
function EndHelper() {
|
|
24
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
1
|
+
import { MaterialRulesPart } from '@gamepark/rules-api';
|
|
2
|
+
import { ScoreHelper } from './ScoreHelper';
|
|
3
|
+
export class EndHelper extends MaterialRulesPart {
|
|
4
|
+
get isEnded() {
|
|
5
|
+
return this.game.players.some((p) => new ScoreHelper(this.game, p).score >= 15);
|
|
25
6
|
}
|
|
26
|
-
|
|
27
|
-
get: function () {
|
|
28
|
-
var _this = this;
|
|
29
|
-
return this.game.players.some(function (p) { return new ScoreHelper_1.ScoreHelper(_this.game, p).score >= 15; });
|
|
30
|
-
},
|
|
31
|
-
enumerable: false,
|
|
32
|
-
configurable: true
|
|
33
|
-
});
|
|
34
|
-
return EndHelper;
|
|
35
|
-
}(rules_api_1.MaterialRulesPart));
|
|
36
|
-
exports.EndHelper = EndHelper;
|
|
7
|
+
}
|
|
@@ -1,48 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
-
};
|
|
20
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.ScoreHelper = void 0;
|
|
22
|
-
var rules_api_1 = require("@gamepark/rules-api");
|
|
23
|
-
var sum_1 = __importDefault(require("lodash/sum"));
|
|
24
|
-
var Memory_1 = require("../Memory");
|
|
25
|
-
var ScoreHelper = (function (_super) {
|
|
26
|
-
__extends(ScoreHelper, _super);
|
|
27
|
-
function ScoreHelper(game, player) {
|
|
28
|
-
var _this = _super.call(this, game) || this;
|
|
29
|
-
_this.player = player;
|
|
30
|
-
return _this;
|
|
1
|
+
import { MaterialRulesPart } from '@gamepark/rules-api';
|
|
2
|
+
import sum from 'lodash/sum';
|
|
3
|
+
import { Memory } from '../Memory';
|
|
4
|
+
export class ScoreHelper extends MaterialRulesPart {
|
|
5
|
+
player;
|
|
6
|
+
constructor(game, player) {
|
|
7
|
+
super(game);
|
|
8
|
+
this.player = player;
|
|
31
9
|
}
|
|
32
|
-
|
|
10
|
+
isWinningRound(round) {
|
|
33
11
|
return this.getRoundScore(round) === 0;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
ScoreHelper.prototype.getRoundScore = function (round) {
|
|
43
|
-
var _a;
|
|
44
|
-
return (_a = this.remind(Memory_1.Memory.PlayerScore, this.player)) === null || _a === void 0 ? void 0 : _a[round - 1];
|
|
45
|
-
};
|
|
46
|
-
return ScoreHelper;
|
|
47
|
-
}(rules_api_1.MaterialRulesPart));
|
|
48
|
-
exports.ScoreHelper = ScoreHelper;
|
|
12
|
+
}
|
|
13
|
+
get score() {
|
|
14
|
+
return sum(this.remind(Memory.PlayerScore, this.player));
|
|
15
|
+
}
|
|
16
|
+
getRoundScore(round) {
|
|
17
|
+
return this.remind(Memory.PlayerScore, this.player)?.[round - 1];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -1,35 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.SortHelper = void 0;
|
|
19
|
-
var rules_api_1 = require("@gamepark/rules-api");
|
|
20
|
-
var Card_1 = require("../../material/Card");
|
|
21
|
-
var SortHelper = (function (_super) {
|
|
22
|
-
__extends(SortHelper, _super);
|
|
23
|
-
function SortHelper() {
|
|
24
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
1
|
+
import { MaterialRulesPart } from '@gamepark/rules-api';
|
|
2
|
+
import { getCardColor, getCardValue } from '../../material/Card';
|
|
3
|
+
export class SortHelper extends MaterialRulesPart {
|
|
4
|
+
get sortByValue() {
|
|
5
|
+
return [(item) => -getCardValue(item.id), (item) => getCardColor(item.id)];
|
|
25
6
|
}
|
|
26
|
-
|
|
27
|
-
get: function () {
|
|
28
|
-
return [function (item) { return -(0, Card_1.getCardValue)(item.id); }, function (item) { return (0, Card_1.getCardColor)(item.id); }];
|
|
29
|
-
},
|
|
30
|
-
enumerable: false,
|
|
31
|
-
configurable: true
|
|
32
|
-
});
|
|
33
|
-
return SortHelper;
|
|
34
|
-
}(rules_api_1.MaterialRulesPart));
|
|
35
|
-
exports.SortHelper = SortHelper;
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gamepark/odin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "The rules of Odin adapted for Game Park",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"sideEffects": false,
|
|
6
7
|
"main": "dist/index.js",
|
|
7
8
|
"types": "dist/index.d.ts",
|
|
@@ -29,5 +30,5 @@
|
|
|
29
30
|
"i18next": "^22.0.3",
|
|
30
31
|
"lodash": "^4.17.21"
|
|
31
32
|
},
|
|
32
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "37b0ac0aa872e97847bbee028a8843f8bbc8591f"
|
|
33
34
|
}
|