slot-machine
Advanced tools
Comparing version 2.0.0 to 2.0.1
{ | ||
"env": { | ||
"es6": true, | ||
"node": true | ||
}, | ||
"extends": "eslint:recommended", | ||
"parserOptions": { | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
"no-console": "off", | ||
"no-extra-parens": "error", | ||
"no-var": "error", | ||
"no-shadow": [ | ||
"error", | ||
{ "allow": ["err", "resolve", "reject"] } | ||
], | ||
"no-trailing-spaces": [ | ||
"error", | ||
{ "skipBlankLines": true } | ||
], | ||
"handle-callback-err": "off", | ||
"yoda": "error", | ||
"block-spacing": "error", | ||
"object-curly-spacing": ["error", "always"], | ||
"prefer-const": "error", | ||
"indent": [ | ||
"error", | ||
4 | ||
], | ||
"quotes": [ | ||
"error", | ||
"single" | ||
], | ||
"semi": [ | ||
"error", | ||
"always" | ||
] | ||
} | ||
} | ||
"extends": "eslint:recommended", | ||
"parserOptions": { | ||
"ecmaVersion": 8 | ||
}, | ||
"env": { | ||
"es6": true, | ||
"node": true | ||
}, | ||
"rules": { | ||
"no-await-in-loop": "warn", | ||
"no-extra-parens": ["warn", "all", { | ||
"nestedBinaryExpressions": false | ||
}], | ||
"no-template-curly-in-string": "error", | ||
"no-unsafe-negation": "error", | ||
"valid-jsdoc": ["error", { | ||
"requireReturn": false, | ||
"requireReturnDescription": false, | ||
"prefer": { | ||
"return": "returns", | ||
"arg": "param" | ||
}, | ||
"preferType": { | ||
"String": "string", | ||
"Number": "number", | ||
"Boolean": "boolean", | ||
"object": "Object", | ||
"function": "Function", | ||
"array": "Array", | ||
"date": "Date", | ||
"error": "Error", | ||
"null": "void" | ||
} | ||
}], | ||
"accessor-pairs": "warn", | ||
"array-callback-return": "error", | ||
"complexity": "warn", | ||
"consistent-return": "error", | ||
"curly": ["error", "multi-line", "consistent"], | ||
"dot-location": ["error", "property"], | ||
"dot-notation": "error", | ||
"eqeqeq": ["error", "smart"], | ||
"no-console": "off", | ||
"no-empty-function": "error", | ||
"no-floating-decimal": "error", | ||
"no-implied-eval": "error", | ||
"no-invalid-this": "error", | ||
"no-lone-blocks": "error", | ||
"no-multi-spaces": "error", | ||
"no-new-func": "error", | ||
"no-new-wrappers": "error", | ||
"no-new": "error", | ||
"no-octal-escape": "error", | ||
"no-return-assign": "error", | ||
"no-return-await": "error", | ||
"no-self-compare": "error", | ||
"no-sequences": "error", | ||
"no-throw-literal": "error", | ||
"no-unmodified-loop-condition": "error", | ||
"no-unused-expressions": "error", | ||
"no-useless-call": "error", | ||
"no-useless-concat": "error", | ||
"no-useless-escape": "error", | ||
"no-useless-return": "error", | ||
"no-void": "error", | ||
"no-warning-comments": "warn", | ||
"require-await": "warn", | ||
"wrap-iife": "error", | ||
"yoda": "error", | ||
"no-label-var": "error", | ||
"no-shadow": "error", | ||
"no-undef-init": "error", | ||
"callback-return": "error", | ||
"handle-callback-err": "error", | ||
"no-mixed-requires": "error", | ||
"no-new-require": "error", | ||
"no-path-concat": "error", | ||
"array-bracket-spacing": "error", | ||
"block-spacing": "error", | ||
"brace-style": ["error", "1tbs", { "allowSingleLine": true }], | ||
"capitalized-comments": ["error", "always", { "ignoreConsecutiveComments": true }], | ||
"comma-dangle": ["error", "never"], | ||
"comma-spacing": "error", | ||
"comma-style": "error", | ||
"computed-property-spacing": "error", | ||
"consistent-this": ["error", "$this"], | ||
"eol-last": "error", | ||
"func-names": "error", | ||
"func-name-matching": "error", | ||
"func-style": ["error", "declaration", { "allowArrowFunctions": true }], | ||
"indent": ["error", 4], | ||
"key-spacing": "error", | ||
"keyword-spacing": "error", | ||
"max-depth": "error", | ||
"max-nested-callbacks": ["error", { "max": 4 }], | ||
"max-statements-per-line": ["error", { "max": 2 }], | ||
"new-cap": "error", | ||
"no-array-constructor": "error", | ||
"no-inline-comments": "error", | ||
"no-lonely-if": "error", | ||
"no-mixed-operators": "error", | ||
"no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 1, "maxBOF": 0 }], | ||
"no-new-object": "error", | ||
"no-spaced-func": "error", | ||
"no-trailing-spaces": "error", | ||
"no-unneeded-ternary": "error", | ||
"no-whitespace-before-property": "error", | ||
"object-curly-spacing": ["error", "always"], | ||
"operator-assignment": "error", | ||
"operator-linebreak": ["error", "before"], | ||
"padded-blocks": ["error", "never"], | ||
"quote-props": ["error", "as-needed"], | ||
"quotes": ["error", "single", { "avoidEscape": true, "allowTemplateLiterals": true }], | ||
"semi-spacing": "error", | ||
"semi": "error", | ||
"space-before-blocks": "error", | ||
"space-before-function-paren": ["error", "never"], | ||
"space-in-parens": "error", | ||
"space-infix-ops": "error", | ||
"space-unary-ops": "error", | ||
"spaced-comment": "error", | ||
"unicode-bom": "error", | ||
"arrow-parens": ["error", "as-needed"], | ||
"arrow-spacing": "error", | ||
"no-duplicate-imports": "error", | ||
"no-useless-computed-key": "error", | ||
"no-useless-constructor": "error", | ||
"prefer-arrow-callback": "error", | ||
"prefer-numeric-literals": "error", | ||
"prefer-rest-params": "error", | ||
"prefer-spread": "error", | ||
"prefer-template": "error", | ||
"rest-spread-spacing": "error", | ||
"template-curly-spacing": "error", | ||
"yield-star-spacing": "error" | ||
} | ||
} |
{ | ||
"name": "slot-machine", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "An OOP slot machine.", | ||
@@ -9,2 +9,5 @@ "main": "src/index.js", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"eslint": "^3.18.0" | ||
}, | ||
"repository": { | ||
@@ -11,0 +14,0 @@ "type": "git", |
@@ -7,3 +7,3 @@ class EvaluatedLine { | ||
*/ | ||
constructor(symbols, diagonal = false){ | ||
constructor(symbols, diagonal = false) { | ||
/** | ||
@@ -26,5 +26,9 @@ * Symbols in this line. | ||
*/ | ||
get isWon(){ | ||
const remainder = this.symbols.filter(s => !s.wild && s.name !== this.symbols[0].name); | ||
get isWon() { | ||
const nonWild = this.symbols.find(s => !s.wildcard); | ||
if (!nonWild) return true; | ||
const remainder = this.symbols.filter(s => !s.wildcard && s.name !== nonWild.name); | ||
if (!remainder.length) return true; | ||
return false; | ||
@@ -37,3 +41,3 @@ } | ||
*/ | ||
get points(){ | ||
get points() { | ||
if (!this.isWon) return 0; | ||
@@ -40,0 +44,0 @@ return this.symbols.reduce((total, symbol) => total + symbol.points, 0); |
@@ -6,3 +6,3 @@ class Results { | ||
*/ | ||
constructor(lines){ | ||
constructor(lines) { | ||
/** | ||
@@ -19,3 +19,3 @@ * The lines in the results. | ||
*/ | ||
get totalPoints(){ | ||
get totalPoints() { | ||
return this.lines.reduce((total, line) => total + line.points, 0); | ||
@@ -28,3 +28,3 @@ } | ||
*/ | ||
get winCount(){ | ||
get winCount() { | ||
return this.lines.filter(line => line.isWon).length; | ||
@@ -36,9 +36,9 @@ } | ||
* @param {boolean} [includeDiagonals=false] - Whether or not to include diagonals. | ||
* @return {string} | ||
* @returns {string} | ||
*/ | ||
visualize(includeDiagonals = false){ | ||
visualize(includeDiagonals = false) { | ||
const lines = this.lines.filter(line => !line.diagonal); | ||
let visual = lines.map(line => line.symbols.map(s => s.display).join(' ')).join('\n'); | ||
if (includeDiagonals){ | ||
if (includeDiagonals) { | ||
const diagonals = this.lines.filter(line => line.diagonal); | ||
@@ -45,0 +45,0 @@ visual += '\n\n'; |
@@ -10,3 +10,3 @@ const EvaluatedLine = require('./EvaluatedLine'); | ||
*/ | ||
constructor(size = 3, symbols = []){ | ||
constructor(size = 3, symbols = []) { | ||
if (size % 2 === 0 || size < 3) throw new RangeError('Slot machine size must be an odd number, 3 or higher.'); | ||
@@ -32,14 +32,14 @@ if (!symbols.length) throw new RangeError('There must be at least one symbol.'); | ||
*/ | ||
play(){ | ||
play() { | ||
const chosens = []; | ||
const totalWeight = this.symbols.reduce((total, symbol) => total + symbol.weight, 0); | ||
for (let i = 0; i < Math.pow(this.size, 2); i++){ | ||
for (let i = 0; i < Math.pow(this.size, 2); i++) { | ||
const rand = Math.random() * totalWeight; | ||
let sum = 0; | ||
for (let j = 0; j < this.symbols.length; j++){ | ||
for (let j = 0; j < this.symbols.length; j++) { | ||
sum += this.symbols[j].weight; | ||
if (rand <= sum){ | ||
if (rand <= sum) { | ||
chosens.push(this.symbols[j]); | ||
@@ -53,3 +53,3 @@ break; | ||
for (let i = 0; i < chosens.length / this.size; i++){ | ||
for (let i = 0; i < chosens.length / this.size; i++) { | ||
lines.push(chosens.slice(i * this.size, (i + 1) * this.size)); | ||
@@ -69,6 +69,6 @@ } | ||
*/ | ||
chanceOf(name){ | ||
chanceOf(name) { | ||
const matchedSymbol = this.symbols.find(symbol => symbol.name === name); | ||
const totalWeight = this.symbols.reduce((total, symbol) => total + symbol.weight, 0); | ||
return matchedSymbol.weight / totalWeight; | ||
@@ -75,0 +75,0 @@ } |
@@ -16,3 +16,3 @@ /** | ||
*/ | ||
constructor(name, options = {}){ | ||
constructor(name, options = {}) { | ||
/** | ||
@@ -53,3 +53,3 @@ * Unique name of this symbol. | ||
*/ | ||
toString(){ | ||
toString() { | ||
return this.display; | ||
@@ -56,0 +56,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
13903
335
0
1