Last active
February 27, 2020 07:59
-
-
Save AcrylicShrimp/82bce2228769a53b95ae41c985efe76e to your computer and use it in GitHub Desktop.
Implementing gotcha system.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const itemArray = [ | |
['banana-1000', 0.65], | |
['choco-960', 0.65], | |
['back-0', 13.7 / 16], | |
['back-1', 13.7 / 16], | |
['back-2', 13.7 / 16], | |
['char-0', 13.7 / 16], | |
['char-1', 13.7 / 16], | |
['char-2', 13.7 / 16], | |
['char-3', 13.7 / 16], | |
['char-4', 13.7 / 16], | |
['char-5', 13.7 / 16], | |
['char-6', 13.7 / 16], | |
['char-7', 13.7 / 16], | |
['char-8', 13.7 / 16], | |
['char-9', 13.7 / 16], | |
['char-10', 13.7 / 16], | |
['char-11', 13.7 / 16], | |
['char-12', 13.7 / 16], | |
['jam-500', 2], | |
['jam-300', 6], | |
['jam-100', 22], | |
['jam-50', 25], | |
['', 30] | |
]; | |
const itemProbArray = itemArray.map(value => value[1]); | |
itemProbArray.reduce((acc, cur, i, src) => (src[i] = acc + cur)); | |
// ... | |
const mt = require('mersenne-twister'); | |
// Sample item here; | |
const pivot = | |
new mt().random() * | |
itemProbArray[itemProbArray.length - 1]; | |
let item = ''; | |
for (let index = 0; index < itemProbArray.length; ++index) | |
if (pivot <= itemProbArray[index]) { | |
item = itemArray[index][0]; | |
break; | |
} | |
print(item); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment