slot-machine
Advanced tools
Comparing version 1.1.0 to 1.1.1
50
index.js
@@ -1,2 +0,2 @@ | ||
let Symbol = require('./symbol.js'); | ||
let Symbol = require('./struct/Symbol.js'); | ||
@@ -12,12 +12,11 @@ module.exports.Symbol = Symbol; | ||
module.exports.play = (symbols, size) => { | ||
if (!size || size < 3){ | ||
size = 3; | ||
} | ||
// Disallow less than 3 | ||
if (!size || size < 3) size = 3; | ||
if (size % 2 === 0){ | ||
size += 1; | ||
} | ||
// Disallow evens | ||
if (size % 2 === 0) size += 1; | ||
let chosens = []; | ||
// Weighted randomizer | ||
for (let i = 0; i < size * size; i++){ | ||
@@ -42,2 +41,3 @@ let rand = Math.random() * symbols.reduce((a, b) => a + b.weight, 0); | ||
// Push the diagonals. This took forever to get correct! | ||
lines.push(chosens.filter((s, i) => (i + size + 1) % (size + 1) === 0)); | ||
@@ -55,22 +55,20 @@ lines.push(chosens.slice(size - 1).filter((s, i) => i % (size - 1) === 0).reverse().slice(1)); | ||
module.exports.calculate = (lines) => { | ||
lines.forEach((symbols, i) => { | ||
let copy = lines; | ||
copy.forEach((symbols, i, l) => { | ||
let win = false; | ||
let remainder = symbols.filter((s) => !s.wild).filter((s) => s.name !== symbols[0].name); | ||
let remainder = symbols.filter(s => !s.wild && s.name !== symbols[0].name); | ||
if (remainder.length === 0){ | ||
win = true; | ||
} | ||
if (remainder.length === 0) win = true; | ||
lines[i] = {symbols, win, points: symbols.reduce((a, b) => a + b.points, 0)}; | ||
lines[i].diagonal = false; | ||
copy[i] = {symbols, win, points: win ? symbols.reduce((a, b) => a + b.points, 0) : 0}; | ||
copy[i].diagonal = false; | ||
if (i === lines.length - 1 || i === lines.length - 2){ | ||
lines[i].diagonal = true; | ||
} | ||
if (i >= l.length - 2) copy[i].diagonal = true; | ||
}); | ||
lines.calculated = true; | ||
return lines; | ||
} | ||
copy.calculated = true; | ||
return copy; | ||
}; | ||
@@ -84,11 +82,9 @@ /** | ||
module.exports.format = (lines, includeDiagonals = true) => { | ||
if (!includeDiagonals) lines = lines.filter(l => !l.diagonal); | ||
if (lines.calculated){ | ||
if (!includeDiagonals){ | ||
lines = lines.filter((l) => !l.diagonal); | ||
} | ||
return lines.map((l) => l.symbols.map((s) => s.symbol).join(' ') + ' ' + (l.diagonal ? 'Diagonal ' : '') + (l.win ? 'Win!' : '')).join('\n'); | ||
return lines.map(l => l.symbols.map(s => s.symbol).join(' ') + ' ' + (l.diagonal ? 'Diagonal ' : '') + (l.win ? 'Win!' : '')).join('\n'); | ||
} | ||
return lines.map((l) => l.map((s) => s.symbol).join(' ')).join('\n'); | ||
} | ||
return lines.map(l => l.map(s => s.symbol).join(' ')).join('\n'); | ||
}; |
{ | ||
"name": "slot-machine", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "A functioning slot machine!", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -25,3 +25,3 @@ ### Usage | ||
### Documentation | ||
##### `Symbol(name, symbol[, points = 1, weight = 1, wild = false])` | ||
##### Symbol(name, symbol[, points = 1, weight = 1, wild = false]) | ||
`name` A unique name. | ||
@@ -32,15 +32,16 @@ `symbol` A symbol for display. | ||
`wild` Whether or not the Symbol can match with any other Symbol. | ||
*Creates a Symbol.* | ||
##### `play(symbols[, size = 3])` | ||
##### play(symbols[, size = 3]) | ||
`symbols` An array of Symbols. | ||
`size` Grid size, will round to nearest odd number above 3. | ||
Returns an array of rows in the slot game, plus two representing diagonals. | ||
*Returns an array of rows in the slot game, plus two representing diagonals.* | ||
##### `calculate(lines)` | ||
##### calculate(lines) | ||
`lines` An array of arrays containing Symbols. | ||
Returns an array, containing the points and results of the lines inputted. | ||
*Returns an array, containing the points and results of the lines inputted.* | ||
##### `format(lines[, includeDiagonals = true])` | ||
##### format(lines[, includeDiagonals = true]) | ||
`lines` An array of arrays containing Symbols, or calculated lines. | ||
`includeDiagonals` Whether or not to include diagonals. Only works with calculated lines. | ||
Returns a formatted slot machine game. | ||
*Returns a formatted slot machine game.* |
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
6550
5
45
87