@elara-services/slots
v1.0.0
Published
A slot machine.
Downloads
6
Readme
About
A slot machine that's not accurate to real life at all.
Example
const { SlotMachine, SlotSymbol } = require('...');
const cherry = new SlotSymbol('cherry', {
display: '🍒',
points: 10,
weight: 100
});
const money = new SlotSymbol('money', {
display: '💰',
points: 100,
weight: 50
});
const wild = new SlotSymbol('wild', {
display: '❔',
points: 10,
weight: 50,
wildcard: true
});
const machine = new SlotMachine(3, [cherry, money, wild]);
const results = machine.play();
console.log(results.visualize());Docs
SlotSymbol(name[, options])
nameA unique name for the symbol.options.displayA character to use for displaying.options.pointsAmount of points the symbol gives.options.weightChance of symbol appearing relative to others.options.wildcardWhether or not the symbol is a wildcard.
Creates a new SlotSymbol instance:
nameThe symbol's name.displayThe character for display.pointsAmount of points the symbol gives.weightChance of symbol appearing.wildcardWhether or not the symbol is a wildcard.
SlotMachine(size, symbols[, random])
sizeSize of grid, must be odd number above 3.symbolsArray of SlotSymbols to use.randomFunction returning number [0, 1).
Creates a new SlotMachine instance:
sizeSize of grid.symbolsSymbols to be used.randomFunction returning number [0, 1).
<SlotMachine>.play()
Plays the slot machine and returns the results.=> Results
<SlotMachine>.chanceOf(name)
nameName of a SlotSymbol.
Gets the chance of a symbol appearing.=> number
<Results>
The results of a slot machine play:
linesThe lines generated from the play, where the last two are the major and minor diagonals.totalPointsTotal amount of points from won lines.winCountAmount of lines that have been won.
<Results>.visualize([includeDiagonals])
includeDiagonalsWhether or not to include diagonals in the visualization.
Creates a formatted string from the results.=> string
<EvaluatedLine>
The lines from a slot machine play:
symbolsThe symbols in the line.diagonalWhether or not the line is a diagonal.isWonWhether or not the line is won.pointsThe amount of points this line would give.
