@gamepark/rules-api 5.19.0 → 5.20.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/Action.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import Game from './Game';
2
1
  import { IncompleteInformation } from './index';
2
+ import Rules from './Rules';
3
3
  declare type Action<Move = any, PlayerId = any> = {
4
4
  id?: string;
5
5
  playerId: PlayerId;
@@ -7,7 +7,7 @@ declare type Action<Move = any, PlayerId = any> = {
7
7
  consequences: Move[];
8
8
  };
9
9
  export default Action;
10
- export declare function playAction<State, Move, PlayerId>(game: Game<State, Move>, move: Move, playerId: PlayerId, id?: string): Action<Move, PlayerId>;
10
+ export declare function playAction<State, Move, PlayerId>(rules: Rules<State, Move, PlayerId>, move: Move, playerId: PlayerId, id?: string): Action<Move, PlayerId>;
11
11
  export declare type ActionWithViews<Move = any, MoveView = Move, PlayerId = any> = {
12
12
  action: Action<Move, PlayerId>;
13
13
  views: ActionView<MoveView, PlayerId>[];
@@ -16,9 +16,9 @@ export declare type ActionView<MoveView = any, PlayerId = any> = {
16
16
  recipient?: PlayerId;
17
17
  action: Action<MoveView, PlayerId>;
18
18
  };
19
- export declare function playActionWithViews<State, View, Move, MoveView, PlayerId>(game: IncompleteInformation<State, View, Move, MoveView, PlayerId>, move: Move, playerId: PlayerId, recipients: PlayerId[], id?: string): ActionWithViews<Move, MoveView, PlayerId>;
20
- export declare function replayAction<State, Move, PlayerId>(game: Game<State, Move>, action: Action<Move, PlayerId>): void;
21
- export declare function replayActions<State, Move, PlayerId>(game: Game<State, Move>, actions: Action<Move, PlayerId>[]): void;
19
+ export declare function playActionWithViews<Game, View, Move, MoveView, PlayerId>(rules: Rules<Game, Move, PlayerId> & IncompleteInformation<View, Move, MoveView>, move: Move, playerId: PlayerId, recipients: PlayerId[], id?: string): ActionWithViews<Move, MoveView, PlayerId>;
20
+ export declare function replayAction<State, Move, PlayerId>(rules: Rules<State, Move, PlayerId>, action: Action<Move, PlayerId>): void;
21
+ export declare function replayActions<State, Move, PlayerId>(rules: Rules<State, Move, PlayerId>, actions: Action<Move, PlayerId>[]): void;
22
22
  export declare type SecretAction<Move = any, MoveView = Move, PlayerId = any> = Action<Move, PlayerId> & {
23
23
  secrets: ActionView<MoveView, PlayerId>[];
24
24
  };
package/dist/Action.js CHANGED
@@ -1,22 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isSecretAction = exports.replayActions = exports.replayAction = exports.playActionWithViews = exports.playAction = void 0;
4
- var Game_1 = require("./Game");
5
4
  var index_1 = require("./index");
6
5
  var RandomMove_1 = require("./RandomMove");
7
- function playAction(game, move, playerId, id) {
8
- if ((0, RandomMove_1.hasRandomMove)(game)) {
9
- move = game.randomize(move);
6
+ var ApplyAutomaticMoves_1 = require("./ApplyAutomaticMoves");
7
+ function playAction(rules, move, playerId, id) {
8
+ if ((0, RandomMove_1.hasRandomMove)(rules)) {
9
+ move = rules.randomize(move);
10
10
  }
11
11
  var action = { id: id, playerId: playerId, move: move, consequences: [] };
12
- game.play(JSON.parse(JSON.stringify(move)));
13
- (0, Game_1.applyAutomaticMoves)(game, function (move) { return action.consequences.push(move); });
12
+ rules.play(JSON.parse(JSON.stringify(move)));
13
+ (0, ApplyAutomaticMoves_1.applyAutomaticMoves)(rules, function (move) { return action.consequences.push(move); });
14
14
  return action;
15
15
  }
16
16
  exports.playAction = playAction;
17
- function playActionWithViews(game, move, playerId, recipients, id) {
18
- if ((0, RandomMove_1.hasRandomMove)(game)) {
19
- move = game.randomize(move);
17
+ function playActionWithViews(rules, move, playerId, recipients, id) {
18
+ if ((0, RandomMove_1.hasRandomMove)(rules)) {
19
+ move = rules.randomize(move);
20
20
  }
21
21
  var actionWithView = {
22
22
  action: { id: id, playerId: playerId, move: move, consequences: [] },
@@ -25,28 +25,28 @@ function playActionWithViews(game, move, playerId, recipients, id) {
25
25
  // Prepare action view for each player
26
26
  for (var _i = 0, recipients_1 = recipients; _i < recipients_1.length; _i++) {
27
27
  var recipient = recipients_1[_i];
28
- actionWithView.views.push({ recipient: recipient, action: { id: id, playerId: playerId, move: (0, index_1.getMoveView)(game, move, recipient), consequences: [] } });
28
+ actionWithView.views.push({ recipient: recipient, action: { id: id, playerId: playerId, move: (0, index_1.getMoveView)(rules, move, recipient), consequences: [] } });
29
29
  }
30
30
  // Prepare action view for spectators
31
- actionWithView.views.push({ action: { id: id, playerId: playerId, move: (0, index_1.getMoveView)(game, move), consequences: [] } });
32
- game.play(JSON.parse(JSON.stringify(move)));
33
- (0, Game_1.applyAutomaticMoves)(game, function (move) {
31
+ actionWithView.views.push({ action: { id: id, playerId: playerId, move: (0, index_1.getMoveView)(rules, move), consequences: [] } });
32
+ rules.play(JSON.parse(JSON.stringify(move)));
33
+ (0, ApplyAutomaticMoves_1.applyAutomaticMoves)(rules, function (move) {
34
34
  actionWithView.action.consequences.push(move);
35
35
  for (var _i = 0, _a = actionWithView.views; _i < _a.length; _i++) {
36
36
  var view = _a[_i];
37
- view.action.consequences.push((0, index_1.getMoveView)(game, move, view.recipient));
37
+ view.action.consequences.push((0, index_1.getMoveView)(rules, move, view.recipient));
38
38
  }
39
39
  });
40
40
  return actionWithView;
41
41
  }
42
42
  exports.playActionWithViews = playActionWithViews;
43
- function replayAction(game, action) {
44
- game.play(JSON.parse(JSON.stringify(action.move)));
45
- action.consequences.forEach(function (move) { return game.play(JSON.parse(JSON.stringify(move))); });
43
+ function replayAction(rules, action) {
44
+ rules.play(JSON.parse(JSON.stringify(action.move)));
45
+ action.consequences.forEach(function (move) { return rules.play(JSON.parse(JSON.stringify(move))); });
46
46
  }
47
47
  exports.replayAction = replayAction;
48
- function replayActions(game, actions) {
49
- actions.forEach(function (action) { return replayAction(game, action); });
48
+ function replayActions(rules, actions) {
49
+ actions.forEach(function (action) { return replayAction(rules, action); });
50
50
  }
51
51
  exports.replayActions = replayActions;
52
52
  function isSecretAction(action) {
@@ -1 +1 @@
1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IAAI,CAAC,IAAA,mBAAW,EAAC,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAA;SACxE;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,cAAc,CAAA;AACvB,CAAC;AA9BD,kDA8BC;AAED,SAAgB,YAAY,CAAwB,KAAmC,EAAE,MAA8B;IACrH,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACnD,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,UAAA,IAAI,IAAI,OAAA,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAA5C,CAA4C,CAAC,CAAA;AACnF,CAAC;AAHD,oCAGC;AAED,SAAgB,aAAa,CAAwB,KAAmC,EAAE,OAAiC;IACzH,OAAO,CAAC,OAAO,CAAC,UAAA,MAAM,IAAI,OAAA,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,EAA3B,CAA2B,CAAC,CAAA;AACxD,CAAC;AAFD,sCAEC;AAMD,SAAgB,cAAc,CAAC,MAAc;IAC3C,OAAO,KAAK,CAAC,OAAO,CAAE,MAAuB,CAAC,OAAO,CAAC,CAAA;AACxD,CAAC;AAFD,wCAEC"}
@@ -0,0 +1,2 @@
1
+ import Rules from './Rules';
2
+ export declare function applyAutomaticMoves<State, Move, PlayerId>(rules: Rules<State, Move, PlayerId>, preprocessMove?: (move: Move) => void): void;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applyAutomaticMoves = void 0;
4
+ var RandomMove_1 = require("./RandomMove");
5
+ var LoopWithFuse_1 = require("./LoopWithFuse");
6
+ function applyAutomaticMoves(rules, preprocessMove) {
7
+ var moves = [];
8
+ (0, LoopWithFuse_1.loopWithFuse)(function () {
9
+ if (moves.length === 0 && rules.getAutomaticMoves) {
10
+ moves.push.apply(moves, (0, RandomMove_1.randomizeMoves)(rules, rules.getAutomaticMoves()));
11
+ }
12
+ var move = moves.shift();
13
+ if (move) {
14
+ if (preprocessMove)
15
+ preprocessMove(move);
16
+ rules.play(JSON.parse(JSON.stringify(move)));
17
+ return true;
18
+ }
19
+ else {
20
+ return false;
21
+ }
22
+ }, { errorFn: function () { return new Error("Infinite loop detected while applying move consequences: ".concat(JSON.stringify(rules.getAutomaticMoves()), ")")); } });
23
+ }
24
+ exports.applyAutomaticMoves = applyAutomaticMoves;
25
+ //# sourceMappingURL=ApplyAutomaticMoves.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApplyAutomaticMoves.js","sourceRoot":"","sources":["../src/ApplyAutomaticMoves.ts"],"names":[],"mappings":";;;AAAA,2CAA2C;AAC3C,+CAA2C;AAG3C,SAAgB,mBAAmB,CAAwB,KAAmC,EAAE,cAAqC;IACnI,IAAM,KAAK,GAAW,EAAE,CAAA;IACxB,IAAA,2BAAY,EAAC;QACX,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,iBAAiB,EAAE;YACjD,KAAK,CAAC,IAAI,OAAV,KAAK,EAAS,IAAA,2BAAc,EAAC,KAAK,EAAE,KAAK,CAAC,iBAAiB,EAAE,CAAC,EAAC;SAChE;QACD,IAAM,IAAI,GAAG,KAAK,CAAC,KAAK,EAAE,CAAA;QAC1B,IAAI,IAAI,EAAE;YACR,IAAI,cAAc;gBAAE,cAAc,CAAC,IAAI,CAAC,CAAA;YACxC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;YAC5C,OAAO,IAAI,CAAA;SACZ;aAAM;YACL,OAAO,KAAK,CAAA;SACb;IACH,CAAC,EAAE,EAAC,OAAO,EAAE,cAAM,OAAA,IAAI,KAAK,CAAC,mEAA4D,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,iBAAkB,EAAE,CAAC,MAAG,CAAC,EAApH,CAAoH,EAAC,CAAC,CAAA;AAC3I,CAAC;AAfD,kDAeC"}
@@ -1,6 +1,5 @@
1
- import Game from './Game';
2
- export default interface Eliminations<State, Move = string, PlayerId = number> extends Game<State, Move> {
1
+ export default interface Eliminations<Move = string, PlayerId = number> {
3
2
  isEliminated(playerId: PlayerId): boolean;
4
3
  giveUpMove?(playerId: PlayerId): Move | undefined;
5
4
  }
6
- export declare function hasEliminations<State, Move, PlayerId>(game: Game<State, Move>): game is Eliminations<State, Move, PlayerId>;
5
+ export declare function hasEliminations<Move, PlayerId>(rules: Object): rules is Eliminations<Move, PlayerId>;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.hasEliminations = void 0;
4
- function hasEliminations(game) {
5
- var withEliminations = game;
6
- return typeof withEliminations.isEliminated === 'function';
4
+ function hasEliminations(rules) {
5
+ var test = rules;
6
+ return typeof test.isEliminated === 'function';
7
7
  }
8
8
  exports.hasEliminations = hasEliminations;
9
9
  //# sourceMappingURL=Eliminations.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Eliminations.js","sourceRoot":"","sources":["../src/Eliminations.ts"],"names":[],"mappings":";;;AAQA,SAAgB,eAAe,CAAwB,IAAuB;IAC5E,IAAI,gBAAgB,GAAG,IAA2C,CAAA;IAClE,OAAO,OAAO,gBAAgB,CAAC,YAAY,KAAK,UAAU,CAAA;AAC5D,CAAC;AAHD,0CAGC"}
1
+ {"version":3,"file":"Eliminations.js","sourceRoot":"","sources":["../src/Eliminations.ts"],"names":[],"mappings":";;;AAMA,SAAgB,eAAe,CAAiB,KAAa;IAC3D,IAAM,IAAI,GAAG,KAAqC,CAAA;IAClD,OAAO,OAAO,IAAI,CAAC,YAAY,KAAK,UAAU,CAAA;AAChD,CAAC;AAHD,0CAGC"}
@@ -1,14 +1,14 @@
1
1
  import Rules from './Rules';
2
- export default interface IncompleteInformation<State, StateView, Move = string, MoveView = string, PlayerId = number> extends Rules<State, Move, PlayerId> {
3
- getView(): StateView;
2
+ export default interface IncompleteInformation<GameView = any, Move = any, MoveView = any> {
3
+ getView(): GameView;
4
4
  getMoveView(move: Move): MoveView;
5
5
  }
6
- export declare function hasIncompleteInformation<State, StateView, Move, MoveView, PlayerId>(rules: Rules<State, Move, PlayerId>): rules is IncompleteInformation<State, StateView, Move, MoveView, PlayerId>;
7
- export interface SecretInformation<State, StateView, Move = string, MoveView = string, PlayerId = number> extends IncompleteInformation<State, StateView, Move, MoveView, PlayerId> {
8
- getPlayerView(playerId: PlayerId): StateView;
6
+ export declare function hasIncompleteInformation<GameView = any, Move = any, MoveView = any>(rules: Object): rules is IncompleteInformation<GameView, Move, MoveView>;
7
+ export interface SecretInformation<GameView = any, Move = any, MoveView = any, PlayerId = any> extends IncompleteInformation<GameView, Move, MoveView> {
8
+ getPlayerView(playerId: PlayerId): GameView;
9
9
  getPlayerMoveView?(move: Move, playerId: PlayerId): MoveView;
10
10
  keepMoveSecret?(move: Move, playerId: PlayerId): boolean;
11
11
  }
12
- export declare function hasSecretInformation<State, StateView, Move, MoveView, PlayerId>(rules: Rules<State, Move, PlayerId>): rules is SecretInformation<State, StateView, Move, MoveView, PlayerId>;
13
- export declare function getGameView<State, StateView, Move, MoveView, PlayerId>(game: IncompleteInformation<State, StateView, Move, MoveView, PlayerId>, playerId?: PlayerId): StateView;
14
- export declare function getMoveView<State, StateView, Move, MoveView, PlayerId>(game: IncompleteInformation<State, StateView, Move, MoveView, PlayerId>, move: Move, playerId?: PlayerId): MoveView;
12
+ export declare function hasSecretInformation<GameView = any, Move = any, MoveView = any, PlayerId = any>(rules: Object): rules is SecretInformation<GameView, Move, MoveView, PlayerId>;
13
+ export declare function getGameView<Game, GameView, PlayerId>(rules: Rules<Game, any, PlayerId>, playerId?: PlayerId): GameView;
14
+ export declare function getMoveView<GameView, Move, MoveView, PlayerId>(rules: Rules<any, Move, PlayerId>, move: Move, playerId?: PlayerId): MoveView;
@@ -2,30 +2,36 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getMoveView = exports.getGameView = exports.hasSecretInformation = exports.hasIncompleteInformation = void 0;
4
4
  function hasIncompleteInformation(rules) {
5
- var game = rules;
6
- return typeof game.getView === 'function' && typeof game.getMoveView === 'function';
5
+ var test = rules;
6
+ return typeof test.getView === 'function' && typeof test.getMoveView === 'function';
7
7
  }
8
8
  exports.hasIncompleteInformation = hasIncompleteInformation;
9
9
  function hasSecretInformation(rules) {
10
- var game = rules;
11
- return typeof game.getPlayerView === 'function';
10
+ var test = rules;
11
+ return typeof test.getPlayerView === 'function';
12
12
  }
13
13
  exports.hasSecretInformation = hasSecretInformation;
14
- function getGameView(game, playerId) {
15
- if (hasSecretInformation(game) && playerId !== undefined) {
16
- return game.getPlayerView(playerId);
14
+ function getGameView(rules, playerId) {
15
+ if (hasSecretInformation(rules) && playerId !== undefined) {
16
+ return rules.getPlayerView(playerId);
17
+ }
18
+ else if (hasIncompleteInformation(rules)) {
19
+ return rules.getView();
17
20
  }
18
21
  else {
19
- return game.getView();
22
+ return rules.state;
20
23
  }
21
24
  }
22
25
  exports.getGameView = getGameView;
23
- function getMoveView(game, move, playerId) {
24
- if (hasSecretInformation(game) && playerId !== undefined && game.getPlayerMoveView) {
25
- return JSON.parse(JSON.stringify(game.getPlayerMoveView(move, playerId)));
26
+ function getMoveView(rules, move, playerId) {
27
+ if (hasSecretInformation(rules) && rules.getPlayerMoveView && playerId !== undefined) {
28
+ return JSON.parse(JSON.stringify(rules.getPlayerMoveView(move, playerId)));
29
+ }
30
+ else if (hasIncompleteInformation(rules)) {
31
+ return JSON.parse(JSON.stringify(rules.getMoveView(move)));
26
32
  }
27
33
  else {
28
- return JSON.parse(JSON.stringify(game.getMoveView(move)));
34
+ return move;
29
35
  }
30
36
  }
31
37
  exports.getMoveView = getMoveView;
@@ -1 +1 @@
1
- {"version":3,"file":"IncompleteInformation.js","sourceRoot":"","sources":["../src/IncompleteInformation.ts"],"names":[],"mappings":";;;AAQA,SAAgB,wBAAwB,CAA6C,KAAmC;IACtH,IAAM,IAAI,GAAG,KAA0E,CAAA;IACvF,OAAO,OAAO,IAAI,CAAC,OAAO,KAAK,UAAU,IAAI,OAAO,IAAI,CAAC,WAAW,KAAK,UAAU,CAAA;AACrF,CAAC;AAHD,4DAGC;AAUD,SAAgB,oBAAoB,CAA6C,KAAmC;IAClH,IAAM,IAAI,GAAG,KAAsE,CAAA;IACnF,OAAO,OAAO,IAAI,CAAC,aAAa,KAAK,UAAU,CAAA;AACjD,CAAC;AAHD,oDAGC;AAED,SAAgB,WAAW,CAA6C,IAAuE,EAAE,QAAmB;IAClK,IAAI,oBAAoB,CAA6C,IAAI,CAAC,IAAI,QAAQ,KAAK,SAAS,EAAE;QACpG,OAAO,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;KACpC;SAAM;QACL,OAAO,IAAI,CAAC,OAAO,EAAE,CAAA;KACtB;AACH,CAAC;AAND,kCAMC;AAED,SAAgB,WAAW,CAA6C,IAAuE,EAAE,IAAU,EAAE,QAAmB;IAC9K,IAAI,oBAAoB,CAA6C,IAAI,CAAC,IAAI,QAAQ,KAAK,SAAS,IAAI,IAAI,CAAC,iBAAiB,EAAE;QAC9H,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,iBAAiB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAA;KAC1E;SAAM;QACL,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;KAC1D;AACH,CAAC;AAND,kCAMC"}
1
+ {"version":3,"file":"IncompleteInformation.js","sourceRoot":"","sources":["../src/IncompleteInformation.ts"],"names":[],"mappings":";;;AAQA,SAAgB,wBAAwB,CAA6C,KAAa;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{
2
+ attempts?: number;
3
+ errorFn?: () => Error;
4
+ }): void;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loopWithFuse = void 0;
4
+ function loopWithFuse(repeat, options) {
5
+ var attempts = (options === null || options === void 0 ? void 0 : options.attempts) || (process.env.NODE_ENV === 'development' ? 100 : 1000);
6
+ var errorFn = (options === null || options === void 0 ? void 0 : options.errorFn) || (function () { return new Error('Infinite loop detected'); });
7
+ while (repeat()) {
8
+ if (attempts == 0) {
9
+ throw errorFn();
10
+ }
11
+ attempts--;
12
+ }
13
+ }
14
+ exports.loopWithFuse = loopWithFuse;
15
+ //# sourceMappingURL=LoopWithFuse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LoopWithFuse.js","sourceRoot":"","sources":["../src/LoopWithFuse.ts"],"names":[],"mappings":";;;AAAA,SAAgB,YAAY,CAAC,MAAqB,EAAE,OAAsD;IACxG,IAAI,QAAQ,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,KAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;IACzF,IAAM,OAAO,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,KAAI,CAAC,cAAM,OAAA,IAAI,KAAK,CAAC,wBAAwB,CAAC,EAAnC,CAAmC,CAAC,CAAA;IAC/E,OAAO,MAAM,EAAE,EAAE;QACf,IAAI,QAAQ,IAAI,CAAC,EAAE;YACjB,MAAM,OAAO,EAAE,CAAA;SAChB;QACD,QAAQ,EAAE,CAAA;KACX;AACH,CAAC;AATD,oCASC"}
@@ -1,7 +1,7 @@
1
- import Game from './Game';
2
- export default interface RandomMove<State, Move = string, R = string> extends Game<State, Move> {
3
- randomize(move: Move): Move & R;
4
- play(move: Move & R): void;
1
+ import Rules from './Rules';
2
+ export default interface RandomMove<Move = string, RandomizedMove = string> {
3
+ randomize(move: Move): Move & RandomizedMove;
4
+ play(move: Move & RandomizedMove): void;
5
5
  }
6
- export declare function hasRandomMove<State, Move, R>(game: Game<State, Move>): game is RandomMove<State, Move, R>;
7
- export declare function randomizeMoves<State, Move>(game: Game<State, Move>, moves: Move[]): Move[];
6
+ export declare function hasRandomMove<State, Move, RandomizedMove>(rules: Rules<State, Move>): rules is Rules<State, Move> & RandomMove<Move, RandomizedMove>;
7
+ export declare function randomizeMoves<State, Move, RandomizedMove = Move>(rules: Rules<State, Move>, moves: Move[]): (Move & RandomizedMove)[];
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.randomizeMoves = exports.hasRandomMove = void 0;
4
- function hasRandomMove(game) {
5
- return typeof game.randomize === 'function';
4
+ function hasRandomMove(rules) {
5
+ var test = rules;
6
+ return typeof test.randomize === 'function';
6
7
  }
7
8
  exports.hasRandomMove = hasRandomMove;
8
- function randomizeMoves(game, moves) {
9
- return hasRandomMove(game) ? moves.map(function (move) { return game.randomize(move); }) : moves;
9
+ function randomizeMoves(rules, moves) {
10
+ return hasRandomMove(rules) ? moves.map(function (move) { return rules.randomize(move); }) : moves;
10
11
  }
11
12
  exports.randomizeMoves = randomizeMoves;
12
13
  //# sourceMappingURL=RandomMove.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"RandomMove.js","sourceRoot":"","sources":["../src/RandomMove.ts"],"names":[],"mappings":";;;AAQA,SAAgB,aAAa,CAAiB,IAAuB;IACnE,OAAO,OAAQ,IAAmC,CAAC,SAAS,KAAK,UAAU,CAAA;AAC7E,CAAC;AAFD,sCAEC;AAED,SAAgB,cAAc,CAAc,IAAuB,EAAE,KAAa;IAChF,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,UAAA,IAAI,IAAI,OAAA,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAApB,CAAoB,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;AAC9E,CAAC;AAFD,wCAEC"}
1
+ {"version":3,"file":"RandomMove.js","sourceRoot":"","sources":["../src/RandomMove.ts"],"names":[],"mappings":";;;AAQA,SAAgB,aAAa,CAA8B,KAAyB;IAClF,IAAM,IAAI,GAAG,KAA8D,CAAA;IAC3E,OAAO,OAAO,IAAI,CAAC,SAAS,KAAK,UAAU,CAAA;AAC7C,CAAC;AAHD,sCAGC;AAED,SAAgB,cAAc,CAAqC,KAAyB,EAAE,KAAa;IACzG,OAAO,aAAa,CAA8B,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,UAAA,IAAI,IAAI,OAAA,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,EAArB,CAAqB,CAAC,CAAC,CAAC,CAAE,KAAmC,CAAA;AAC5I,CAAC;AAFD,wCAEC"}
package/dist/Rules.d.ts CHANGED
@@ -1,11 +1,14 @@
1
- import Game from './Game';
2
- export default abstract class Rules<State = any, Move = any, PlayerId = any> implements Game<State, Move> {
1
+ export default abstract class Rules<State = any, Move = any, PlayerId = any> {
3
2
  state: State;
4
- protected constructor(game: State);
3
+ automaticMoves: Move[];
4
+ constructor(game: State);
5
+ delegate(): Rules<State, Move, PlayerId> | undefined;
6
+ delegates(): Rules<State, Move, PlayerId>[];
5
7
  isTurnToPlay(playerId: PlayerId): boolean;
6
8
  getActivePlayer?(): PlayerId | undefined;
7
9
  isLegalMove(playerId: PlayerId, move: Move): boolean;
8
- getLegalMoves?(playerId: PlayerId): Move[];
9
- abstract play(move: Move): void;
10
+ getLegalMoves(playerId: PlayerId): Move[];
11
+ getAutomaticMoves(): Move[];
12
+ play(move: Move): void;
10
13
  isOver(playerIds: PlayerId[]): boolean;
11
14
  }
package/dist/Rules.js CHANGED
@@ -1,4 +1,13 @@
1
1
  "use strict";
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
@@ -7,17 +16,30 @@ var fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
7
16
  var Eliminations_1 = require("./Eliminations");
8
17
  var Rules = /** @class */ (function () {
9
18
  function Rules(game) {
19
+ this.automaticMoves = [];
10
20
  this.state = game;
11
21
  }
22
+ Rules.prototype.delegate = function () {
23
+ return;
24
+ };
25
+ Rules.prototype.delegates = function () {
26
+ var delegate = this.delegate();
27
+ return delegate ? [delegate] : [];
28
+ };
12
29
  Rules.prototype.isTurnToPlay = function (playerId) {
13
- if (!this.getActivePlayer) {
14
- throw new Error('You must either implement "isTurnToPlay" or "getActivePlayer" if only one player is active at a time');
30
+ var rules = this.delegates();
31
+ if (rules.some(function (rules) { return rules.isTurnToPlay(playerId); })) {
32
+ return true;
33
+ }
34
+ if (this.getActivePlayer) {
35
+ return playerId === this.getActivePlayer();
15
36
  }
16
- return playerId === this.getActivePlayer();
37
+ return false;
17
38
  };
18
39
  Rules.prototype.isLegalMove = function (playerId, move) {
19
- if (!this.getLegalMoves) {
20
- throw new Error('You must either implement "isLegalMove" or "getLegalMoves');
40
+ var rules = this.delegates();
41
+ if (rules.some(function (rules) { return rules.isLegalMove(playerId, move); })) {
42
+ return true;
21
43
  }
22
44
  if (this.getLegalMoves(playerId).some(function (legalMove) { return (0, fast_deep_equal_1.default)(move, legalMove); })) {
23
45
  return true;
@@ -27,6 +49,18 @@ var Rules = /** @class */ (function () {
27
49
  }
28
50
  return false;
29
51
  };
52
+ Rules.prototype.getLegalMoves = function (playerId) {
53
+ return this.delegates().flatMap(function (rules) { return rules.getLegalMoves(playerId); });
54
+ };
55
+ Rules.prototype.getAutomaticMoves = function () {
56
+ return __spreadArray(__spreadArray([], this.automaticMoves, true), this.delegates().flatMap(function (rules) { return rules.getAutomaticMoves(); }), true);
57
+ };
58
+ Rules.prototype.play = function (move) {
59
+ for (var _i = 0, _a = this.delegates(); _i < _a.length; _i++) {
60
+ var rules = _a[_i];
61
+ rules.play(move);
62
+ }
63
+ };
30
64
  Rules.prototype.isOver = function (playerIds) {
31
65
  var _this = this;
32
66
  return !playerIds.some(function (playerId) { return _this.isTurnToPlay(playerId); });
package/dist/Rules.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Rules.js","sourceRoot":"","sources":["../src/Rules.ts"],"names":[],"mappings":";;;;;AACA,oEAAmC;AACnC,+CAA8C;AAE9C;IAGE,eAAsB,IAAW;QAC/B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;IACnB,CAAC;IAED,4BAAY,GAAZ,UAAa,QAAkB;QAC7B,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;YACzB,MAAM,IAAI,KAAK,CAAC,sGAAsG,CAAC,CAAA;SACxH;QACD,OAAO,QAAQ,KAAK,IAAI,CAAC,eAAe,EAAE,CAAA;IAC5C,CAAC;IAID,2BAAW,GAAX,UAAY,QAAkB,EAAE,IAAU;QACxC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;YACvB,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAA;SAC7E;QACD,IAAI,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,UAAA,SAAS,IAAI,OAAA,IAAA,yBAAK,EAAC,IAAI,EAAE,SAAS,CAAC,EAAtB,CAAsB,CAAC,EAAE;YAC1E,OAAO,IAAI,CAAA;SACZ;QACD,IAAI,IAAA,8BAAe,EAAC,IAAI,CAAC,IAAI,IAAI,CAAC,UAAU,EAAE;YAC5C,OAAO,IAAA,yBAAK,EAAC,IAAI,EAAE,IAAI,CAAC,UAAU,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I,OAAA,KAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,EAA3B,CAA2B,CAAC,CAAA;IACjE,CAAC;IACH,YAAC;AAAD,CAAC,AA7DD,IA6DC"}
package/dist/Undo.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import Action from './Action';
2
- import Game from './Game';
3
- export default interface Undo<State, Move = string, PlayerId = number> extends Game<State, Move> {
2
+ export default interface Undo<State, Move = string, PlayerId = number> {
4
3
  canUndo(action: Action<Move, PlayerId>, consecutiveActions: Action<Move, PlayerId>[]): boolean;
5
4
  restoreLocalMoves?(localState: State): void;
6
5
  }
7
- export declare function hasUndo<State, Move, PlayerId>(game: Game<State, Move>): game is Undo<State, Move, PlayerId>;
6
+ export declare function hasUndo<State, Move, PlayerId>(rules: Object): rules is Undo<State, Move, PlayerId>;
package/dist/Undo.js CHANGED
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.hasUndo = void 0;
4
- function hasUndo(game) {
5
- return typeof game.canUndo === 'function';
4
+ function hasUndo(rules) {
5
+ var test = rules;
6
+ return typeof test.canUndo === 'function';
6
7
  }
7
8
  exports.hasUndo = hasUndo;
8
9
  //# sourceMappingURL=Undo.js.map
package/dist/Undo.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Undo.js","sourceRoot":"","sources":["../src/Undo.ts"],"names":[],"mappings":";;;AAQA,SAAgB,OAAO,CAAwB,IAAuB;IACpE,OAAO,OAAQ,IAAoC,CAAC,OAAO,KAAK,UAAU,CAAA;AAC5E,CAAC;AAFD,0BAEC"}
1
+ {"version":3,"file":"Undo.js","sourceRoot":"","sources":["../src/Undo.ts"],"names":[],"mappings":";;;AAOA,SAAgB,OAAO,CAAwB,KAAa;IAC1D,IAAM,IAAI,GAAG,KAAoC,CAAA;IACjD,OAAO,OAAO,IAAI,CAAC,OAAO,KAAK,UAAU,CAAA;AAC3C,CAAC;AAHD,0BAGC"}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,4 @@
1
- export { default as Game } from './Game';
2
- export * from './Game';
3
1
  export { default as Rules } from './Rules';
4
- export { default as GameCreator } from './GameCreator';
5
2
  export { default as RulesCreator } from './RulesCreator';
6
3
  export { default as Action } from './Action';
7
4
  export * from './Action';
@@ -21,3 +18,5 @@ export { default as Robot } from './Robot';
21
18
  export { default as Dummy } from './Dummy';
22
19
  export * from './options';
23
20
  export * from './utils';
21
+ export { applyAutomaticMoves } from './ApplyAutomaticMoves';
22
+ export { loopWithFuse } from './LoopWithFuse';
package/dist/index.js CHANGED
@@ -17,8 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.Dummy = exports.Rules = void 0;
21
- __exportStar(require("./Game"), exports);
20
+ exports.loopWithFuse = exports.applyAutomaticMoves = exports.Dummy = exports.Rules = void 0;
22
21
  var Rules_1 = require("./Rules");
23
22
  Object.defineProperty(exports, "Rules", { enumerable: true, get: function () { return __importDefault(Rules_1).default; } });
24
23
  __exportStar(require("./Action"), exports);
@@ -32,4 +31,8 @@ var Dummy_1 = require("./Dummy");
32
31
  Object.defineProperty(exports, "Dummy", { enumerable: true, get: function () { return __importDefault(Dummy_1).default; } });
33
32
  __exportStar(require("./options"), exports);
34
33
  __exportStar(require("./utils"), exports);
34
+ var ApplyAutomaticMoves_1 = require("./ApplyAutomaticMoves");
35
+ Object.defineProperty(exports, "applyAutomaticMoves", { enumerable: true, get: function () { return ApplyAutomaticMoves_1.applyAutomaticMoves; } });
36
+ var LoopWithFuse_1 = require("./LoopWithFuse");
37
+ Object.defineProperty(exports, "loopWithFuse", { enumerable: true, get: function () { return LoopWithFuse_1.loopWithFuse; } });
35
38
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AACA,yCAAsB;AACtB,iCAAwC;AAAhC,+GAAA,OAAO,OAAS;AAKxB,2CAAwB;AAGxB,0DAAuC;AAGvC,yCAAsB;AAGtB,gDAA6B;AAG7B,iDAA8B;AAG9B,iDAA8B;AAG9B,8CAA2B;AAG3B,iCAAwC;AAAhC,+GAAA,OAAO,OAAS;AAExB,4CAAyB;AACzB,0CAAuB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,iCAAwC;AAAhC,+GAAA,OAAO,OAAS;AAIxB,2CAAwB;AAGxB,0DAAuC;AAGvC,yCAAsB;AAGtB,gDAA6B;AAG7B,iDAA8B;AAG9B,iDAA8B;AAG9B,8CAA2B;AAG3B,iCAAwC;AAAhC,+GAAA,OAAO,OAAS;AAExB,4CAAyB;AACzB,0CAAuB;AACvB,6DAAyD;AAAjD,0HAAA,mBAAmB,OAAA;AAC3B,+CAA2C;AAAnC,4GAAA,YAAY,OAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gamepark/rules-api",
3
- "version": "5.19.0",
3
+ "version": "5.20.0",
4
4
  "description": "API to implement the rules of a board game",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -27,5 +27,5 @@
27
27
  "devDependencies": {
28
28
  "i18next": ">=21.3.0"
29
29
  },
30
- "gitHead": "1c0efa27e6557111a721fd1ad0c95ac1394a3543"
30
+ "gitHead": "f04c7333a2295153061eac50ad910375fc50758c"
31
31
  }