@slot-engine/core 0.1.10 → 0.1.11
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 +47 -18
- package/dist/index.d.ts +47 -18
- package/dist/index.js +338 -217
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +338 -217
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -81,6 +81,22 @@ type GameConfig<TGameModes extends AnyGameModes = AnyGameModes, TSymbols extends
|
|
|
81
81
|
anticipationTriggers: Record<(typeof SPIN_TYPE)[keyof typeof SPIN_TYPE], number>;
|
|
82
82
|
};
|
|
83
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Class for handling simulations of the slot game.
|
|
86
|
+
*
|
|
87
|
+
* High level overview:
|
|
88
|
+
* - Main thread compiles user code to JS and spawns workers
|
|
89
|
+
* - Workers run compiled code to execute simulations
|
|
90
|
+
* - Workers send data to main thread
|
|
91
|
+
* - Main thread merges data and writes files
|
|
92
|
+
*
|
|
93
|
+
* Notes:
|
|
94
|
+
* - Backpressure system with credits to avoid overwhelming the main thread
|
|
95
|
+
* - Limited amount of credits
|
|
96
|
+
* - Worker uses credit to return data to main thread
|
|
97
|
+
* - After writing data, main thread gives worker new credit
|
|
98
|
+
* - Prevents workers sending more data than the main thread can write in time
|
|
99
|
+
*/
|
|
84
100
|
declare class Simulation {
|
|
85
101
|
readonly gameConfigOpts: GameConfigOptions;
|
|
86
102
|
readonly gameConfig: GameConfig;
|
|
@@ -88,10 +104,15 @@ declare class Simulation {
|
|
|
88
104
|
readonly concurrency: number;
|
|
89
105
|
private debug;
|
|
90
106
|
private actualSims;
|
|
91
|
-
private library;
|
|
92
107
|
private wallet;
|
|
93
108
|
private recordsWriteStream;
|
|
94
109
|
private hasWrittenRecord;
|
|
110
|
+
private readonly maxPendingSims;
|
|
111
|
+
private readonly maxHighWaterMark;
|
|
112
|
+
private PATHS;
|
|
113
|
+
private credits;
|
|
114
|
+
private creditWaiters;
|
|
115
|
+
private creditListenerInit;
|
|
95
116
|
constructor(opts: SimulationOptions, gameConfigOpts: GameConfigOptions);
|
|
96
117
|
runSimulation(opts: SimulationConfigOptions): Promise<void>;
|
|
97
118
|
/**
|
|
@@ -99,7 +120,9 @@ declare class Simulation {
|
|
|
99
120
|
*/
|
|
100
121
|
spawnWorkersForGameMode(opts: {
|
|
101
122
|
mode: string;
|
|
102
|
-
|
|
123
|
+
chunks: [number, number][];
|
|
124
|
+
chunkCriteriaCounts: Array<Record<string, number>>;
|
|
125
|
+
totalSims: number;
|
|
103
126
|
}): Promise<void>;
|
|
104
127
|
callWorker(opts: {
|
|
105
128
|
basePath: string;
|
|
@@ -108,6 +131,7 @@ declare class Simulation {
|
|
|
108
131
|
simEnd: number;
|
|
109
132
|
index: number;
|
|
110
133
|
totalSims: number;
|
|
134
|
+
criteriaCounts: Record<string, number>;
|
|
111
135
|
}): Promise<unknown>;
|
|
112
136
|
/**
|
|
113
137
|
* Will run a single simulation until the specified criteria is met.
|
|
@@ -118,6 +142,8 @@ declare class Simulation {
|
|
|
118
142
|
criteria: string;
|
|
119
143
|
index: number;
|
|
120
144
|
}): void;
|
|
145
|
+
private initCreditListener;
|
|
146
|
+
private acquireCredit;
|
|
121
147
|
/**
|
|
122
148
|
* If a simulation does not meet the required criteria, reset the state to run it again.
|
|
123
149
|
*
|
|
@@ -136,16 +162,6 @@ declare class Simulation {
|
|
|
136
162
|
* You can customize the game flow by implementing the `onHandleGameFlow` hook in the game configuration.
|
|
137
163
|
*/
|
|
138
164
|
protected handleGameFlow(ctx: GameContext): void;
|
|
139
|
-
/**
|
|
140
|
-
* Creates a CSV file in the format "simulationId,weight,payout".
|
|
141
|
-
*
|
|
142
|
-
* `weight` defaults to 1.
|
|
143
|
-
*/
|
|
144
|
-
private writeLookupTableCSV;
|
|
145
|
-
/**
|
|
146
|
-
* Creates a CSV file in the format "simulationId,criteria,payoutBase,payoutFreespins".
|
|
147
|
-
*/
|
|
148
|
-
private writeLookupTableSegmentedCSV;
|
|
149
165
|
private writeRecords;
|
|
150
166
|
private writeIndexJson;
|
|
151
167
|
private writeBooksJson;
|
|
@@ -158,6 +174,7 @@ declare class Simulation {
|
|
|
158
174
|
* Generates reelset CSV files for all game modes.
|
|
159
175
|
*/
|
|
160
176
|
private generateReelsetFiles;
|
|
177
|
+
private mergeCsv;
|
|
161
178
|
/**
|
|
162
179
|
* Confirms all pending records and adds them to the main records list.
|
|
163
180
|
*/
|
|
@@ -167,13 +184,29 @@ type SimulationOptions = {
|
|
|
167
184
|
/**
|
|
168
185
|
* Object containing the game modes and their respective simulation runs amount.
|
|
169
186
|
*/
|
|
170
|
-
simRunsAmount:
|
|
187
|
+
simRunsAmount: Record<string, number>;
|
|
171
188
|
/**
|
|
172
189
|
* Number of concurrent processes to use for simulations.
|
|
173
190
|
*
|
|
174
191
|
* Default: 6
|
|
175
192
|
*/
|
|
176
193
|
concurrency?: number;
|
|
194
|
+
/**
|
|
195
|
+
* The maximum number of simulation results to keep pending in memory before writing to disk.
|
|
196
|
+
*
|
|
197
|
+
* Higher values may speed up simulations but use more RAM.
|
|
198
|
+
*
|
|
199
|
+
* Default: 250
|
|
200
|
+
*/
|
|
201
|
+
maxPendingSims?: number;
|
|
202
|
+
/**
|
|
203
|
+
* The maximum data buffer in MB for writing simulation results to disk.
|
|
204
|
+
*
|
|
205
|
+
* Higher values may speed up simulations but use more RAM.
|
|
206
|
+
*
|
|
207
|
+
* Default: 50
|
|
208
|
+
*/
|
|
209
|
+
maxDiskBuffer?: number;
|
|
177
210
|
};
|
|
178
211
|
type SimulationConfigOptions = {
|
|
179
212
|
debug?: boolean;
|
|
@@ -189,7 +222,7 @@ declare class ResultSet<TUserState extends AnyUserData> {
|
|
|
189
222
|
forceFreespins?: boolean;
|
|
190
223
|
evaluate?: (ctx: GameContext<AnyGameModes, AnySymbols, TUserState>) => boolean;
|
|
191
224
|
constructor(opts: ResultSetOpts<TUserState>);
|
|
192
|
-
static
|
|
225
|
+
static getNumberOfSimsForCriteria(ctx: Simulation, gameModeName: string): Record<string, number>;
|
|
193
226
|
/**
|
|
194
227
|
* Checks if core criteria is met, e.g. target multiplier or max win.
|
|
195
228
|
*/
|
|
@@ -614,10 +647,6 @@ declare class Book {
|
|
|
614
647
|
basegameWins: number;
|
|
615
648
|
freespinsWins: number;
|
|
616
649
|
};
|
|
617
|
-
/**
|
|
618
|
-
* Intended for internal use only.
|
|
619
|
-
*/
|
|
620
|
-
static fromSerialized(data: ReturnType<Book["serialize"]>): Book;
|
|
621
650
|
}
|
|
622
651
|
interface BookEvent {
|
|
623
652
|
index: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -81,6 +81,22 @@ type GameConfig<TGameModes extends AnyGameModes = AnyGameModes, TSymbols extends
|
|
|
81
81
|
anticipationTriggers: Record<(typeof SPIN_TYPE)[keyof typeof SPIN_TYPE], number>;
|
|
82
82
|
};
|
|
83
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Class for handling simulations of the slot game.
|
|
86
|
+
*
|
|
87
|
+
* High level overview:
|
|
88
|
+
* - Main thread compiles user code to JS and spawns workers
|
|
89
|
+
* - Workers run compiled code to execute simulations
|
|
90
|
+
* - Workers send data to main thread
|
|
91
|
+
* - Main thread merges data and writes files
|
|
92
|
+
*
|
|
93
|
+
* Notes:
|
|
94
|
+
* - Backpressure system with credits to avoid overwhelming the main thread
|
|
95
|
+
* - Limited amount of credits
|
|
96
|
+
* - Worker uses credit to return data to main thread
|
|
97
|
+
* - After writing data, main thread gives worker new credit
|
|
98
|
+
* - Prevents workers sending more data than the main thread can write in time
|
|
99
|
+
*/
|
|
84
100
|
declare class Simulation {
|
|
85
101
|
readonly gameConfigOpts: GameConfigOptions;
|
|
86
102
|
readonly gameConfig: GameConfig;
|
|
@@ -88,10 +104,15 @@ declare class Simulation {
|
|
|
88
104
|
readonly concurrency: number;
|
|
89
105
|
private debug;
|
|
90
106
|
private actualSims;
|
|
91
|
-
private library;
|
|
92
107
|
private wallet;
|
|
93
108
|
private recordsWriteStream;
|
|
94
109
|
private hasWrittenRecord;
|
|
110
|
+
private readonly maxPendingSims;
|
|
111
|
+
private readonly maxHighWaterMark;
|
|
112
|
+
private PATHS;
|
|
113
|
+
private credits;
|
|
114
|
+
private creditWaiters;
|
|
115
|
+
private creditListenerInit;
|
|
95
116
|
constructor(opts: SimulationOptions, gameConfigOpts: GameConfigOptions);
|
|
96
117
|
runSimulation(opts: SimulationConfigOptions): Promise<void>;
|
|
97
118
|
/**
|
|
@@ -99,7 +120,9 @@ declare class Simulation {
|
|
|
99
120
|
*/
|
|
100
121
|
spawnWorkersForGameMode(opts: {
|
|
101
122
|
mode: string;
|
|
102
|
-
|
|
123
|
+
chunks: [number, number][];
|
|
124
|
+
chunkCriteriaCounts: Array<Record<string, number>>;
|
|
125
|
+
totalSims: number;
|
|
103
126
|
}): Promise<void>;
|
|
104
127
|
callWorker(opts: {
|
|
105
128
|
basePath: string;
|
|
@@ -108,6 +131,7 @@ declare class Simulation {
|
|
|
108
131
|
simEnd: number;
|
|
109
132
|
index: number;
|
|
110
133
|
totalSims: number;
|
|
134
|
+
criteriaCounts: Record<string, number>;
|
|
111
135
|
}): Promise<unknown>;
|
|
112
136
|
/**
|
|
113
137
|
* Will run a single simulation until the specified criteria is met.
|
|
@@ -118,6 +142,8 @@ declare class Simulation {
|
|
|
118
142
|
criteria: string;
|
|
119
143
|
index: number;
|
|
120
144
|
}): void;
|
|
145
|
+
private initCreditListener;
|
|
146
|
+
private acquireCredit;
|
|
121
147
|
/**
|
|
122
148
|
* If a simulation does not meet the required criteria, reset the state to run it again.
|
|
123
149
|
*
|
|
@@ -136,16 +162,6 @@ declare class Simulation {
|
|
|
136
162
|
* You can customize the game flow by implementing the `onHandleGameFlow` hook in the game configuration.
|
|
137
163
|
*/
|
|
138
164
|
protected handleGameFlow(ctx: GameContext): void;
|
|
139
|
-
/**
|
|
140
|
-
* Creates a CSV file in the format "simulationId,weight,payout".
|
|
141
|
-
*
|
|
142
|
-
* `weight` defaults to 1.
|
|
143
|
-
*/
|
|
144
|
-
private writeLookupTableCSV;
|
|
145
|
-
/**
|
|
146
|
-
* Creates a CSV file in the format "simulationId,criteria,payoutBase,payoutFreespins".
|
|
147
|
-
*/
|
|
148
|
-
private writeLookupTableSegmentedCSV;
|
|
149
165
|
private writeRecords;
|
|
150
166
|
private writeIndexJson;
|
|
151
167
|
private writeBooksJson;
|
|
@@ -158,6 +174,7 @@ declare class Simulation {
|
|
|
158
174
|
* Generates reelset CSV files for all game modes.
|
|
159
175
|
*/
|
|
160
176
|
private generateReelsetFiles;
|
|
177
|
+
private mergeCsv;
|
|
161
178
|
/**
|
|
162
179
|
* Confirms all pending records and adds them to the main records list.
|
|
163
180
|
*/
|
|
@@ -167,13 +184,29 @@ type SimulationOptions = {
|
|
|
167
184
|
/**
|
|
168
185
|
* Object containing the game modes and their respective simulation runs amount.
|
|
169
186
|
*/
|
|
170
|
-
simRunsAmount:
|
|
187
|
+
simRunsAmount: Record<string, number>;
|
|
171
188
|
/**
|
|
172
189
|
* Number of concurrent processes to use for simulations.
|
|
173
190
|
*
|
|
174
191
|
* Default: 6
|
|
175
192
|
*/
|
|
176
193
|
concurrency?: number;
|
|
194
|
+
/**
|
|
195
|
+
* The maximum number of simulation results to keep pending in memory before writing to disk.
|
|
196
|
+
*
|
|
197
|
+
* Higher values may speed up simulations but use more RAM.
|
|
198
|
+
*
|
|
199
|
+
* Default: 250
|
|
200
|
+
*/
|
|
201
|
+
maxPendingSims?: number;
|
|
202
|
+
/**
|
|
203
|
+
* The maximum data buffer in MB for writing simulation results to disk.
|
|
204
|
+
*
|
|
205
|
+
* Higher values may speed up simulations but use more RAM.
|
|
206
|
+
*
|
|
207
|
+
* Default: 50
|
|
208
|
+
*/
|
|
209
|
+
maxDiskBuffer?: number;
|
|
177
210
|
};
|
|
178
211
|
type SimulationConfigOptions = {
|
|
179
212
|
debug?: boolean;
|
|
@@ -189,7 +222,7 @@ declare class ResultSet<TUserState extends AnyUserData> {
|
|
|
189
222
|
forceFreespins?: boolean;
|
|
190
223
|
evaluate?: (ctx: GameContext<AnyGameModes, AnySymbols, TUserState>) => boolean;
|
|
191
224
|
constructor(opts: ResultSetOpts<TUserState>);
|
|
192
|
-
static
|
|
225
|
+
static getNumberOfSimsForCriteria(ctx: Simulation, gameModeName: string): Record<string, number>;
|
|
193
226
|
/**
|
|
194
227
|
* Checks if core criteria is met, e.g. target multiplier or max win.
|
|
195
228
|
*/
|
|
@@ -614,10 +647,6 @@ declare class Book {
|
|
|
614
647
|
basegameWins: number;
|
|
615
648
|
freespinsWins: number;
|
|
616
649
|
};
|
|
617
|
-
/**
|
|
618
|
-
* Intended for internal use only.
|
|
619
|
-
*/
|
|
620
|
-
static fromSerialized(data: ReturnType<Book["serialize"]>): Book;
|
|
621
650
|
}
|
|
622
651
|
interface BookEvent {
|
|
623
652
|
index: number;
|