Appearance
Getting Started with hizi engine generator
Installation
The generator is available on the public npm registry. Install it like any other npm package.
bash
npm install @hizi.io/engine-generatorQuick Start
The generator works in three steps. First, simulate outcomes. Then, record them with addResult(). Finally, write output files with start() and end().
typescript
import { HiziEngineGenerator } from '@hizi.io/engine-generator';
const generator = new HiziEngineGenerator();
await generator.start('./output/');
// Creates ./output/ and begins streaming scenarios.jsonl.
// end() writes entries.jsonl and compresses both files to .br
for (const spin of simulate(1_000_000)) {
generator.addResult(spin.scenario, {
win: spin.win,
metaTags: spin.tags,
});
}
await generator.end();Open an output directory with start() before you record any results. Then call addResult() once for each outcome your game engine produces. A scenario carries your own game-specific result data:
typescript
// Your game engine produces an outcome
const win = 50;
const scenario = {
result: {
reelIndexes: [12, 45, 78],
visibleSymbols: [
[2, 3, 1],
[2, 2, 2],
[4, 0, 5],
],
},
};
generator.addResult(scenario, {
win,
metaTags: ['medium-win'],
});Repeat this step for every spin in your simulation. A typical simulation has hundreds of thousands or millions of spins.
The generator writes each scenario straight to disk as you record it. It does not accumulate scenarios in memory, whatever the size of the dataset. The generator keeps up to 1,000 snapshots for each entry. A zero-win (dead spin) entry gets a larger budget of 2,000 snapshots. The generator always tracks the full weight of the entry. Change these limits with the constructor options.
end() is the last step. The hizi engine loads the output files it writes.