@gamepark/rules-api 6.38.5 → 7.0.0-beta.1
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.js +1 -2
- package/dist/Bot.js +15 -37
- package/dist/Bot.js.map +1 -1
- package/dist/Competitive.js +3 -9
- package/dist/Competitive.js.map +1 -1
- package/dist/Eliminations.js +2 -6
- package/dist/Eliminations.js.map +1 -1
- package/dist/GameSetup.js +1 -2
- package/dist/HiddenInformation.js +2 -6
- package/dist/HiddenInformation.js.map +1 -1
- package/dist/LocalMovePreview.js +1 -5
- package/dist/LocalMovePreview.js.map +1 -1
- package/dist/RandomMove.js +1 -2
- package/dist/Rules.js +49 -59
- package/dist/Rules.js.map +1 -1
- package/dist/SecretInformation.d.ts +11 -0
- package/dist/SecretInformation.js +2 -6
- package/dist/SecretInformation.js.map +1 -1
- package/dist/TimeLimit.js +1 -5
- package/dist/TimeLimit.js.map +1 -1
- package/dist/Undo.js +2 -6
- package/dist/Undo.js.map +1 -1
- package/dist/UnpredictableMove.js +1 -5
- package/dist/UnpredictableMove.js.map +1 -1
- package/dist/index.js +16 -32
- package/dist/index.js.map +1 -1
- package/dist/material/HiddenMaterialRules.d.ts +1 -1
- package/dist/material/HiddenMaterialRules.js +125 -189
- package/dist/material/HiddenMaterialRules.js.map +1 -1
- package/dist/material/MaterialGame.js +1 -2
- package/dist/material/MaterialGameSetup.js +52 -70
- package/dist/material/MaterialGameSetup.js.map +1 -1
- package/dist/material/MaterialRules.d.ts +1 -1
- package/dist/material/MaterialRules.js +186 -255
- package/dist/material/MaterialRules.js.map +1 -1
- package/dist/material/SecretMaterialRules.js +9 -35
- package/dist/material/SecretMaterialRules.js.map +1 -1
- package/dist/material/index.js +11 -27
- package/dist/material/index.js.map +1 -1
- package/dist/material/items/Material.js +177 -268
- package/dist/material/items/Material.js.map +1 -1
- package/dist/material/items/MaterialDeck.js +10 -36
- package/dist/material/items/MaterialDeck.js.map +1 -1
- package/dist/material/items/MaterialItem.js +1 -2
- package/dist/material/items/MaterialMoney.js +89 -147
- package/dist/material/items/MaterialMoney.js.map +1 -1
- package/dist/material/items/MaterialMutator.js +108 -149
- package/dist/material/items/MaterialMutator.js.map +1 -1
- package/dist/material/items/index.js +5 -21
- package/dist/material/items/index.js.map +1 -1
- package/dist/material/location/Location.js +1 -14
- package/dist/material/location/Location.js.map +1 -1
- package/dist/material/location/LocationBuilder.js +26 -41
- package/dist/material/location/LocationBuilder.js.map +1 -1
- package/dist/material/location/index.js +3 -19
- package/dist/material/location/index.js.map +1 -1
- package/dist/material/location/strategy/FillGapStrategy.js +9 -16
- package/dist/material/location/strategy/FillGapStrategy.js.map +1 -1
- package/dist/material/location/strategy/LocationStrategy.js +1 -2
- package/dist/material/location/strategy/PositiveSequenceStrategy.js +26 -35
- package/dist/material/location/strategy/PositiveSequenceStrategy.js.map +1 -1
- package/dist/material/location/strategy/StackingStrategy.js +15 -22
- package/dist/material/location/strategy/StackingStrategy.js.map +1 -1
- package/dist/material/location/strategy/index.js +5 -23
- package/dist/material/location/strategy/index.js.map +1 -1
- package/dist/material/memory/GameMemory.js +10 -14
- package/dist/material/memory/GameMemory.js.map +1 -1
- package/dist/material/memory/PlayerMemory.js +13 -18
- package/dist/material/memory/PlayerMemory.js.map +1 -1
- package/dist/material/memory/index.js +2 -18
- package/dist/material/memory/index.js.map +1 -1
- package/dist/material/moves/CustomMove.js +4 -9
- package/dist/material/moves/CustomMove.js.map +1 -1
- package/dist/material/moves/MaterialMove.js +1 -2
- package/dist/material/moves/MaterialMoveBuilder.js +16 -32
- package/dist/material/moves/MaterialMoveBuilder.js.map +1 -1
- package/dist/material/moves/MoveKind.js +2 -5
- package/dist/material/moves/MoveKind.js.map +1 -1
- package/dist/material/moves/index.js +7 -23
- package/dist/material/moves/index.js.map +1 -1
- package/dist/material/moves/items/CreateItem.js +6 -13
- package/dist/material/moves/items/CreateItem.js.map +1 -1
- package/dist/material/moves/items/CreateItemsAtOnce.js +6 -13
- package/dist/material/moves/items/CreateItemsAtOnce.js.map +1 -1
- package/dist/material/moves/items/DeleteItem.js +6 -13
- package/dist/material/moves/items/DeleteItem.js.map +1 -1
- package/dist/material/moves/items/DeleteItemsAtOnce.js +6 -13
- package/dist/material/moves/items/DeleteItemsAtOnce.js.map +1 -1
- package/dist/material/moves/items/ItemMove.js +1 -2
- package/dist/material/moves/items/ItemMoveType.js +2 -5
- package/dist/material/moves/items/ItemMoveType.js.map +1 -1
- package/dist/material/moves/items/MoveItem.js +6 -13
- package/dist/material/moves/items/MoveItem.js.map +1 -1
- package/dist/material/moves/items/MoveItemsAtOnce.js +6 -13
- package/dist/material/moves/items/MoveItemsAtOnce.js.map +1 -1
- package/dist/material/moves/items/RollItem.js +6 -13
- package/dist/material/moves/items/RollItem.js.map +1 -1
- package/dist/material/moves/items/SelectItem.js +6 -13
- package/dist/material/moves/items/SelectItem.js.map +1 -1
- package/dist/material/moves/items/Shuffle.js +7 -15
- package/dist/material/moves/items/Shuffle.js.map +1 -1
- package/dist/material/moves/items/index.js +11 -27
- package/dist/material/moves/items/index.js.map +1 -1
- package/dist/material/moves/local/CloseTutorialPopup.js +4 -8
- package/dist/material/moves/local/CloseTutorialPopup.js.map +1 -1
- package/dist/material/moves/local/DisplayHelp.js +2 -5
- package/dist/material/moves/local/DisplayHelp.js.map +1 -1
- package/dist/material/moves/local/DropItem.js +1 -2
- package/dist/material/moves/local/LocalMove.js +2 -5
- package/dist/material/moves/local/LocalMove.js.map +1 -1
- package/dist/material/moves/local/SetTutorialStep.js +4 -8
- package/dist/material/moves/local/SetTutorialStep.js.map +1 -1
- package/dist/material/moves/local/index.js +5 -21
- package/dist/material/moves/local/index.js.map +1 -1
- package/dist/material/moves/rules/EndGame.js +4 -8
- package/dist/material/moves/rules/EndGame.js.map +1 -1
- package/dist/material/moves/rules/EndPlayerTurn.js +4 -8
- package/dist/material/moves/rules/EndPlayerTurn.js.map +1 -1
- package/dist/material/moves/rules/RuleMove.js +3 -7
- package/dist/material/moves/rules/RuleMove.js.map +1 -1
- package/dist/material/moves/rules/StartPlayerTurn.js +4 -8
- package/dist/material/moves/rules/StartPlayerTurn.js.map +1 -1
- package/dist/material/moves/rules/StartRule.js +4 -8
- package/dist/material/moves/rules/StartRule.js.map +1 -1
- package/dist/material/moves/rules/StartSimultaneousRule.js +4 -8
- package/dist/material/moves/rules/StartSimultaneousRule.js.map +1 -1
- package/dist/material/moves/rules/index.js +6 -22
- package/dist/material/moves/rules/index.js.map +1 -1
- package/dist/material/rules/MaterialRulesPart.d.ts +1 -1
- package/dist/material/rules/MaterialRulesPart.js +38 -63
- package/dist/material/rules/MaterialRulesPart.js.map +1 -1
- package/dist/material/rules/PlayerTurnRule.js +20 -52
- package/dist/material/rules/PlayerTurnRule.js.map +1 -1
- package/dist/material/rules/RuleStep.js +1 -2
- package/dist/material/rules/SimultaneousRule.js +19 -51
- package/dist/material/rules/SimultaneousRule.js.map +1 -1
- package/dist/material/rules/index.js +4 -20
- package/dist/material/rules/index.js.map +1 -1
- package/dist/material/tutorial/TutorialState.js +1 -2
- package/dist/material/tutorial/index.js +1 -17
- package/dist/material/tutorial/index.js.map +1 -1
- package/dist/options/EnumArrayOption.js +3 -7
- package/dist/options/EnumArrayOption.js.map +1 -1
- package/dist/options/EnumOption.js +1 -5
- package/dist/options/EnumOption.js.map +1 -1
- package/dist/options/Option.js +1 -2
- package/dist/options/OptionSpecOf.js +1 -2
- package/dist/options/OptionsSpec.js +1 -2
- package/dist/options/OptionsValidationError.js +6 -28
- package/dist/options/OptionsValidationError.js.map +1 -1
- package/dist/options/PlayerEnumOption.js +19 -33
- package/dist/options/PlayerEnumOption.js.map +1 -1
- package/dist/options/PlayersOptionsSpec.js +1 -2
- package/dist/options/WithIdOption.js +1 -2
- package/dist/options/WithPlayerOptionsSpec.js +1 -5
- package/dist/options/WithPlayerOptionsSpec.js.map +1 -1
- package/dist/options/WithPlayersOptions.js +1 -2
- package/dist/options/index.js +12 -28
- package/dist/options/index.js.map +1 -1
- package/dist/options/isWithPlayerIdOptions.js +3 -7
- package/dist/options/isWithPlayerIdOptions.js.map +1 -1
- package/dist/utils/action-view.util.js +18 -26
- package/dist/utils/action-view.util.js.map +1 -1
- package/dist/utils/action.util.js +11 -17
- package/dist/utils/action.util.js.map +1 -1
- package/dist/utils/adjacent-groups.util.js +33 -42
- package/dist/utils/adjacent-groups.util.js.map +1 -1
- package/dist/utils/automatic-moves.util.js +10 -16
- package/dist/utils/automatic-moves.util.js.map +1 -1
- package/dist/utils/enum.util.js +7 -14
- package/dist/utils/enum.util.js.map +1 -1
- package/dist/utils/game-view.util.js +5 -9
- package/dist/utils/game-view.util.js.map +1 -1
- package/dist/utils/grid.hex.util.js +36 -88
- package/dist/utils/grid.hex.util.js.map +1 -1
- package/dist/utils/grid.squares.util.js +8 -19
- package/dist/utils/grid.squares.util.js.map +1 -1
- package/dist/utils/grid.util.js +1 -5
- package/dist/utils/grid.util.js.map +1 -1
- package/dist/utils/index.js +16 -32
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/listing.util.js +8 -14
- package/dist/utils/listing.util.js.map +1 -1
- package/dist/utils/loops.util.js +3 -7
- package/dist/utils/loops.util.js.map +1 -1
- package/dist/utils/money.util.js +54 -79
- package/dist/utils/money.util.js.map +1 -1
- package/dist/utils/neighbors.util.js +6 -11
- package/dist/utils/neighbors.util.js.map +1 -1
- package/dist/utils/polyhex.util.js +36 -56
- package/dist/utils/polyhex.util.js.map +1 -1
- package/dist/utils/random.util.js +2 -6
- package/dist/utils/random.util.js.map +1 -1
- package/dist/utils/rank.util.js +9 -13
- package/dist/utils/rank.util.js.map +1 -1
- package/package.json +38 -38
- package/dist/ApplyAutomaticMoves.d.ts +0 -2
- package/dist/ApplyAutomaticMoves.js +0 -25
- package/dist/ApplyAutomaticMoves.js.map +0 -1
- package/dist/DefaultGameSetup.d.ts +0 -7
- package/dist/DefaultGameSetup.js +0 -15
- package/dist/DefaultGameSetup.js.map +0 -1
- package/dist/Dummy.d.ts +0 -7
- package/dist/Dummy.js +0 -27
- package/dist/Dummy.js.map +0 -1
- package/dist/GameSetupCreator.d.ts +0 -4
- package/dist/GameSetupCreator.js +0 -3
- package/dist/GameSetupCreator.js.map +0 -1
- package/dist/IncompleteInformation.d.ts +0 -14
- package/dist/IncompleteInformation.js +0 -38
- package/dist/IncompleteInformation.js.map +0 -1
- package/dist/LoopWithFuse.d.ts +0 -4
- package/dist/LoopWithFuse.js +0 -15
- package/dist/LoopWithFuse.js.map +0 -1
- package/dist/Robot.d.ts +0 -1
- package/dist/Robot.js +0 -3
- package/dist/Robot.js.map +0 -1
- package/dist/RulesCreator.d.ts +0 -7
- package/dist/RulesCreator.js +0 -3
- package/dist/RulesCreator.js.map +0 -1
- package/dist/material/location/strategy/StakingStrategy.d.ts +0 -12
- package/dist/material/location/strategy/StakingStrategy.js +0 -32
- package/dist/material/location/strategy/StakingStrategy.js.map +0 -1
- package/dist/material/moves/items/ItemMovesBuilder.d.ts +0 -8
- package/dist/material/moves/items/ItemMovesBuilder.js +0 -34
- package/dist/material/moves/items/ItemMovesBuilder.js.map +0 -1
- package/dist/material/rules/MaterialMoveBuilder.d.ts +0 -9
- package/dist/material/rules/MaterialMoveBuilder.js +0 -28
- package/dist/material/rules/MaterialMoveBuilder.js.map +0 -1
- package/dist/material/rules/MaterialRulesMovesBuilder.d.ts +0 -12
- package/dist/material/rules/MaterialRulesMovesBuilder.js +0 -36
- package/dist/material/rules/MaterialRulesMovesBuilder.js.map +0 -1
- package/dist/setup/DefaultGameSetup.d.ts +0 -7
- package/dist/setup/DefaultGameSetup.js +0 -15
- package/dist/setup/DefaultGameSetup.js.map +0 -1
- package/dist/setup/GameSetup.d.ts +0 -3
- package/dist/setup/GameSetup.js +0 -3
- package/dist/setup/GameSetup.js.map +0 -1
- package/dist/setup/GameSetupCreator.d.ts +0 -4
- package/dist/setup/GameSetupCreator.js +0 -3
- package/dist/setup/GameSetupCreator.js.map +0 -1
- package/dist/setup/index.d.ts +0 -2
- package/dist/setup/index.js +0 -19
- package/dist/setup/index.js.map +0 -1
- package/dist/utils/EnumUtils.d.ts +0 -1
- package/dist/utils/EnumUtils.js +0 -8
- package/dist/utils/EnumUtils.js.map +0 -1
- package/dist/utils/coordinates.util.d.ts +0 -5
- package/dist/utils/coordinates.util.js +0 -16
- package/dist/utils/coordinates.util.js.map +0 -1
- package/dist/utils/isDeadEndMove.util.d.ts +0 -2
- package/dist/utils/isDeadEndMove.util.js +0 -19
- package/dist/utils/isDeadEndMove.util.js.map +0 -1
|
@@ -1,45 +1,10 @@
|
|
|
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 __assign = (this && this.__assign) || function () {
|
|
18
|
-
__assign = Object.assign || function(t) {
|
|
19
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
-
s = arguments[i];
|
|
21
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
-
t[p] = s[p];
|
|
23
|
-
}
|
|
24
|
-
return t;
|
|
25
|
-
};
|
|
26
|
-
return __assign.apply(this, arguments);
|
|
27
|
-
};
|
|
28
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
29
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
|
-
};
|
|
31
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
-
exports.MaterialRules = void 0;
|
|
33
|
-
var difference_1 = __importDefault(require("lodash/difference"));
|
|
34
|
-
var random_1 = __importDefault(require("lodash/random"));
|
|
35
|
-
var shuffle_1 = __importDefault(require("lodash/shuffle"));
|
|
36
|
-
var union_1 = __importDefault(require("lodash/union"));
|
|
37
|
-
var Rules_1 = require("../Rules");
|
|
38
|
-
var TimeLimit_1 = require("../TimeLimit");
|
|
39
|
-
var items_1 = require("./items");
|
|
40
|
-
var memory_1 = require("./memory");
|
|
41
|
-
var moves_1 = require("./moves");
|
|
42
|
-
var rules_1 = require("./rules");
|
|
1
|
+
import { difference, random, shuffle, union } from 'es-toolkit';
|
|
2
|
+
import { Rules } from '../Rules';
|
|
3
|
+
import { hasTimeLimit } from '../TimeLimit';
|
|
4
|
+
import { Material, MaterialMutator } from './items';
|
|
5
|
+
import { GameMemory, PlayerMemory } from './memory';
|
|
6
|
+
import { isEndGame, isRoll, isSelectItem, isShuffle, isStartPlayerTurn, isStartSimultaneousRule, ItemMoveType, LocalMoveType, MaterialMoveBuilder, MoveKind, RuleMoveType } from './moves';
|
|
7
|
+
import { isSimultaneousRule } from './rules';
|
|
43
8
|
/**
|
|
44
9
|
* The MaterialRules class is the main class to implement the rules of a board game with the "Material oriented" approach.
|
|
45
10
|
* With this approach, the game state and the game moves is structured around the game material items and their movements.
|
|
@@ -51,65 +16,42 @@ var rules_1 = require("./rules");
|
|
|
51
16
|
* @typeparam MaterialType - Numeric enum of the types of material manipulated in the game
|
|
52
17
|
* @typeparam LocationType - Numeric enum of the types of location in the game where the material can be located
|
|
53
18
|
*/
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
* Games with more complex use cases can implement their own {@link LocationStrategy}.
|
|
63
|
-
*/
|
|
64
|
-
_this.locationsStrategies = {};
|
|
65
|
-
_this.startPlayerTurn = moves_1.MaterialMoveBuilder.startPlayerTurn;
|
|
66
|
-
_this.startSimultaneousRule = moves_1.MaterialMoveBuilder.startSimultaneousRule;
|
|
67
|
-
_this.startRule = moves_1.MaterialMoveBuilder.startRule;
|
|
68
|
-
_this.customMove = moves_1.MaterialMoveBuilder.customMove;
|
|
69
|
-
_this.endGame = moves_1.MaterialMoveBuilder.endGame;
|
|
70
|
-
return _this;
|
|
71
|
-
}
|
|
19
|
+
export class MaterialRules extends Rules {
|
|
20
|
+
/**
|
|
21
|
+
* The "location strategies" are global rules that always apply in a game when we want to maintain a consistency in the position of the material.
|
|
22
|
+
* For example, we usually want the cards in a player hand to always go from x=0 to x=n without a gap, so we use a {@link PositiveSequenceStrategy} to enforce
|
|
23
|
+
* the rule once and for all. If we want to create a "river" of card we can use a {@link FillGapStrategy}.
|
|
24
|
+
* Games with more complex use cases can implement their own {@link LocationStrategy}.
|
|
25
|
+
*/
|
|
26
|
+
locationsStrategies = {};
|
|
72
27
|
/**
|
|
73
28
|
* Helper function to manipulate the material items of the game. See {@link Material}.
|
|
74
29
|
*
|
|
75
30
|
* @param type The type of Material we want to work on
|
|
76
31
|
* @returns a Material instance to manipulate all the material of that type in current game state.
|
|
77
32
|
*/
|
|
78
|
-
|
|
79
|
-
return new
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
configurable: true
|
|
101
|
-
});
|
|
102
|
-
Object.defineProperty(MaterialRules.prototype, "activePlayers", {
|
|
103
|
-
/**
|
|
104
|
-
* @returns all the active players
|
|
105
|
-
*/
|
|
106
|
-
get: function () {
|
|
107
|
-
var _a, _b, _c;
|
|
108
|
-
return ((_a = this.game.rule) === null || _a === void 0 ? void 0 : _a.player) !== undefined ? [this.game.rule.player] : (_c = (_b = this.game.rule) === null || _b === void 0 ? void 0 : _b.players) !== null && _c !== void 0 ? _c : [];
|
|
109
|
-
},
|
|
110
|
-
enumerable: false,
|
|
111
|
-
configurable: true
|
|
112
|
-
});
|
|
33
|
+
material(type) {
|
|
34
|
+
return new Material(type, this.game.items[type]);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Shortcut for this.game.players
|
|
38
|
+
* @returns array of the players identifiers
|
|
39
|
+
*/
|
|
40
|
+
get players() {
|
|
41
|
+
return this.game.players;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* @return the active player if exactly one player is active
|
|
45
|
+
*/
|
|
46
|
+
get activePlayer() {
|
|
47
|
+
return this.getActivePlayer();
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* @returns all the active players
|
|
51
|
+
*/
|
|
52
|
+
get activePlayers() {
|
|
53
|
+
return this.game.rule?.player !== undefined ? [this.game.rule.player] : this.game.rule?.players ?? [];
|
|
54
|
+
}
|
|
113
55
|
/**
|
|
114
56
|
* Utility function to access the memory tool for the game or on player.
|
|
115
57
|
* this.game.memory can be used to store any data that is not available through the state of the material, or current rule.
|
|
@@ -118,18 +60,18 @@ var MaterialRules = /** @class */ (function (_super) {
|
|
|
118
60
|
* @returns {@link GameMemory} or {@link PlayerMemory} utility
|
|
119
61
|
* @protected
|
|
120
62
|
*/
|
|
121
|
-
|
|
122
|
-
return player === undefined ? new
|
|
123
|
-
}
|
|
63
|
+
getMemory(player) {
|
|
64
|
+
return player === undefined ? new GameMemory(this.game) : new PlayerMemory(this.game, player);
|
|
65
|
+
}
|
|
124
66
|
/**
|
|
125
67
|
* Save a new value inside the memory.
|
|
126
68
|
* @param key The key to index the memorized value.
|
|
127
69
|
* @param value Any JSON serializable value to store, or a function that takes previous stored value and returns the new value to store.
|
|
128
70
|
* @param player optional, if we need to memorize a different value for each player.
|
|
129
71
|
*/
|
|
130
|
-
|
|
72
|
+
memorize(key, value, player) {
|
|
131
73
|
return this.getMemory(player).memorize(key, value);
|
|
132
|
-
}
|
|
74
|
+
}
|
|
133
75
|
/**
|
|
134
76
|
* Retrieve the value memorized under a given key.
|
|
135
77
|
* Shortcut for this.game.memory[key] or this.game.memory[key][player]
|
|
@@ -137,37 +79,38 @@ var MaterialRules = /** @class */ (function (_super) {
|
|
|
137
79
|
* @param key Key under which the memory is store. Usually a value of a numeric enum named "Memory".
|
|
138
80
|
* @param player optional, if we need to memorize a different value for each player.
|
|
139
81
|
*/
|
|
140
|
-
|
|
82
|
+
remind(key, player) {
|
|
141
83
|
return this.getMemory(player).remind(key);
|
|
142
|
-
}
|
|
84
|
+
}
|
|
143
85
|
/**
|
|
144
86
|
* Delete a value from the memory
|
|
145
87
|
* @param key Key of the value to delete
|
|
146
88
|
* @param player optional, if we need to memorize a different value for each player.
|
|
147
89
|
*/
|
|
148
|
-
|
|
90
|
+
forget(key, player) {
|
|
149
91
|
this.getMemory(player).forget(key);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
92
|
+
}
|
|
93
|
+
startPlayerTurn = MaterialMoveBuilder.startPlayerTurn;
|
|
94
|
+
startSimultaneousRule = MaterialMoveBuilder.startSimultaneousRule;
|
|
95
|
+
startRule = MaterialMoveBuilder.startRule;
|
|
96
|
+
customMove = MaterialMoveBuilder.customMove;
|
|
97
|
+
endGame = MaterialMoveBuilder.endGame;
|
|
98
|
+
/**
|
|
99
|
+
* Instantiates the class that handled the rules of the game corresponding to the current rule id.
|
|
100
|
+
* This function reads the current value in this.game.rule.id and instantiate the corresponding class in the {@link rules} property.
|
|
101
|
+
*
|
|
102
|
+
* @returns the class that handled the rules of the game, at current specific game state.
|
|
103
|
+
*/
|
|
104
|
+
get rulesStep() {
|
|
105
|
+
if (!this.game.rule)
|
|
106
|
+
return;
|
|
107
|
+
const RulesStep = this.rules[this.game.rule.id];
|
|
108
|
+
if (!RulesStep) {
|
|
109
|
+
console.error(`The rules class for rules id ${this.game.rule.id} is missing`);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
return new RulesStep(this.game);
|
|
113
|
+
}
|
|
171
114
|
/**
|
|
172
115
|
* Returns a utility class to change the state of the items.
|
|
173
116
|
* Used by the framework to apply the Material moves on the items (should not be manipulated directly in the games).
|
|
@@ -175,11 +118,11 @@ var MaterialRules = /** @class */ (function (_super) {
|
|
|
175
118
|
* @param type MaterialType of the item we want to modify
|
|
176
119
|
* @returns a MaterialMutator to change the state of the items
|
|
177
120
|
*/
|
|
178
|
-
|
|
121
|
+
mutator(type) {
|
|
179
122
|
if (!this.game.items[type])
|
|
180
123
|
this.game.items[type] = [];
|
|
181
|
-
return new
|
|
182
|
-
}
|
|
124
|
+
return new MaterialMutator(type, this.game.items[type], this.locationsStrategies[type], this.itemsCanMerge(type));
|
|
125
|
+
}
|
|
183
126
|
/**
|
|
184
127
|
* Items can sometime be stored with a quantity (for example, coins).
|
|
185
128
|
* By default, if you create or move similar items to the exact same location, they will merge into one item with a quantity.
|
|
@@ -188,29 +131,29 @@ var MaterialRules = /** @class */ (function (_super) {
|
|
|
188
131
|
* @param _type type of items
|
|
189
132
|
* @returns true if items can merge into one item with a quantity (default behavior)
|
|
190
133
|
*/
|
|
191
|
-
|
|
134
|
+
itemsCanMerge(_type) {
|
|
192
135
|
return true;
|
|
193
|
-
}
|
|
136
|
+
}
|
|
194
137
|
/**
|
|
195
138
|
* In the material approach, the rules behavior is delegated to the current {@link rulesStep}. See {@link Rules.delegate}
|
|
196
139
|
*/
|
|
197
|
-
|
|
140
|
+
delegate() {
|
|
198
141
|
return this.rulesStep;
|
|
199
|
-
}
|
|
142
|
+
}
|
|
200
143
|
/**
|
|
201
144
|
* Randomize Shuffle of Roll moves (see {@link RandomMove.randomize})
|
|
202
145
|
* @param move The Material Move to randomize
|
|
203
146
|
* @returns the randomized move
|
|
204
147
|
*/
|
|
205
|
-
|
|
206
|
-
if (
|
|
207
|
-
return
|
|
148
|
+
randomize(move) {
|
|
149
|
+
if (isShuffle(move)) {
|
|
150
|
+
return { ...move, newIndexes: shuffle(move.indexes) };
|
|
208
151
|
}
|
|
209
|
-
else if (
|
|
210
|
-
return
|
|
152
|
+
else if (isRoll(move)) {
|
|
153
|
+
return { ...move, location: { ...move.location, rotation: this.roll(move) } };
|
|
211
154
|
}
|
|
212
155
|
return move;
|
|
213
|
-
}
|
|
156
|
+
}
|
|
214
157
|
/**
|
|
215
158
|
* When a RollItem move is create, it has to be randomized on the server side before it is saved and shared.
|
|
216
159
|
* This function provides the random value. By default, it returns a value between 0 and 5 assuming a 6 sided dice is rolled.
|
|
@@ -219,9 +162,9 @@ var MaterialRules = /** @class */ (function (_super) {
|
|
|
219
162
|
* @param _move The RollItem move to randomize
|
|
220
163
|
* @returns a random rolled value, by default a value between 0 and 5 (cubic dice result)
|
|
221
164
|
*/
|
|
222
|
-
|
|
223
|
-
return (
|
|
224
|
-
}
|
|
165
|
+
roll(_move) {
|
|
166
|
+
return random(5);
|
|
167
|
+
}
|
|
225
168
|
/**
|
|
226
169
|
* Execution of the Material Moves. See {@link Rules.play}.
|
|
227
170
|
*
|
|
@@ -229,136 +172,131 @@ var MaterialRules = /** @class */ (function (_super) {
|
|
|
229
172
|
* @param context Context in which the move was played
|
|
230
173
|
* @returns Consequences of the move
|
|
231
174
|
*/
|
|
232
|
-
|
|
233
|
-
|
|
175
|
+
play(move, context) {
|
|
176
|
+
const consequences = [];
|
|
234
177
|
switch (move.kind) {
|
|
235
|
-
case
|
|
236
|
-
consequences.push
|
|
178
|
+
case MoveKind.ItemMove:
|
|
179
|
+
consequences.push(...this.onPlayItemMove(move, context));
|
|
237
180
|
break;
|
|
238
|
-
case
|
|
239
|
-
consequences.push
|
|
181
|
+
case MoveKind.RulesMove:
|
|
182
|
+
consequences.push(...this.onPlayRulesMove(move, context));
|
|
240
183
|
break;
|
|
241
|
-
case
|
|
242
|
-
consequences.push
|
|
184
|
+
case MoveKind.CustomMove:
|
|
185
|
+
consequences.push(...this.onCustomMove(move, context));
|
|
243
186
|
break;
|
|
244
|
-
case
|
|
187
|
+
case MoveKind.LocalMove:
|
|
245
188
|
switch (move.type) {
|
|
246
|
-
case
|
|
189
|
+
case LocalMoveType.DisplayHelp:
|
|
247
190
|
this.game.helpDisplay = move.helpDisplay;
|
|
248
191
|
break;
|
|
249
|
-
case
|
|
192
|
+
case LocalMoveType.DropItem:
|
|
250
193
|
if (!this.game.droppedItems) {
|
|
251
194
|
this.game.droppedItems = [];
|
|
252
195
|
}
|
|
253
196
|
this.game.droppedItems.push(move.item);
|
|
254
197
|
break;
|
|
255
|
-
case
|
|
198
|
+
case LocalMoveType.SetTutorialStep:
|
|
256
199
|
this.game.tutorial.step = move.step;
|
|
257
200
|
this.game.tutorial.stepComplete = false;
|
|
258
201
|
this.game.tutorial.popupClosed = false;
|
|
259
202
|
break;
|
|
260
|
-
case
|
|
203
|
+
case LocalMoveType.CloseTutorialPopup:
|
|
261
204
|
this.game.tutorial.popupClosed = true;
|
|
262
205
|
}
|
|
263
206
|
}
|
|
264
|
-
|
|
207
|
+
const endGameIndex = consequences.findIndex(isEndGame);
|
|
265
208
|
if (endGameIndex !== -1) {
|
|
266
209
|
return consequences.slice(0, endGameIndex + 1);
|
|
267
210
|
}
|
|
268
211
|
return consequences;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
if (!
|
|
273
|
-
consequences.push
|
|
212
|
+
}
|
|
213
|
+
onPlayItemMove(move, context) {
|
|
214
|
+
const consequences = [];
|
|
215
|
+
if (!context?.transient) {
|
|
216
|
+
consequences.push(...this.beforeItemMove(move, context));
|
|
274
217
|
}
|
|
275
218
|
if (!this.game.items[move.itemType])
|
|
276
219
|
this.game.items[move.itemType] = [];
|
|
277
|
-
|
|
220
|
+
const mutator = this.mutator(move.itemType);
|
|
278
221
|
mutator.applyMove(move);
|
|
279
222
|
if (this.game.droppedItems) {
|
|
280
|
-
this.game.droppedItems = this.game.droppedItems.filter(
|
|
223
|
+
this.game.droppedItems = this.game.droppedItems.filter((droppedItem) => {
|
|
281
224
|
if (move.itemType !== droppedItem.type) {
|
|
282
225
|
return true;
|
|
283
226
|
}
|
|
284
227
|
switch (move.type) {
|
|
285
|
-
case
|
|
286
|
-
case
|
|
228
|
+
case ItemMoveType.Move:
|
|
229
|
+
case ItemMoveType.Delete:
|
|
287
230
|
return move.itemIndex !== droppedItem.index;
|
|
288
|
-
case
|
|
231
|
+
case ItemMoveType.MoveAtOnce:
|
|
289
232
|
return !move.indexes.includes(droppedItem.index);
|
|
290
233
|
}
|
|
291
234
|
});
|
|
292
235
|
}
|
|
293
|
-
|
|
294
|
-
if (context
|
|
236
|
+
const indexes = getItemMoveIndexes(move);
|
|
237
|
+
if (context?.transient) {
|
|
295
238
|
if (!this.game.transientItems)
|
|
296
239
|
this.game.transientItems = {};
|
|
297
|
-
this.game.transientItems[move.itemType] = (
|
|
240
|
+
this.game.transientItems[move.itemType] = union(this.game.transientItems[move.itemType] ?? [], indexes);
|
|
298
241
|
}
|
|
299
242
|
else if (this.game.transientItems) {
|
|
300
|
-
this.game.transientItems[move.itemType] = (
|
|
243
|
+
this.game.transientItems[move.itemType] = difference(this.game.transientItems[move.itemType] ?? [], indexes);
|
|
301
244
|
}
|
|
302
|
-
if (!
|
|
303
|
-
consequences.push
|
|
245
|
+
if (!context?.transient) {
|
|
246
|
+
consequences.push(...this.afterItemMove(move, context));
|
|
304
247
|
}
|
|
305
248
|
return consequences;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
if ((_b = (_a = this.game.rule) === null || _a === void 0 ? void 0 : _a.players) === null || _b === void 0 ? void 0 : _b.includes(move.player)) {
|
|
325
|
-
this.game.rule.players = this.game.rule.players.filter(function (player) { return player !== move.player; });
|
|
326
|
-
if ((0, rules_1.isSimultaneousRule)(rulesStep)) {
|
|
327
|
-
consequences.push.apply(consequences, rulesStep.onPlayerTurnEnd(move, context));
|
|
249
|
+
}
|
|
250
|
+
beforeItemMove(move, context) {
|
|
251
|
+
return this.rulesStep?.beforeItemMove(move, context) ?? [];
|
|
252
|
+
}
|
|
253
|
+
afterItemMove(move, context) {
|
|
254
|
+
return this.rulesStep?.afterItemMove(move, context) ?? [];
|
|
255
|
+
}
|
|
256
|
+
onCustomMove(move, context) {
|
|
257
|
+
return this.rulesStep?.onCustomMove(move, context) ?? [];
|
|
258
|
+
}
|
|
259
|
+
onPlayRulesMove(move, context) {
|
|
260
|
+
const consequences = [];
|
|
261
|
+
const rulesStep = this.rulesStep;
|
|
262
|
+
if (move.type === RuleMoveType.EndPlayerTurn) {
|
|
263
|
+
if (this.game.rule?.players?.includes(move.player)) {
|
|
264
|
+
this.game.rule.players = this.game.rule.players.filter(player => player !== move.player);
|
|
265
|
+
if (isSimultaneousRule(rulesStep)) {
|
|
266
|
+
consequences.push(...rulesStep.onPlayerTurnEnd(move, context));
|
|
328
267
|
if (this.game.rule.players.length === 0) {
|
|
329
|
-
consequences.push
|
|
268
|
+
consequences.push(...rulesStep.getMovesAfterPlayersDone());
|
|
330
269
|
}
|
|
331
270
|
}
|
|
332
271
|
}
|
|
333
272
|
else {
|
|
334
|
-
console.warn(
|
|
273
|
+
console.warn(`${this.constructor.name}: endPlayerTurn was triggered for player ${move.player} which is already inactive: ${JSON.parse(JSON.stringify(this.game.rule))}`);
|
|
335
274
|
}
|
|
336
275
|
}
|
|
337
276
|
else {
|
|
338
|
-
consequences.push
|
|
277
|
+
consequences.push(...this.changeRule(move, context));
|
|
339
278
|
}
|
|
340
279
|
return consequences;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
var rule = this.game.rule;
|
|
280
|
+
}
|
|
281
|
+
changeRule(move, context) {
|
|
282
|
+
const moves = this.rulesStep?.onRuleEnd(move, context) ?? [];
|
|
283
|
+
const rule = this.game.rule;
|
|
346
284
|
switch (move.type) {
|
|
347
|
-
case
|
|
285
|
+
case RuleMoveType.StartPlayerTurn:
|
|
348
286
|
this.game.rule = { id: move.id, player: move.player };
|
|
349
287
|
break;
|
|
350
|
-
case
|
|
351
|
-
this.game.rule = { id: move.id, players:
|
|
288
|
+
case RuleMoveType.StartSimultaneousRule:
|
|
289
|
+
this.game.rule = { id: move.id, players: move.players ?? this.game.players };
|
|
352
290
|
break;
|
|
353
|
-
case
|
|
354
|
-
this.game.rule = { id: move.id, player:
|
|
291
|
+
case RuleMoveType.StartRule:
|
|
292
|
+
this.game.rule = { id: move.id, player: this.game.rule?.player };
|
|
355
293
|
break;
|
|
356
|
-
case
|
|
294
|
+
case RuleMoveType.EndGame:
|
|
357
295
|
delete this.game.rule;
|
|
358
296
|
break;
|
|
359
297
|
}
|
|
360
|
-
return moves.concat(
|
|
361
|
-
}
|
|
298
|
+
return moves.concat(this.rulesStep?.onRuleStart(move, rule, context) ?? []);
|
|
299
|
+
}
|
|
362
300
|
/**
|
|
363
301
|
* By default, a Material Move can be undone if no player became active and no dice was rolled.
|
|
364
302
|
* See {@link Undo.canUndo} and {@link HiddenMaterialRules.canUndo}
|
|
@@ -367,41 +305,41 @@ var MaterialRules = /** @class */ (function (_super) {
|
|
|
367
305
|
* @param consecutiveActions Action played in between
|
|
368
306
|
* @returns true if the action can be undone by the player that played it
|
|
369
307
|
*/
|
|
370
|
-
|
|
371
|
-
for (
|
|
308
|
+
canUndo(action, consecutiveActions) {
|
|
309
|
+
for (let i = consecutiveActions.length - 1; i >= 0; i--) {
|
|
372
310
|
if (this.consecutiveActionBlocksUndo(action, consecutiveActions[i])) {
|
|
373
311
|
return false;
|
|
374
312
|
}
|
|
375
313
|
}
|
|
376
314
|
return !this.actionBlocksUndo(action);
|
|
377
|
-
}
|
|
378
|
-
|
|
315
|
+
}
|
|
316
|
+
consecutiveActionBlocksUndo(action, consecutiveAction) {
|
|
379
317
|
if (this.actionActivatesPlayer(consecutiveAction)) {
|
|
380
318
|
return true;
|
|
381
319
|
}
|
|
382
320
|
if (consecutiveAction.playerId === action.playerId) {
|
|
383
|
-
if (!
|
|
321
|
+
if (!isSelectItem(consecutiveAction.move) || !isSelectItem(action.move)) {
|
|
384
322
|
return true;
|
|
385
323
|
}
|
|
386
324
|
}
|
|
387
325
|
return false;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
for (
|
|
326
|
+
}
|
|
327
|
+
actionBlocksUndo(action) {
|
|
328
|
+
for (let i = action.consequences.length - 1; i >= 0; i--) {
|
|
391
329
|
if (this.moveBlocksUndo(action.consequences[i], action.playerId)) {
|
|
392
330
|
return true;
|
|
393
331
|
}
|
|
394
332
|
}
|
|
395
333
|
return this.moveBlocksUndo(action.move, action.playerId);
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
for (
|
|
334
|
+
}
|
|
335
|
+
actionActivatesPlayer(action) {
|
|
336
|
+
for (let i = action.consequences.length - 1; i >= 0; i--) {
|
|
399
337
|
if (this.moveActivatesPlayer(action.consequences[i])) {
|
|
400
338
|
return true;
|
|
401
339
|
}
|
|
402
340
|
}
|
|
403
341
|
return this.moveActivatesPlayer(action.move);
|
|
404
|
-
}
|
|
342
|
+
}
|
|
405
343
|
/**
|
|
406
344
|
* @protected
|
|
407
345
|
* If a moves blocks the undo, any action with this move cannot be undone.
|
|
@@ -411,28 +349,23 @@ var MaterialRules = /** @class */ (function (_super) {
|
|
|
411
349
|
* @param player The player that triggered the move
|
|
412
350
|
* @returns true if the move blocks the undo
|
|
413
351
|
*/
|
|
414
|
-
|
|
415
|
-
return this.moveActivatesPlayer(move, player) ||
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
};
|
|
352
|
+
moveBlocksUndo(move, player) {
|
|
353
|
+
return this.moveActivatesPlayer(move, player) || isRoll(move);
|
|
354
|
+
}
|
|
355
|
+
moveActivatesPlayer(move, player) {
|
|
356
|
+
return (isStartPlayerTurn(move) && move.player !== player)
|
|
357
|
+
|| (isStartSimultaneousRule(move) && (move.players ?? this.game.players).some((p) => p !== player));
|
|
358
|
+
}
|
|
422
359
|
/**
|
|
423
360
|
* Restore help display & local item moves
|
|
424
361
|
*/
|
|
425
|
-
|
|
426
|
-
var _this = this;
|
|
362
|
+
restoreTransientState(previousState) {
|
|
427
363
|
this.game.helpDisplay = previousState.helpDisplay;
|
|
428
364
|
this.game.transientItems = previousState.transientItems;
|
|
429
|
-
|
|
430
|
-
previousState.transientItems[type].forEach(
|
|
431
|
-
};
|
|
432
|
-
for (var type in previousState.transientItems) {
|
|
433
|
-
_loop_1(type);
|
|
365
|
+
for (const type in previousState.transientItems) {
|
|
366
|
+
previousState.transientItems[type].forEach(index => this.game.items[type][index] = previousState.items[type][index]);
|
|
434
367
|
}
|
|
435
|
-
}
|
|
368
|
+
}
|
|
436
369
|
/**
|
|
437
370
|
* Random moves, or moves that reveals something to me, are unpredictable.
|
|
438
371
|
* Unpredictable moves cannot be precomputed on client side, the server side's response is necessary.
|
|
@@ -442,39 +375,37 @@ var MaterialRules = /** @class */ (function (_super) {
|
|
|
442
375
|
* @param _player The player playing the move
|
|
443
376
|
* @returns true if the move outcome cannot be predicted on client side
|
|
444
377
|
*/
|
|
445
|
-
|
|
446
|
-
return
|
|
447
|
-
}
|
|
378
|
+
isUnpredictableMove(move, _player) {
|
|
379
|
+
return isRoll(move);
|
|
380
|
+
}
|
|
448
381
|
/**
|
|
449
382
|
* A Material Game is over when there is no rule left to execute. This state results of a {@link EndGame} move.
|
|
450
383
|
*
|
|
451
384
|
* @returns true if game is over
|
|
452
385
|
*/
|
|
453
|
-
|
|
386
|
+
isOver() {
|
|
454
387
|
return !this.game.rule;
|
|
455
|
-
}
|
|
388
|
+
}
|
|
456
389
|
/**
|
|
457
390
|
* Amount of time given to a player everytime it is their turn to play.
|
|
458
391
|
* @param playerId Id of the player, if you want to give different time depending on the id for asymmetric games.
|
|
459
392
|
* @return number of seconds to add to the player's clock
|
|
460
393
|
*/
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
return rule &&
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
}(Rules_1.Rules));
|
|
467
|
-
exports.MaterialRules = MaterialRules;
|
|
394
|
+
giveTime(playerId) {
|
|
395
|
+
const rule = this.rulesStep;
|
|
396
|
+
return rule && hasTimeLimit(rule) ? rule.giveTime(playerId) : 60;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
468
399
|
function getItemMoveIndexes(move) {
|
|
469
400
|
switch (move.type) {
|
|
470
|
-
case
|
|
471
|
-
case
|
|
472
|
-
case
|
|
473
|
-
case
|
|
401
|
+
case ItemMoveType.Move:
|
|
402
|
+
case ItemMoveType.Delete:
|
|
403
|
+
case ItemMoveType.Roll:
|
|
404
|
+
case ItemMoveType.Select:
|
|
474
405
|
return [move.itemIndex];
|
|
475
|
-
case
|
|
476
|
-
case
|
|
477
|
-
case
|
|
406
|
+
case ItemMoveType.MoveAtOnce:
|
|
407
|
+
case ItemMoveType.DeleteAtOnce:
|
|
408
|
+
case ItemMoveType.Shuffle:
|
|
478
409
|
return move.indexes;
|
|
479
410
|
default:
|
|
480
411
|
return [];
|