Skip to content

Commit

Permalink
Added weighted values for magnitudes
Browse files Browse the repository at this point in the history
  • Loading branch information
DeanTupper committed May 5, 2015
1 parent e633050 commit c1fb322
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/core/Configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,24 @@ function Configuration(width, height, colors, magnitudes, specials, types, turns

this.getRandomShell = function() {
return new Shell(Util.selectRandom(colors),
Util.selectRandom(magnitudes),
weightedMagnitude(),
Util.selectRandom(types),
Util.selectRandom(specials));
}
function weightedMagnitude(){
var weights = new Map([]);
weights.set(1, .40);
weights.set(2, .30);
weights.set(3, .15);
weights.set(4, .10);
weights.set(5, .05);
var p = 1 - Math.random();
for(var i = 1; i <= 5 ; i++){
var current = weights.get(i)
p = p - current;
if(p <= 0){
return i;
}
}
}
}

0 comments on commit c1fb322

Please sign in to comment.