Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

slot-machine

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

slot-machine - npm Package Compare versions

Comparing version 2.0.2 to 2.1.0

src/index.d.ts

9

.eslintrc.json
{
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 8
"ecmaVersion": 6
},

@@ -45,3 +45,3 @@ "env": {

"eqeqeq": ["error", "smart"],
"no-console": "off",
"no-console": "error",
"no-empty-function": "error",

@@ -119,3 +119,3 @@ "no-floating-decimal": "error",

"quote-props": ["error", "as-needed"],
"quotes": ["error", "single", { "avoidEscape": true, "allowTemplateLiterals": true }],
"quotes": ["error", "single"],
"semi-spacing": "error",

@@ -136,2 +136,3 @@ "semi": "error",

"no-useless-constructor": "error",
"prefer-const": "error",
"prefer-arrow-callback": "error",

@@ -146,2 +147,2 @@ "prefer-numeric-literals": "error",

}
}
}
{
"name": "slot-machine",
"version": "2.0.2",
"version": "2.1.0",
"description": "A slot machine.",
"main": "src/index.js",
"main": "./src/index.js",
"types": "./src/index.d.ts",
"keywords": ["slot machine", "slots", "gambling", "rng"],

@@ -7,0 +8,0 @@ "author": "1Computer",

@@ -1,4 +0,9 @@

### Usage
# About
A slot machine that's not accurate to real life at all.
# Example
```js
const { SlotMachine, SlotSymbol } = require('slot-machine');
const { SlotMachine, SlotSymbol } = require('../src/index');

@@ -27,16 +32,69 @@ const cherry = new SlotSymbol('cherry', {

results.visualize(true);
// 🍒 🍒 💰
// 💰 💰 🍒
// ❔ 🍒 🍒
//
// 🍒 💰 🍒
// 💰 💰 ❔
console.log(results.visualize());
```
results.totalPoints; // 240
results.winCount; // 2
results.lines[0].symbols; // [cherry, cherry, money]
results.lines[1].points; // 0
results.lines[2].isWon; // true
results.lines[3].diagonal; // true
```
# Docs
### `SlotSymbol(name[, options])`
- `name` A unique name for the symbol.
- `options.display` A character to use for displaying.
- `options.points` Amount of points the symbol gives.
- `options.weight` Chance of symbol appearing relative to others.
- `options.wildcard` Whether or not the symbol is a wildcard.
Creates a new SlotSymbol instance:
- `name` The symbol's name.
- `display` The character for display.
- `points` Amount of points the symbol gives.
- `weight` Chance of symbol appearing.
- `wildcard` Whether or not the symbol is a wildcard.
### `SlotMachine(size, symbols[, random])`
- `size` Size of grid, must be odd number above 3.
- `symbols` Array of SlotSymbols to use.
- `random` Function returning number [0, 1).
Creates a new SlotMachine instance:
- `size` Size of grid.
- `symbols` Symbols to be used.
- `random` Function returning number [0, 1).
##### `<SlotMachine>.play()`
Plays the slot machine and returns the results.
`=> Results`
##### `<SlotMachine>.chanceOf(name)`
- `name` Name of a SlotSymbol.
Gets the chance of a symbol appearing.
`=> number`
### `<Results>`
The results of a slot machine play:
- `lines` The lines generated from the play, where the last two are the major and minor diagonals.
- `totalPoints` Total amount of points from won lines.
- `winCount` Amount of lines that have been won.
##### `<Results>.visualize([includeDiagonals])`
- `includeDiagonals` Whether or not to include diagonals in the visualization.
Creates a formatted string from the results.
`=> string`
### `<EvaluatedLine>`
The lines from a slot machine play:
- `symbols` The symbols in the line.
- `diagonal` Whether or not the line is a diagonal.
- `isWon` Whether or not the line is won.
- `points` The amount of points this line would give.

@@ -9,4 +9,5 @@ const EvaluatedLine = require('./EvaluatedLine');

* @param {Symbol[]} symbols - Array of symbols to use.
* @param {Function} [random] - A function that returns a number [0, 1).
*/
constructor(size = 3, symbols = []) {
constructor(size = 3, symbols = [], random = () => Math.random()) {
if (size % 2 === 0 || size < 3) throw new RangeError('Slot machine size must be an odd number, 3 or higher.');

@@ -26,2 +27,9 @@ if (!symbols.length) throw new RangeError('There must be at least one symbol.');

this.symbols = symbols;
/**
* The function used for randomizing.
* Returns [0, 1).
* @returns {number}
*/
this.random = random;
}

@@ -38,3 +46,3 @@

for (let i = 0; i < Math.pow(this.size, 2); i++) {
const rand = Math.random() * totalWeight;
const rand = this.random() * totalWeight;
let sum = 0;

@@ -41,0 +49,0 @@

@@ -0,1 +1,3 @@

/* eslint-disable no-console */
const { SlotMachine, SlotSymbol } = require('../src/index');

@@ -26,2 +28,3 @@

console.log(results.visualize(true));
console.log(results.lines.map(l => l.isWon));
console.log(results.totalPoints, results.winCount);

@@ -28,0 +31,0 @@ console.log(results.lines[0].symbols);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc