@gamepark/odin 0.0.8 → 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.
@@ -1,161 +1,64 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
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
- var __read = (this && this.__read) || function (o, n) {
18
- var m = typeof Symbol === "function" && o[Symbol.iterator];
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.EndOfRoundRule = void 0;
58
- var rules_api_1 = require("@gamepark/rules-api");
59
- var sum_1 = __importDefault(require("lodash/sum"));
60
- var LocationType_1 = require("../material/LocationType");
61
- var MaterialType_1 = require("../material/MaterialType");
62
- var CustomMoveType_1 = require("./CustomMoveType");
63
- var Memory_1 = require("./Memory");
64
- var RuleId_1 = require("./RuleId");
65
- var EndOfRoundRule = (function (_super) {
66
- __extends(EndOfRoundRule, _super);
67
- function EndOfRoundRule() {
68
- return _super !== null && _super.apply(this, arguments) || this;
69
- }
70
- EndOfRoundRule.prototype.onRuleStart = function () {
71
- var moves = [this.customMove(CustomMoveType_1.CustomMoveType.TurnTempo, true)];
72
- moves.push.apply(moves, __spreadArray([], __read(this.onRoundEnd()), false));
1
+ import { isMoveItemTypeAtOnce, isShuffleItemType, MaterialRulesPart } from '@gamepark/rules-api';
2
+ import sum from 'lodash/sum';
3
+ import { LocationType } from '../material/LocationType';
4
+ import { MaterialType } from '../material/MaterialType';
5
+ import { CustomMoveType } from './CustomMoveType';
6
+ import { Memory } from './Memory';
7
+ import { RuleId } from './RuleId';
8
+ export class EndOfRoundRule extends MaterialRulesPart {
9
+ onRuleStart() {
10
+ const moves = [this.customMove(CustomMoveType.TurnTempo, true)];
11
+ moves.push(...this.onRoundEnd());
73
12
  if (moves.length === 1) {
74
- moves.push.apply(moves, __spreadArray([], __read(this.groupToDeckMove), false));
13
+ moves.push(...this.groupToDeckMove);
75
14
  }
76
15
  return moves;
77
- };
78
- EndOfRoundRule.prototype.onRoundEnd = function () {
79
- var e_1, _a;
80
- var ended = false;
81
- var _loop_1 = function (player) {
82
- var hand = this_1.material(MaterialType_1.MaterialType.Card).location(LocationType_1.LocationType.Hand).player(player);
83
- this_1.memorize(Memory_1.Memory.PlayerScore, function (s) {
84
- if (s === void 0) { s = []; }
85
- return __spreadArray(__spreadArray([], __read(s), false), [hand.length], false);
86
- }, player);
87
- var score = (0, sum_1.default)(this_1.remind(Memory_1.Memory.PlayerScore, player));
16
+ }
17
+ onRoundEnd() {
18
+ let ended = false;
19
+ for (const player of this.game.players) {
20
+ const hand = this.material(MaterialType.Card).location(LocationType.Hand).player(player);
21
+ this.memorize(Memory.PlayerScore, (s = []) => [...s, hand.length], player);
22
+ const score = sum(this.remind(Memory.PlayerScore, player));
88
23
  if (!ended && score >= 15)
89
24
  ended = true;
90
- };
91
- var this_1 = this;
92
- try {
93
- for (var _b = __values(this.game.players), _c = _b.next(); !_c.done; _c = _b.next()) {
94
- var player = _c.value;
95
- _loop_1(player);
96
- }
97
- }
98
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
99
- finally {
100
- try {
101
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
102
- }
103
- finally { if (e_1) throw e_1.error; }
104
25
  }
105
26
  if (!ended) {
106
- this.memorize(Memory_1.Memory.Round, function (r) {
27
+ this.memorize(Memory.Round, (r) => {
107
28
  return r + 1;
108
29
  });
109
30
  return [];
110
31
  }
111
32
  return [this.endGame()];
112
- };
113
- Object.defineProperty(EndOfRoundRule.prototype, "deck", {
114
- get: function () {
115
- return this.material(MaterialType_1.MaterialType.Card).location(LocationType_1.LocationType.Deck).deck();
116
- },
117
- enumerable: false,
118
- configurable: true
119
- });
120
- Object.defineProperty(EndOfRoundRule.prototype, "groupToDeckMove", {
121
- get: function () {
122
- var moves = [];
123
- moves.push(this.material(MaterialType_1.MaterialType.Card)
124
- .location(function (l) { return l.type !== LocationType_1.LocationType.Deck; })
125
- .moveItemsAtOnce({
126
- type: LocationType_1.LocationType.Deck
127
- }));
128
- return moves;
129
- },
130
- enumerable: false,
131
- configurable: true
132
- });
133
- EndOfRoundRule.prototype.afterItemMove = function (move) {
134
- var moves = [];
135
- if ((0, rules_api_1.isMoveItemTypeAtOnce)(MaterialType_1.MaterialType.Card)(move) && move.location.type === LocationType_1.LocationType.Deck) {
33
+ }
34
+ get deck() {
35
+ return this.material(MaterialType.Card).location(LocationType.Deck).deck();
36
+ }
37
+ get groupToDeckMove() {
38
+ const moves = [];
39
+ moves.push(this.material(MaterialType.Card)
40
+ .location((l) => l.type !== LocationType.Deck)
41
+ .moveItemsAtOnce({
42
+ type: LocationType.Deck
43
+ }));
44
+ return moves;
45
+ }
46
+ afterItemMove(move) {
47
+ const moves = [];
48
+ if (isMoveItemTypeAtOnce(MaterialType.Card)(move) && move.location.type === LocationType.Deck) {
136
49
  moves.push(this.deck.shuffle());
137
50
  }
138
- if ((0, rules_api_1.isShuffleItemType)(MaterialType_1.MaterialType.Card)(move)) {
139
- var newFirstPlayer = this.newFirstPlayer;
140
- this.memorize(Memory_1.Memory.FirstPlayer, newFirstPlayer);
141
- moves.push(this.startRule(RuleId_1.RuleId.DealCards));
51
+ if (isShuffleItemType(MaterialType.Card)(move)) {
52
+ const newFirstPlayer = this.newFirstPlayer;
53
+ this.memorize(Memory.FirstPlayer, newFirstPlayer);
54
+ moves.push(this.startRule(RuleId.DealCards));
142
55
  }
143
56
  return moves;
144
- };
145
- Object.defineProperty(EndOfRoundRule.prototype, "newFirstPlayer", {
146
- get: function () {
147
- return this.game.players[(this.game.players.indexOf(this.firstPlayer) + 1) % this.game.players.length];
148
- },
149
- enumerable: false,
150
- configurable: true
151
- });
152
- Object.defineProperty(EndOfRoundRule.prototype, "firstPlayer", {
153
- get: function () {
154
- return this.remind(Memory_1.Memory.FirstPlayer);
155
- },
156
- enumerable: false,
157
- configurable: true
158
- });
159
- return EndOfRoundRule;
160
- }(rules_api_1.MaterialRulesPart));
161
- exports.EndOfRoundRule = EndOfRoundRule;
57
+ }
58
+ get newFirstPlayer() {
59
+ return this.game.players[(this.game.players.indexOf(this.firstPlayer) + 1) % this.game.players.length];
60
+ }
61
+ get firstPlayer() {
62
+ return this.remind(Memory.FirstPlayer);
63
+ }
64
+ }
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Memory = void 0;
4
- var Memory;
1
+ export var Memory;
5
2
  (function (Memory) {
6
3
  Memory[Memory["PlayedCards"] = 1] = "PlayedCards";
7
4
  Memory[Memory["FirstPlayer"] = 2] = "FirstPlayer";
@@ -9,4 +6,4 @@ var Memory;
9
6
  Memory[Memory["HandSort"] = 4] = "HandSort";
10
7
  Memory[Memory["Round"] = 5] = "Round";
11
8
  Memory[Memory["PlayerScore"] = 6] = "PlayerScore";
12
- })(Memory = exports.Memory || (exports.Memory = {}));
9
+ })(Memory || (Memory = {}));
@@ -1,100 +1,43 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
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
- var __read = (this && this.__read) || function (o, n) {
18
- var m = typeof Symbol === "function" && o[Symbol.iterator];
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
- Object.defineProperty(exports, "__esModule", { value: true });
43
- exports.PickCardRule = void 0;
44
- var rules_api_1 = require("@gamepark/rules-api");
45
- var LocationType_1 = require("../material/LocationType");
46
- var MaterialType_1 = require("../material/MaterialType");
47
- var BasePlayerTurn_1 = require("./BasePlayerTurn");
48
- var CustomMoveType_1 = require("./CustomMoveType");
49
- var RuleId_1 = require("./RuleId");
50
- var PickCardRule = (function (_super) {
51
- __extends(PickCardRule, _super);
52
- function PickCardRule() {
53
- return _super !== null && _super.apply(this, arguments) || this;
54
- }
55
- PickCardRule.prototype.onRuleStart = function () {
1
+ import { isMoveItemType } from '@gamepark/rules-api';
2
+ import { LocationType, MiddleOfTable } from '../material/LocationType';
3
+ import { MaterialType } from '../material/MaterialType';
4
+ import { BasePlayerTurn } from './BasePlayerTurn';
5
+ import { CustomMoveType } from './CustomMoveType';
6
+ import { RuleId } from './RuleId';
7
+ export class PickCardRule extends BasePlayerTurn {
8
+ onRuleStart() {
56
9
  if (this.isEndOfRound) {
57
- return [this.startRule(RuleId_1.RuleId.EndOfRound)];
10
+ return [this.startRule(RuleId.EndOfRound)];
58
11
  }
59
- var moves = [this.customMove(CustomMoveType_1.CustomMoveType.TurnTempo)];
60
- var playerMoves = this.getPlayerMoves();
61
- if (playerMoves.length === 1 && (0, rules_api_1.isMoveItemType)(MaterialType_1.MaterialType.Card)(playerMoves[0]) && playerMoves[0].location.type === LocationType_1.LocationType.Hand) {
12
+ const moves = [this.customMove(CustomMoveType.TurnTempo)];
13
+ const playerMoves = this.getPlayerMoves();
14
+ if (playerMoves.length === 1 && isMoveItemType(MaterialType.Card)(playerMoves[0]) && playerMoves[0].location.type === LocationType.Hand) {
62
15
  moves.push(playerMoves[0]);
63
16
  return moves;
64
17
  }
65
18
  if (this.getPlayerMoves().length)
66
19
  return moves;
67
- moves.push.apply(moves, __spreadArray([], __read(this.goToNextRule()), false));
20
+ moves.push(...this.goToNextRule());
68
21
  return moves;
69
- };
70
- Object.defineProperty(PickCardRule.prototype, "isEndOfRound", {
71
- get: function () {
72
- return this.material(MaterialType_1.MaterialType.Card).location(LocationType_1.LocationType.Hand).player(this.player).length === 0;
73
- },
74
- enumerable: false,
75
- configurable: true
76
- });
77
- PickCardRule.prototype.getPlayerMoves = function () {
22
+ }
23
+ get isEndOfRound() {
24
+ return this.material(MaterialType.Card).location(LocationType.Hand).player(this.player).length === 0;
25
+ }
26
+ getPlayerMoves() {
78
27
  return this.currentTable.moveItems({
79
- type: LocationType_1.LocationType.Hand,
28
+ type: LocationType.Hand,
80
29
  player: this.player
81
30
  });
82
- };
83
- PickCardRule.prototype.afterItemMove = function (move) {
84
- if (!(0, rules_api_1.isMoveItemType)(MaterialType_1.MaterialType.Card)(move) || move.location.type !== LocationType_1.LocationType.Hand)
31
+ }
32
+ afterItemMove(move) {
33
+ if (!isMoveItemType(MaterialType.Card)(move) || move.location.type !== LocationType.Hand)
85
34
  return [];
86
35
  return this.goToNextRule();
87
- };
88
- PickCardRule.prototype.goToNextRule = function () {
89
- return [this.startRule(RuleId_1.RuleId.ChangePlayer)];
90
- };
91
- Object.defineProperty(PickCardRule.prototype, "currentTable", {
92
- get: function () {
93
- return this.material(MaterialType_1.MaterialType.Card).location(LocationType_1.LocationType.MiddleOfTable).locationId(LocationType_1.MiddleOfTable.Current);
94
- },
95
- enumerable: false,
96
- configurable: true
97
- });
98
- return PickCardRule;
99
- }(BasePlayerTurn_1.BasePlayerTurn));
100
- exports.PickCardRule = PickCardRule;
36
+ }
37
+ goToNextRule() {
38
+ return [this.startRule(RuleId.ChangePlayer)];
39
+ }
40
+ get currentTable() {
41
+ return this.material(MaterialType.Card).location(LocationType.MiddleOfTable).locationId(MiddleOfTable.Current);
42
+ }
43
+ }
@@ -11,6 +11,7 @@ export declare class PlayCardsRule extends BasePlayerTurn {
11
11
  goToNextPlayer(): MaterialMove<number, number, number, number>[];
12
12
  get firstPlayer(): number;
13
13
  get table(): import("@gamepark/rules-api").Material<number, number, number>;
14
+ get nextTable(): import("@gamepark/rules-api").Material<number, number, number>;
14
15
  get playableCards(): import("@gamepark/rules-api").Material<number, number, number>;
15
16
  get hand(): import("@gamepark/rules-api").Material<number, number, number>;
16
17
  kCombinations<T>(arr: T[], k: number): T[][];