@slot-engine/core 0.0.3 → 0.0.4

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/index.d.mts CHANGED
@@ -603,12 +603,6 @@ declare class GameState<TGameModes extends AnyGameModes, TSymbols extends AnySym
603
603
  */
604
604
  getCurrentGameMode(): GameMode;
605
605
  resetState(): void;
606
- /**
607
- * Checks if a max win is reached by comparing `wallet.currentWin` to `config.maxWin`.
608
- *
609
- * Should be called after `wallet.confirmSpinWin()`.
610
- */
611
- isMaxWinTriggered(): void;
612
606
  /**
613
607
  * Empties the list of pending records in the recorder.
614
608
  */
@@ -769,7 +763,7 @@ declare class Board<TGameModes extends AnyGameModes, TSymbols extends AnySymbols
769
763
  */
770
764
  getRandomReelStops(reels: Reels, reelStops: number[][], amount: number): Record<string, number>;
771
765
  /**
772
- * Selects a random reelset based on the configured weights for the current game mode.\
766
+ * Selects a random reel set based on the configured weights of the current result set.\
773
767
  * Returns the reels as arrays of GameSymbols.
774
768
  */
775
769
  getRandomReelset(): Reels;
@@ -896,7 +890,7 @@ declare class GameConfig<TGameModes extends AnyGameModes = AnyGameModes, TSymbol
896
890
  /**
897
891
  * Retrieves a reel set by its ID within a specific game mode.
898
892
  */
899
- getReelsetById(gameMode: string, id: string): ReelGenerator;
893
+ getReelsetById(gameMode: string, id: string): Reels;
900
894
  /**
901
895
  * Retrieves the number of free spins awarded for a given spin type and scatter count.
902
896
  */
@@ -904,7 +898,7 @@ declare class GameConfig<TGameModes extends AnyGameModes = AnyGameModes, TSymbol
904
898
  /**
905
899
  * Retrieves a result set by its criteria within a specific game mode.
906
900
  */
907
- getGameModeCriteria(mode: string, criteria: string): ResultSet<any>;
901
+ getResultSetByCriteria(mode: string, criteria: string): ResultSet<any>;
908
902
  /**
909
903
  * Returns all configured symbols as an array.
910
904
  */
@@ -1175,64 +1169,14 @@ declare class SlotGame<TGameModes extends AnyGameModes = AnyGameModes, TSymbols
1175
1169
  * @internal
1176
1170
  */
1177
1171
  interface CommonGameOptions<TGameModes extends AnyGameModes = AnyGameModes, TSymbols extends AnySymbols = AnySymbols, TUserState extends AnyUserData = AnyUserData> {
1178
- /**
1179
- * The unique identifier of the game, used for configuration and identification.
1180
- */
1181
1172
  id: string;
1182
- /**
1183
- * The name of the game, used for display purposes.
1184
- */
1185
1173
  name: string;
1186
- /**
1187
- * A GameMode is the core structure of a slot, defining the board,\
1188
- * bet cost, win type, and other properties.
1189
- *
1190
- * One-off mechanisms can also be injected into the core game logic from here.
1191
- */
1192
1174
  gameModes: Record<GameModeName, GameMode>;
1193
- /**
1194
- * A list of all symbols that will appear on the reels.
1195
- */
1196
1175
  symbols: TSymbols;
1197
- /**
1198
- * A mapping from spin type to scatter counts to the number of free spins awarded.
1199
- *
1200
- * @example
1201
- * ```ts
1202
- * scatterToFreespins: {
1203
- * [GameConfig.CONSTANTS.BASE_GAME]: {
1204
- * 3: 10,
1205
- * 4: 12,
1206
- * 5: 15,
1207
- * },
1208
- * [GameConfig.CONSTANTS.FREE_SPINS]: {
1209
- * 3: 6,
1210
- * 4: 8,
1211
- * 5: 10,
1212
- * },
1213
- * },
1214
- * ```
1215
- */
1216
1176
  scatterToFreespins: Record<string, Record<number, number>>;
1217
- /**
1218
- * If set, this will pad the board with symbols on the top and bottom of the reels.\
1219
- * Useful for teasing symbols right above or below the active board.
1220
- *
1221
- * Default: 1
1222
- */
1223
1177
  padSymbols?: number;
1224
- /**
1225
- * The maximum win multiplier of the game, e.g. 5000 for a 5000x max win.
1226
- */
1227
1178
  maxWinX: number;
1228
- /**
1229
- * Hooks are used to inject custom logic at specific points in the game flow.\
1230
- * Some required hooks must be implemented for certain features to work.
1231
- */
1232
1179
  hooks: GameHooks<TGameModes, TSymbols, TUserState>;
1233
- /**
1234
- * Custom additional state that can be used in game flow logic.
1235
- */
1236
1180
  userState?: TUserState;
1237
1181
  }
1238
1182
  /**
@@ -1280,14 +1224,62 @@ type HookContext<T> = T extends SlotGame<infer G, infer S, infer U> ? Simulation
1280
1224
 
1281
1225
  type InferGameType<TGameModes extends AnyGameModes, TSymbols extends AnySymbols, TUserState extends AnyUserData> = SlotGame<TGameModes, TSymbols, TUserState>;
1282
1226
  interface CreateSlotGameOpts<TGameModes extends AnyGameModes = AnyGameModes, TSymbols extends AnySymbols = AnySymbols, TUserState extends AnyUserData = AnyUserData> {
1227
+ /**
1228
+ * The unique identifier of the game, used for configuration and identification.
1229
+ */
1283
1230
  id: CommonGameOptions["id"];
1231
+ /**
1232
+ * The name of the game, used for display purposes.
1233
+ */
1284
1234
  name: CommonGameOptions["name"];
1235
+ /**
1236
+ * A GameMode is the core structure of a slot, defining the board,\
1237
+ * bet cost, win type, and other properties.
1238
+ */
1285
1239
  gameModes: TGameModes;
1240
+ /**
1241
+ * A list of all symbols that will appear on the reels.
1242
+ */
1286
1243
  symbols: TSymbols;
1244
+ /**
1245
+ * A mapping from spin type to scatter counts to the number of free spins awarded.
1246
+ *
1247
+ * @example
1248
+ * ```ts
1249
+ * scatterToFreespins: {
1250
+ * [GameConfig.SPIN_TYPE.BASE_GAME]: {
1251
+ * 3: 10,
1252
+ * 4: 12,
1253
+ * 5: 15,
1254
+ * },
1255
+ * [GameConfig.SPIN_TYPE.FREE_SPINS]: {
1256
+ * 3: 6,
1257
+ * 4: 8,
1258
+ * 5: 10,
1259
+ * },
1260
+ * },
1261
+ * ```
1262
+ */
1287
1263
  scatterToFreespins: CommonGameOptions["scatterToFreespins"];
1264
+ /**
1265
+ * If set, this will pad the board with symbols on the top and bottom of the reels.\
1266
+ * Useful for teasing symbols right above or below the active board.
1267
+ *
1268
+ * Default: 1
1269
+ */
1288
1270
  padSymbols?: CommonGameOptions["padSymbols"];
1271
+ /**
1272
+ * The maximum win multiplier of the game, e.g. 5000 for a 5000x max win.
1273
+ */
1289
1274
  maxWinX: CommonGameOptions["maxWinX"];
1275
+ /**
1276
+ * Custom additional state that can be used in game flow logic.
1277
+ */
1290
1278
  userState?: TUserState;
1279
+ /**
1280
+ * Hooks are used to inject custom logic at specific points in the game flow.\
1281
+ * Some required hooks must be implemented for certain features to work.
1282
+ */
1291
1283
  hooks: CommonGameOptions<TGameModes, TSymbols, TUserState>["hooks"];
1292
1284
  }
1293
1285
  declare function createSlotGame<TGame>(opts: TGame extends InferGameType<infer G, infer S, infer U> ? CreateSlotGameOpts<G, S, U> : never): TGame;
package/dist/index.d.ts CHANGED
@@ -603,12 +603,6 @@ declare class GameState<TGameModes extends AnyGameModes, TSymbols extends AnySym
603
603
  */
604
604
  getCurrentGameMode(): GameMode;
605
605
  resetState(): void;
606
- /**
607
- * Checks if a max win is reached by comparing `wallet.currentWin` to `config.maxWin`.
608
- *
609
- * Should be called after `wallet.confirmSpinWin()`.
610
- */
611
- isMaxWinTriggered(): void;
612
606
  /**
613
607
  * Empties the list of pending records in the recorder.
614
608
  */
@@ -769,7 +763,7 @@ declare class Board<TGameModes extends AnyGameModes, TSymbols extends AnySymbols
769
763
  */
770
764
  getRandomReelStops(reels: Reels, reelStops: number[][], amount: number): Record<string, number>;
771
765
  /**
772
- * Selects a random reelset based on the configured weights for the current game mode.\
766
+ * Selects a random reel set based on the configured weights of the current result set.\
773
767
  * Returns the reels as arrays of GameSymbols.
774
768
  */
775
769
  getRandomReelset(): Reels;
@@ -896,7 +890,7 @@ declare class GameConfig<TGameModes extends AnyGameModes = AnyGameModes, TSymbol
896
890
  /**
897
891
  * Retrieves a reel set by its ID within a specific game mode.
898
892
  */
899
- getReelsetById(gameMode: string, id: string): ReelGenerator;
893
+ getReelsetById(gameMode: string, id: string): Reels;
900
894
  /**
901
895
  * Retrieves the number of free spins awarded for a given spin type and scatter count.
902
896
  */
@@ -904,7 +898,7 @@ declare class GameConfig<TGameModes extends AnyGameModes = AnyGameModes, TSymbol
904
898
  /**
905
899
  * Retrieves a result set by its criteria within a specific game mode.
906
900
  */
907
- getGameModeCriteria(mode: string, criteria: string): ResultSet<any>;
901
+ getResultSetByCriteria(mode: string, criteria: string): ResultSet<any>;
908
902
  /**
909
903
  * Returns all configured symbols as an array.
910
904
  */
@@ -1175,64 +1169,14 @@ declare class SlotGame<TGameModes extends AnyGameModes = AnyGameModes, TSymbols
1175
1169
  * @internal
1176
1170
  */
1177
1171
  interface CommonGameOptions<TGameModes extends AnyGameModes = AnyGameModes, TSymbols extends AnySymbols = AnySymbols, TUserState extends AnyUserData = AnyUserData> {
1178
- /**
1179
- * The unique identifier of the game, used for configuration and identification.
1180
- */
1181
1172
  id: string;
1182
- /**
1183
- * The name of the game, used for display purposes.
1184
- */
1185
1173
  name: string;
1186
- /**
1187
- * A GameMode is the core structure of a slot, defining the board,\
1188
- * bet cost, win type, and other properties.
1189
- *
1190
- * One-off mechanisms can also be injected into the core game logic from here.
1191
- */
1192
1174
  gameModes: Record<GameModeName, GameMode>;
1193
- /**
1194
- * A list of all symbols that will appear on the reels.
1195
- */
1196
1175
  symbols: TSymbols;
1197
- /**
1198
- * A mapping from spin type to scatter counts to the number of free spins awarded.
1199
- *
1200
- * @example
1201
- * ```ts
1202
- * scatterToFreespins: {
1203
- * [GameConfig.CONSTANTS.BASE_GAME]: {
1204
- * 3: 10,
1205
- * 4: 12,
1206
- * 5: 15,
1207
- * },
1208
- * [GameConfig.CONSTANTS.FREE_SPINS]: {
1209
- * 3: 6,
1210
- * 4: 8,
1211
- * 5: 10,
1212
- * },
1213
- * },
1214
- * ```
1215
- */
1216
1176
  scatterToFreespins: Record<string, Record<number, number>>;
1217
- /**
1218
- * If set, this will pad the board with symbols on the top and bottom of the reels.\
1219
- * Useful for teasing symbols right above or below the active board.
1220
- *
1221
- * Default: 1
1222
- */
1223
1177
  padSymbols?: number;
1224
- /**
1225
- * The maximum win multiplier of the game, e.g. 5000 for a 5000x max win.
1226
- */
1227
1178
  maxWinX: number;
1228
- /**
1229
- * Hooks are used to inject custom logic at specific points in the game flow.\
1230
- * Some required hooks must be implemented for certain features to work.
1231
- */
1232
1179
  hooks: GameHooks<TGameModes, TSymbols, TUserState>;
1233
- /**
1234
- * Custom additional state that can be used in game flow logic.
1235
- */
1236
1180
  userState?: TUserState;
1237
1181
  }
1238
1182
  /**
@@ -1280,14 +1224,62 @@ type HookContext<T> = T extends SlotGame<infer G, infer S, infer U> ? Simulation
1280
1224
 
1281
1225
  type InferGameType<TGameModes extends AnyGameModes, TSymbols extends AnySymbols, TUserState extends AnyUserData> = SlotGame<TGameModes, TSymbols, TUserState>;
1282
1226
  interface CreateSlotGameOpts<TGameModes extends AnyGameModes = AnyGameModes, TSymbols extends AnySymbols = AnySymbols, TUserState extends AnyUserData = AnyUserData> {
1227
+ /**
1228
+ * The unique identifier of the game, used for configuration and identification.
1229
+ */
1283
1230
  id: CommonGameOptions["id"];
1231
+ /**
1232
+ * The name of the game, used for display purposes.
1233
+ */
1284
1234
  name: CommonGameOptions["name"];
1235
+ /**
1236
+ * A GameMode is the core structure of a slot, defining the board,\
1237
+ * bet cost, win type, and other properties.
1238
+ */
1285
1239
  gameModes: TGameModes;
1240
+ /**
1241
+ * A list of all symbols that will appear on the reels.
1242
+ */
1286
1243
  symbols: TSymbols;
1244
+ /**
1245
+ * A mapping from spin type to scatter counts to the number of free spins awarded.
1246
+ *
1247
+ * @example
1248
+ * ```ts
1249
+ * scatterToFreespins: {
1250
+ * [GameConfig.SPIN_TYPE.BASE_GAME]: {
1251
+ * 3: 10,
1252
+ * 4: 12,
1253
+ * 5: 15,
1254
+ * },
1255
+ * [GameConfig.SPIN_TYPE.FREE_SPINS]: {
1256
+ * 3: 6,
1257
+ * 4: 8,
1258
+ * 5: 10,
1259
+ * },
1260
+ * },
1261
+ * ```
1262
+ */
1287
1263
  scatterToFreespins: CommonGameOptions["scatterToFreespins"];
1264
+ /**
1265
+ * If set, this will pad the board with symbols on the top and bottom of the reels.\
1266
+ * Useful for teasing symbols right above or below the active board.
1267
+ *
1268
+ * Default: 1
1269
+ */
1288
1270
  padSymbols?: CommonGameOptions["padSymbols"];
1271
+ /**
1272
+ * The maximum win multiplier of the game, e.g. 5000 for a 5000x max win.
1273
+ */
1289
1274
  maxWinX: CommonGameOptions["maxWinX"];
1275
+ /**
1276
+ * Custom additional state that can be used in game flow logic.
1277
+ */
1290
1278
  userState?: TUserState;
1279
+ /**
1280
+ * Hooks are used to inject custom logic at specific points in the game flow.\
1281
+ * Some required hooks must be implemented for certain features to work.
1282
+ */
1291
1283
  hooks: CommonGameOptions<TGameModes, TSymbols, TUserState>["hooks"];
1292
1284
  }
1293
1285
  declare function createSlotGame<TGame>(opts: TGame extends InferGameType<infer G, infer S, infer U> ? CreateSlotGameOpts<G, S, U> : never): TGame;
package/dist/index.js CHANGED
@@ -116,7 +116,7 @@ var GameConfig = class _GameConfig {
116
116
  `Reel set with id "${id}" not found in game mode "${gameMode}". Available reel sets: ${this.config.gameModes[gameMode].reelSets.map((rs) => rs.id).join(", ")}`
117
117
  );
118
118
  }
119
- return reelSet;
119
+ return reelSet.reels;
120
120
  }
121
121
  /**
122
122
  * Retrieves the number of free spins awarded for a given spin type and scatter count.
@@ -133,7 +133,7 @@ var GameConfig = class _GameConfig {
133
133
  /**
134
134
  * Retrieves a result set by its criteria within a specific game mode.
135
135
  */
136
- getGameModeCriteria(mode, criteria) {
136
+ getResultSetByCriteria(mode, criteria) {
137
137
  const gameMode = this.config.gameModes[mode];
138
138
  if (!gameMode) {
139
139
  throw new Error(`Game mode "${mode}" not found in game config.`);
@@ -1103,13 +1103,6 @@ var GameState = class extends GameConfig {
1103
1103
  this.clearPendingRecords();
1104
1104
  this.state.userData = this.config.userState || {};
1105
1105
  }
1106
- /**
1107
- * Checks if a max win is reached by comparing `wallet.currentWin` to `config.maxWin`.
1108
- *
1109
- * Should be called after `wallet.confirmSpinWin()`.
1110
- */
1111
- isMaxWinTriggered() {
1112
- }
1113
1106
  /**
1114
1107
  * Empties the list of pending records in the recorder.
1115
1108
  */
@@ -1555,7 +1548,7 @@ var Board = class extends GameState {
1555
1548
  return stopPositionsForReels;
1556
1549
  }
1557
1550
  /**
1558
- * Selects a random reelset based on the configured weights for the current game mode.\
1551
+ * Selects a random reel set based on the configured weights of the current result set.\
1559
1552
  * Returns the reels as arrays of GameSymbols.
1560
1553
  */
1561
1554
  getRandomReelset() {
@@ -1570,7 +1563,7 @@ var Board = class extends GameState {
1570
1563
  reelSetId = weightedRandom(weights[this.state.currentSpinType], this.state.rng);
1571
1564
  }
1572
1565
  const reelSet = this.getReelsetById(this.state.currentGameMode, reelSetId);
1573
- return reelSet.reels;
1566
+ return reelSet;
1574
1567
  }
1575
1568
  /**
1576
1569
  * Draws a board using specified reel stops.
@@ -2300,22 +2293,25 @@ var SimulationContext = class extends Board {
2300
2293
  this.state.currentGameMode = mode;
2301
2294
  this.state.currentSimulationId = simId;
2302
2295
  this.state.isCriteriaMet = false;
2296
+ const resultSet = this.getResultSetByCriteria(this.state.currentGameMode, criteria);
2303
2297
  while (!this.state.isCriteriaMet) {
2304
2298
  this.actualSims++;
2305
2299
  this.resetSimulation();
2306
- const resultSet = this.getGameModeCriteria(this.state.currentGameMode, criteria);
2307
2300
  this.state.currentResultSet = resultSet;
2308
2301
  this.state.book.criteria = resultSet.criteria;
2309
2302
  this.handleGameFlow();
2310
2303
  if (resultSet.meetsCriteria(this)) {
2311
2304
  this.state.isCriteriaMet = true;
2312
- this.config.hooks.onSimulationAccepted?.(this);
2313
- this.record({
2314
- criteria: resultSet.criteria
2315
- });
2316
2305
  }
2317
2306
  }
2318
2307
  this.wallet.confirmWins(this);
2308
+ if (this.state.book.getPayout() >= this.config.maxWinX) {
2309
+ this.state.triggeredMaxWin = true;
2310
+ }
2311
+ this.record({
2312
+ criteria: resultSet.criteria
2313
+ });
2314
+ this.config.hooks.onSimulationAccepted?.(this);
2319
2315
  this.confirmRecords();
2320
2316
  import_worker_threads2.parentPort?.postMessage({
2321
2317
  type: "complete",