ICE Lotto Test
This is a prototyping of how a lottery drawing would be done in a web app. It does not simulate populating the prize pools or entering the entrants. It merely shows what would be done to pick winners amongst the various pools.
by jsumners
HTML
<div id="output" style="white-space: pre;">
</div>
JavaScript
var $output = $('#output');
/**
* Gold Pot Rules (to be implemented)
* 1. Deposits <= 10 go into the small pot.
* 2. Deposits >= 11 go into the large pot.
* 3. Small pot deposits that total 20g or more
* go push the entrant into the large pot. This
* person's deposits also all move to the large pot.
*/
var Entrant = function(deposits) {
if (!(this instanceof Entrant)) {
return new Entrant(deposits);
}
this.deposits = deposits || [];
};
Entrant.prototype.addDeposit = function(deposit) {
this.deposits.push(deposit);
};
Entrant.prototype.inSmallPool = function() {
return this.deposits.filter(function(i) {
return i > 10;
}).length === 0;
};
var entrants = {
"sanctum": new Entrant([5, 12, 1, 2, 3, 10]),
"semaj": new Entrant([1, 1, 3, 10]),
"aleron": new Entrant([1, 20, 15, 10]),
"john": new Entrant([1]),
"joe": new Entrant([1, 2]),
"bob": new Entrant([12, 13, 15]),
"jane": new Entrant([15, 20]),
"wanda": new Entrant([20]),
"nancy": new Entrant([2, 3, 15])
};
var Bucket = function() {
if (!(this instanceof Bucket)) {
return new Bucket();
}
this.entries = [];
this.prizes = [];
};
Bucket.prototype.addEntry = function(name) {
this.entries.push(name);
};
Bucket.prototype.shuffle = function() {
// https://github.com/coolaj86/knuth-shuffle
var currIndex = this.entries.length,
tempValue, randomIndex;
while (0 !== currIndex) {
randomIndex = Math.floor(Math.random() * currIndex);
currIndex = currIndex - 1;
tempValue = this.entries[currIndex];
this.entries[currIndex] = this.entries[randomIndex];
this.entries[randomIndex] = tempValue;
}
};
Bucket.prototype.pickWinner = function() {
var winnerIndex = Math.floor(Math.random() * this.entries.length);
return this.entries[winnerIndex];
};
var coinPools = {
cheapPool: {
total: 0,
entrants: []
...