* Shuffle agents before sorting.
Without this fix, on Safari (Mac), "grudger" ends up always dominating on step 4, not just sometimes.
This commit is contained in:
parent
f6da0dc3a3
commit
71986e40b9
|
@ -173,4 +173,15 @@ function _makeMovieClip(resourceName, options){
|
|||
// Gimme
|
||||
return mc;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function _shuffleArray(array) {
|
||||
var tmp, current, top = array.length;
|
||||
if(top) while(--top) {
|
||||
current = Math.floor(Math.random() * (top + 1));
|
||||
tmp = array[current];
|
||||
array[current] = array[top];
|
||||
array[top] = tmp;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
|
|
@ -229,11 +229,8 @@ function Tournament(config){
|
|||
self.agentsSorted = null;
|
||||
self.playOneTournament = function(){
|
||||
PD.playOneTournament(self.agents, Tournament.NUM_TURNS);
|
||||
self.agentsSorted = self.agents.slice();
|
||||
self.agentsSorted.sort(function(a,b){
|
||||
if(a.coins==b.coins) return (Math.random()<0.5); // if equal, random
|
||||
return a.coins-b.coins; // otherwise, sort as per usual
|
||||
});
|
||||
self.agentsSorted = _shuffleArray(self.agents.slice());
|
||||
self.agentsSorted.sort(function(a,b){ return a.coins-b.coins; });
|
||||
};
|
||||
|
||||
// Get rid of X worst
|
||||
|
|
Loading…
Reference in New Issue