Created
May 29, 2013 14:59
-
-
Save connors511/5670944 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function getRandomRepresentation(number, stats) { | |
var std = 2; | |
// We need 3 games to make stats | |
if (stats.length < 5) { | |
log("Not enough data to determine random representation", 'debug'); | |
// We dont have all the data | |
// If largestPrimeFactor(number) > 15, avoid tables? | |
if (number == 1) { | |
// 1 will cause fractions if used for x*y format | |
return rand(1,2); | |
} | |
} | |
// (100/(summen af korrektheds procenterne for repræsentationerne)*(korrekthedsprocenten for den give repræsentation man ønsker chancen for)) | |
// Should rely on user performance | |
var chance = rand(1,100); | |
var c = 0, tmp = 0; | |
log("Rolled chance = " + chance, 'rnd'); | |
for (var key in stats.stats.reps) { | |
if (key == 'total') | |
continue; | |
tmp = (100/stats.stats.reps.total.correct) * stats.stats.reps[key].correct; | |
log("tmp = " + tmp + " with c = " + c + " for rep = " + key, 'rnd'); | |
if (tmp == 0) { | |
return key; | |
} | |
if (chance <= c + tmp) { | |
log("Rep = " + key + " it is", 'rnd'); | |
return key; | |
} else { | |
c += tmp; | |
} | |
}; | |
// Should never happen | |
log("Fallback to random. Had chance = " + chance + " with c = " + c, 'error'); | |
return rand(1,3); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment