gPickWinners = gpu.createKernel(function(agents, scores, nSlots, slotCount){
var maxScore = 0;
var topMove = agents[this.thread.y][this.thread.x];
let startIndex = Math.floor(Math.random() * slotCount);
for (let i = 0; i < slotCount; i++) {
let index = (startIndex + i) % slotCount;
var p = (this.thread.y + nSlots[index][1] + 640) % 640;
var q = (this.thread.x + nSlots[index][0] + 640) % 640;
if (scores[p][q] > maxScore) {
topMove = agents[p][q];
maxScore = scores[p][q];
}
}
return topMove;
}).setOutput([640, 640]);