@gamepark/rules-api 5.15.1 → 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 +5 -5
- package/dist/Action.js +19 -19
- package/dist/Action.js.map +1 -1
- package/dist/ApplyAutomaticMoves.d.ts +2 -0
- package/dist/ApplyAutomaticMoves.js +25 -0
- package/dist/ApplyAutomaticMoves.js.map +1 -0
- package/dist/Dummy.js +1 -17
- package/dist/Dummy.js.map +1 -1
- package/dist/Eliminations.d.ts +2 -3
- package/dist/Eliminations.js +3 -3
- package/dist/Eliminations.js.map +1 -1
- package/dist/IncompleteInformation.d.ts +8 -8
- package/dist/IncompleteInformation.js +18 -12
- package/dist/IncompleteInformation.js.map +1 -1
- package/dist/LoopWithFuse.d.ts +4 -0
- package/dist/LoopWithFuse.js +15 -0
- package/dist/LoopWithFuse.js.map +1 -0
- package/dist/RandomMove.d.ts +6 -6
- package/dist/RandomMove.js +5 -4
- package/dist/RandomMove.js.map +1 -1
- package/dist/Rules.d.ts +11 -3
- package/dist/Rules.js +68 -0
- package/dist/Rules.js.map +1 -1
- package/dist/Undo.d.ts +2 -3
- package/dist/Undo.js +3 -2
- package/dist/Undo.js.map +1 -1
- package/dist/index.d.ts +2 -5
- package/dist/index.js +7 -6
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/ActionWithViews.d.ts +0 -11
- package/dist/ActionWithViews.js +0 -33
- package/dist/ActionWithViews.js.map +0 -1
- package/dist/GameOptions.d.ts +0 -3
- package/dist/GameOptions.js +0 -3
- package/dist/GameOptions.js.map +0 -1
- package/dist/PlayerAction.d.ts +0 -10
- package/dist/PlayerAction.js +0 -28
- package/dist/PlayerAction.js.map +0 -1
- package/dist/SecretAction.d.ts +0 -6
- package/dist/SecretAction.js +0 -8
- package/dist/SecretAction.js.map +0 -1
- package/dist/SecretMove.d.ts +0 -5
- package/dist/SecretMove.js +0 -9
- package/dist/SecretMove.js.map +0 -1
- package/dist/UndoCreator.d.ts +0 -4
- package/dist/UndoCreator.js +0 -3
- package/dist/UndoCreator.js.map +0 -1
- package/dist/_Game.d.ts +0 -17
- package/dist/_Game.js +0 -23
- package/dist/_Game.js.map +0 -1
- package/dist/_Rules.d.ts +0 -11
- package/dist/_Rules.js +0 -3
- package/dist/_Rules.js.map +0 -1
- package/dist/options/BooleanOption.d.ts +0 -6
- package/dist/options/BooleanOption.js +0 -3
- package/dist/options/BooleanOption.js.map +0 -1
- package/dist/options/BooleanOptionDescription.d.ts +0 -5
- package/dist/options/BooleanOptionDescription.js +0 -3
- package/dist/options/BooleanOptionDescription.js.map +0 -1
- package/dist/options/BooleanOptionSpec.d.ts +0 -4
- package/dist/options/BooleanOptionSpec.js +0 -3
- package/dist/options/BooleanOptionSpec.js.map +0 -1
- package/dist/options/EnumOptionSpec.d.ts +0 -6
- package/dist/options/EnumOptionSpec.js +0 -3
- package/dist/options/EnumOptionSpec.js.map +0 -1
- package/dist/options/GameOptions.d.ts +0 -6
- package/dist/options/GameOptions.js +0 -3
- package/dist/options/GameOptions.js.map +0 -1
- package/dist/options/GameOptionsOf.d.ts +0 -5
- package/dist/options/GameOptionsOf.js +0 -3
- package/dist/options/GameOptionsOf.js.map +0 -1
- package/dist/options/GameOptionsSpecs.d.ts +0 -5
- package/dist/options/GameOptionsSpecs.js +0 -3
- package/dist/options/GameOptionsSpecs.js.map +0 -1
- package/dist/options/IntegerOptionDescription.d.ts +0 -7
- package/dist/options/IntegerOptionDescription.js +0 -3
- package/dist/options/IntegerOptionDescription.js.map +0 -1
- package/dist/options/ListOptionDescription.d.ts +0 -8
- package/dist/options/ListOptionDescription.js +0 -3
- package/dist/options/ListOptionDescription.js.map +0 -1
- package/dist/options/OptionDescription.d.ts +0 -4
- package/dist/options/OptionDescription.js +0 -3
- package/dist/options/OptionDescription.js.map +0 -1
- package/dist/options/OptionDescriptionOf.d.ts +0 -4
- package/dist/options/OptionDescriptionOf.js +0 -3
- package/dist/options/OptionDescriptionOf.js.map +0 -1
- package/dist/options/OptionSpec.d.ts +0 -4
- package/dist/options/OptionSpec.js +0 -3
- package/dist/options/OptionSpec.js.map +0 -1
- package/dist/options/OptionType.d.ts +0 -6
- package/dist/options/OptionType.js +0 -10
- package/dist/options/OptionType.js.map +0 -1
- package/dist/options/OptionsDescription.d.ts +0 -23
- package/dist/options/OptionsDescription.js +0 -53
- package/dist/options/OptionsDescription.js.map +0 -1
- package/dist/options/PlayerIdsSpec.d.ts +0 -7
- package/dist/options/PlayerIdsSpec.js +0 -3
- package/dist/options/PlayerIdsSpec.js.map +0 -1
- package/dist/options/getPlayerName.d.ts +0 -4
- package/dist/options/getPlayerName.js +0 -16
- package/dist/options/getPlayerName.js.map +0 -1
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>(
|
|
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<
|
|
20
|
-
export declare function replayAction<State, Move, PlayerId>(
|
|
21
|
-
export declare function replayActions<State, Move, PlayerId>(
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
13
|
-
(0,
|
|
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(
|
|
18
|
-
if ((0, RandomMove_1.hasRandomMove)(
|
|
19
|
-
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)(
|
|
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)(
|
|
32
|
-
|
|
33
|
-
(0,
|
|
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)(
|
|
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(
|
|
44
|
-
|
|
45
|
-
action.consequences.forEach(function (move) { return
|
|
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(
|
|
49
|
-
actions.forEach(function (action) { return replayAction(
|
|
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) {
|
package/dist/Action.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Action.js","sourceRoot":"","sources":["../src/Action.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"Action.js","sourceRoot":"","sources":["../src/Action.ts"],"names":[],"mappings":"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"}
|
|
@@ -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"}
|
package/dist/Dummy.js
CHANGED
|
@@ -12,15 +12,7 @@ var Dummy = /** @class */ (function () {
|
|
|
12
12
|
};
|
|
13
13
|
Dummy.prototype.getLegalMoves = function (state, playerId) {
|
|
14
14
|
var rules = new this.Rules(state);
|
|
15
|
-
if (
|
|
16
|
-
if (rules.getActivePlayer() === playerId) {
|
|
17
|
-
return rules.getLegalMoves();
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
return [];
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
else if (hasLegalMoves(rules)) {
|
|
15
|
+
if (rules.getLegalMoves) {
|
|
24
16
|
return rules.getLegalMoves(playerId);
|
|
25
17
|
}
|
|
26
18
|
else {
|
|
@@ -31,12 +23,4 @@ var Dummy = /** @class */ (function () {
|
|
|
31
23
|
return Dummy;
|
|
32
24
|
}());
|
|
33
25
|
exports.default = Dummy;
|
|
34
|
-
function isSequentialGame(rules) {
|
|
35
|
-
var game = rules;
|
|
36
|
-
return typeof game.getActivePlayer === 'function' && typeof game.getLegalMoves === 'function';
|
|
37
|
-
}
|
|
38
|
-
function hasLegalMoves(rules) {
|
|
39
|
-
var game = rules;
|
|
40
|
-
return typeof game.getLegalMoves === 'function';
|
|
41
|
-
}
|
|
42
26
|
//# sourceMappingURL=Dummy.js.map
|
package/dist/Dummy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dummy.js","sourceRoot":"","sources":["../src/Dummy.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"Dummy.js","sourceRoot":"","sources":["../src/Dummy.ts"],"names":[],"mappings":";;AAEA;IAIE,eAAY,KAA0C;QACpD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;IAED,6BAAa,GAAb,UAAc,KAAY,EAAE,QAAkB;QAC5C,IAAI,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;QAC/C,IAAI,CAAC,KAAK,CAAC,MAAM;YAAE,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;QAC7C,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;IAC3E,CAAC;IAED,6BAAa,GAAb,UAAc,KAAY,EAAE,QAAkB;QAC5C,IAAM,KAAK,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QACnC,IAAI,KAAK,CAAC,aAAa,EAAE;YACvB,OAAO,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;SACrC;aAAM;YACL,OAAO,CAAC,KAAK,CAAC,+DAA+D,CAAC,CAAA;YAC9E,OAAO,EAAE,CAAA;SACV;IACH,CAAC;IACH,YAAC;AAAD,CAAC,AAvBD,IAuBC"}
|
package/dist/Eliminations.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
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<
|
|
5
|
+
export declare function hasEliminations<Move, PlayerId>(rules: Object): rules is Eliminations<Move, PlayerId>;
|
package/dist/Eliminations.js
CHANGED
|
@@ -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(
|
|
5
|
-
var
|
|
6
|
-
return typeof
|
|
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
|
package/dist/Eliminations.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Eliminations.js","sourceRoot":"","sources":["../src/Eliminations.ts"],"names":[],"mappings":";;;
|
|
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<
|
|
3
|
-
getView():
|
|
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<
|
|
7
|
-
export interface SecretInformation<
|
|
8
|
-
getPlayerView(playerId: PlayerId):
|
|
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<
|
|
13
|
-
export declare function getGameView<
|
|
14
|
-
export declare function getMoveView<
|
|
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
|
|
6
|
-
return typeof
|
|
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
|
|
11
|
-
return typeof
|
|
10
|
+
var test = rules;
|
|
11
|
+
return typeof test.getPlayerView === 'function';
|
|
12
12
|
}
|
|
13
13
|
exports.hasSecretInformation = hasSecretInformation;
|
|
14
|
-
function getGameView(
|
|
15
|
-
if (hasSecretInformation(
|
|
16
|
-
return
|
|
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
|
|
22
|
+
return rules.state;
|
|
20
23
|
}
|
|
21
24
|
}
|
|
22
25
|
exports.getGameView = getGameView;
|
|
23
|
-
function getMoveView(
|
|
24
|
-
if (hasSecretInformation(
|
|
25
|
-
return JSON.parse(JSON.stringify(
|
|
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
|
|
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,
|
|
1
|
+
{"version":3,"file":"IncompleteInformation.js","sourceRoot":"","sources":["../src/IncompleteInformation.ts"],"names":[],"mappings":";;;AAQA,SAAgB,wBAAwB,CAA6C,KAAa;IAChG,IAAM,IAAI,GAAG,KAAwD,CAAA;IACrE,OAAO,OAAO,IAAI,CAAC,OAAO,KAAK,UAAU,IAAI,OAAO,IAAI,CAAC,WAAW,KAAK,UAAU,CAAA;AACrF,CAAC;AAHD,4DAGC;AAUD,SAAgB,oBAAoB,CAA6D,KAAa;IAC5G,IAAM,IAAI,GAAG,KAA8D,CAAA;IAC3E,OAAO,OAAO,IAAI,CAAC,aAAa,KAAK,UAAU,CAAA;AACjD,CAAC;AAHD,oDAGC;AAED,SAAgB,WAAW,CAA2B,KAAiC,EAAE,QAAmB;IAC1G,IAAI,oBAAoB,CAA+B,KAAK,CAAC,IAAI,QAAQ,KAAK,SAAS,EAAE;QACvF,OAAO,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;KACrC;SAAM,IAAI,wBAAwB,CAAW,KAAK,CAAC,EAAE;QACpD,OAAO,KAAK,CAAC,OAAO,EAAE,CAAA;KACvB;SAAM;QACL,OAAO,KAAK,CAAC,KAAwB,CAAA;KACtC;AACH,CAAC;AARD,kCAQC;AAED,SAAgB,WAAW,CAAqC,KAAiC,EAAE,IAAU,EAAE,QAAmB;IAChI,IAAI,oBAAoB,CAAqC,KAAK,CAAC,IAAI,KAAK,CAAC,iBAAiB,IAAI,QAAQ,KAAK,SAAS,EAAE;QACxH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAA;KAC3E;SAAM,IAAI,wBAAwB,CAA2B,KAAK,CAAC,EAAE;QACpE,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;KAC3D;SAAM;QACL,OAAO,IAAuB,CAAA;KAC/B;AACH,CAAC;AARD,kCAQC"}
|
|
@@ -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"}
|
package/dist/RandomMove.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
export default interface RandomMove<
|
|
3
|
-
randomize(move: Move): Move &
|
|
4
|
-
play(move: Move &
|
|
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,
|
|
7
|
-
export declare function randomizeMoves<State, 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)[];
|
package/dist/RandomMove.js
CHANGED
|
@@ -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(
|
|
5
|
-
|
|
4
|
+
function hasRandomMove(rules) {
|
|
5
|
+
var test = rules;
|
|
6
|
+
return typeof test.randomize === 'function';
|
|
6
7
|
}
|
|
7
8
|
exports.hasRandomMove = hasRandomMove;
|
|
8
|
-
function randomizeMoves(
|
|
9
|
-
return hasRandomMove(
|
|
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
|
package/dist/RandomMove.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RandomMove.js","sourceRoot":"","sources":["../src/RandomMove.ts"],"names":[],"mappings":";;;AAQA,SAAgB,aAAa,
|
|
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,6 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export default abstract class Rules<State = any, Move = any, PlayerId = any> {
|
|
2
|
+
state: State;
|
|
3
|
+
automaticMoves: Move[];
|
|
4
|
+
constructor(game: State);
|
|
5
|
+
delegate(): Rules<State, Move, PlayerId> | undefined;
|
|
6
|
+
delegates(): Rules<State, Move, PlayerId>[];
|
|
3
7
|
isTurnToPlay(playerId: PlayerId): boolean;
|
|
8
|
+
getActivePlayer?(): PlayerId | undefined;
|
|
4
9
|
isLegalMove(playerId: PlayerId, move: Move): boolean;
|
|
5
|
-
|
|
10
|
+
getLegalMoves(playerId: PlayerId): Move[];
|
|
11
|
+
getAutomaticMoves(): Move[];
|
|
12
|
+
play(move: Move): void;
|
|
13
|
+
isOver(playerIds: PlayerId[]): boolean;
|
|
6
14
|
}
|
package/dist/Rules.js
CHANGED
|
@@ -1,3 +1,71 @@
|
|
|
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
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
2
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
var fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
|
|
16
|
+
var Eliminations_1 = require("./Eliminations");
|
|
17
|
+
var Rules = /** @class */ (function () {
|
|
18
|
+
function Rules(game) {
|
|
19
|
+
this.automaticMoves = [];
|
|
20
|
+
this.state = game;
|
|
21
|
+
}
|
|
22
|
+
Rules.prototype.delegate = function () {
|
|
23
|
+
return;
|
|
24
|
+
};
|
|
25
|
+
Rules.prototype.delegates = function () {
|
|
26
|
+
var delegate = this.delegate();
|
|
27
|
+
return delegate ? [delegate] : [];
|
|
28
|
+
};
|
|
29
|
+
Rules.prototype.isTurnToPlay = function (playerId) {
|
|
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();
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
};
|
|
39
|
+
Rules.prototype.isLegalMove = function (playerId, move) {
|
|
40
|
+
var rules = this.delegates();
|
|
41
|
+
if (rules.some(function (rules) { return rules.isLegalMove(playerId, move); })) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
if (this.getLegalMoves(playerId).some(function (legalMove) { return (0, fast_deep_equal_1.default)(move, legalMove); })) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
if ((0, Eliminations_1.hasEliminations)(this) && this.giveUpMove) {
|
|
48
|
+
return (0, fast_deep_equal_1.default)(move, this.giveUpMove(playerId));
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
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
|
+
};
|
|
64
|
+
Rules.prototype.isOver = function (playerIds) {
|
|
65
|
+
var _this = this;
|
|
66
|
+
return !playerIds.some(function (playerId) { return _this.isTurnToPlay(playerId); });
|
|
67
|
+
};
|
|
68
|
+
return Rules;
|
|
69
|
+
}());
|
|
70
|
+
exports.default = Rules;
|
|
3
71
|
//# sourceMappingURL=Rules.js.map
|
package/dist/Rules.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Rules.js","sourceRoot":"","sources":["../src/Rules.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"Rules.js","sourceRoot":"","sources":["../src/Rules.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,oEAAmC;AACnC,+CAA8C;AAE9C;IAIE,eAAY,IAAW;QAFvB,mBAAc,GAAW,EAAE,CAAA;QAGzB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;IACnB,CAAC;IAED,wBAAQ,GAAR;QACE,OAAM;IACR,CAAC;IAED,yBAAS,GAAT;QACE,IAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAA;QAChC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IACnC,CAAC;IAED,4BAAY,GAAZ,UAAa,QAAkB;QAC7B,IAAM,KAAK,GAAG,IAAI,CAAC,SAAS,EAAE,CAAA;QAC9B,IAAI,KAAK,CAAC,IAAI,CAAC,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,EAA5B,CAA4B,CAAC,EAAE;YACrD,OAAO,IAAI,CAAA;SACZ;QACD,IAAI,IAAI,CAAC,eAAe,EAAE;YACxB,OAAO,QAAQ,KAAK,IAAI,CAAC,eAAe,EAAE,CAAA;SAC3C;QACD,OAAO,KAAK,CAAA;IACd,CAAC;IAID,2BAAW,GAAX,UAAY,QAAkB,EAAE,IAAU;QACxC,IAAM,KAAK,GAAG,IAAI,CAAC,SAAS,EAAE,CAAA;QAC9B,IAAI,KAAK,CAAC,IAAI,CAAC,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,WAAW,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAjC,CAAiC,CAAC,EAAE;YAC1D,OAAO,IAAI,CAAA;SACZ;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,CAAC,QAAQ,CAAC,CAAC,CAAA;SAC9C;QACD,OAAO,KAAK,CAAA;IACd,CAAC;IAED,6BAAa,GAAb,UAAc,QAAkB;QAC9B,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC,EAA7B,CAA6B,CAAC,CAAA;IACzE,CAAC;IAED,iCAAiB,GAAjB;QACE,uCAAW,IAAI,CAAC,cAAc,SAAK,IAAI,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,iBAAiB,EAAE,EAAzB,CAAyB,CAAC,QAAC;IAClG,CAAC;IAED,oBAAI,GAAJ,UAAK,IAAU;QACb,KAAoB,UAAgB,EAAhB,KAAA,IAAI,CAAC,SAAS,EAAE,EAAhB,cAAgB,EAAhB,IAAgB,EAAE;YAAjC,IAAM,KAAK,SAAA;YACd,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;SACjB;IACH,CAAC;IAED,sBAAM,GAAN,UAAO,SAAqB;QAA5B,iBAEC;QADC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,UAAA,QAAQ,IAAI,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
|
-
|
|
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>(
|
|
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(
|
|
5
|
-
|
|
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":";;;
|
|
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,9 +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 SequentialGame } from './SequentialGame';
|
|
5
|
-
export { default as SimultaneousGame } from './SimultaneousGame';
|
|
6
|
-
export { default as GameCreator } from './GameCreator';
|
|
7
2
|
export { default as RulesCreator } from './RulesCreator';
|
|
8
3
|
export { default as Action } from './Action';
|
|
9
4
|
export * from './Action';
|
|
@@ -23,3 +18,5 @@ export { default as Robot } from './Robot';
|
|
|
23
18
|
export { default as Dummy } from './Dummy';
|
|
24
19
|
export * from './options';
|
|
25
20
|
export * from './utils';
|
|
21
|
+
export { applyAutomaticMoves } from './ApplyAutomaticMoves';
|
|
22
|
+
export { loopWithFuse } from './LoopWithFuse';
|
package/dist/index.js
CHANGED
|
@@ -17,12 +17,9 @@ 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.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
Object.defineProperty(exports, "SequentialGame", { enumerable: true, get: function () { return __importDefault(SequentialGame_1).default; } });
|
|
24
|
-
var SimultaneousGame_1 = require("./SimultaneousGame");
|
|
25
|
-
Object.defineProperty(exports, "SimultaneousGame", { enumerable: true, get: function () { return __importDefault(SimultaneousGame_1).default; } });
|
|
20
|
+
exports.loopWithFuse = exports.applyAutomaticMoves = exports.Dummy = exports.Rules = void 0;
|
|
21
|
+
var Rules_1 = require("./Rules");
|
|
22
|
+
Object.defineProperty(exports, "Rules", { enumerable: true, get: function () { return __importDefault(Rules_1).default; } });
|
|
26
23
|
__exportStar(require("./Action"), exports);
|
|
27
24
|
__exportStar(require("./IncompleteInformation"), exports);
|
|
28
25
|
__exportStar(require("./Undo"), exports);
|
|
@@ -34,4 +31,8 @@ var Dummy_1 = require("./Dummy");
|
|
|
34
31
|
Object.defineProperty(exports, "Dummy", { enumerable: true, get: function () { return __importDefault(Dummy_1).default; } });
|
|
35
32
|
__exportStar(require("./options"), exports);
|
|
36
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; } });
|
|
37
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":";;;;;;;;;;;;;;;;;;;;
|
|
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.
|
|
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": "
|
|
30
|
+
"gitHead": "f04c7333a2295153061eac50ad910375fc50758c"
|
|
31
31
|
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { IncompleteInformation } from './index';
|
|
2
|
-
import PlayerAction from './PlayerAction';
|
|
3
|
-
declare type ActionWithViews<Move, MoveView, PlayerId> = {
|
|
4
|
-
action: PlayerAction<Move, PlayerId>;
|
|
5
|
-
views: {
|
|
6
|
-
recipient?: PlayerId;
|
|
7
|
-
action: PlayerAction<MoveView, PlayerId>;
|
|
8
|
-
}[];
|
|
9
|
-
};
|
|
10
|
-
export default ActionWithViews;
|
|
11
|
-
export declare function playActionWithViews<State, View, Move, MoveView, PlayerId>(game: IncompleteInformation<State, View, Move, MoveView, PlayerId>, move: Move, playerId: PlayerId, recipients: PlayerId[]): ActionWithViews<Move, MoveView, PlayerId>;
|
package/dist/ActionWithViews.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.playActionWithViews = void 0;
|
|
4
|
-
var index_1 = require("./index");
|
|
5
|
-
function playActionWithViews(game, move, playerId, recipients) {
|
|
6
|
-
var actionWithView = {
|
|
7
|
-
action: { playerId: playerId, move: move, consequences: [] },
|
|
8
|
-
views: []
|
|
9
|
-
};
|
|
10
|
-
game.play(JSON.parse(JSON.stringify(move)));
|
|
11
|
-
// Prepare action view for each player
|
|
12
|
-
for (var _i = 0, recipients_1 = recipients; _i < recipients_1.length; _i++) {
|
|
13
|
-
var recipient = recipients_1[_i];
|
|
14
|
-
actionWithView.views.push({ recipient: recipient, action: { playerId: playerId, move: index_1.getMoveView(game, move, recipient), consequences: [] } });
|
|
15
|
-
}
|
|
16
|
-
// Prepare action view for spectators
|
|
17
|
-
actionWithView.views.push({ action: { playerId: playerId, move: index_1.getMoveView(game, move), consequences: [] } });
|
|
18
|
-
index_1.loopWithFuse(function () {
|
|
19
|
-
var consequence = game.getAutomaticMove ? game.getAutomaticMove() : undefined;
|
|
20
|
-
if (consequence) {
|
|
21
|
-
game.play(JSON.parse(JSON.stringify(consequence)));
|
|
22
|
-
actionWithView.action.consequences.push(consequence);
|
|
23
|
-
for (var _i = 0, _a = actionWithView.views; _i < _a.length; _i++) {
|
|
24
|
-
var view = _a[_i];
|
|
25
|
-
view.action.consequences.push(index_1.getMoveView(game, consequence, view.recipient));
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return consequence !== undefined;
|
|
29
|
-
}, { errorFn: function () { return new Error("Infinite loop detected while applying automatic moves after " + move + " in " + game.state); } });
|
|
30
|
-
return actionWithView;
|
|
31
|
-
}
|
|
32
|
-
exports.playActionWithViews = playActionWithViews;
|
|
33
|
-
//# sourceMappingURL=ActionWithViews.js.map
|