Code Monkey home page Code Monkey logo

slot-machine's Introduction

About

A slot machine that's not accurate to real life at all.

Example

const { SlotMachine, SlotSymbol } = require('../src/index');

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])

  • 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.

slot-machine's People

Contributors

1computer1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

slot-machine's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.