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