Public
Edited
Dec 22, 2022
Fork of Untitled
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
playerOverview = {
let o = [...players];
o.forEach(d=>d.rate=latestRating(d.key));
return o;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
nextRound = ()=> {
mutable round++;
console.log("Next Round "+round);
let b = [];

let newRound = [...players];
newRound = newRound.sort((a,b)=> latestRating(a.key) - latestRating(b.key)).reverse();

let possibilities = [];
newRound.forEach((a,i) => {
newRound.forEach((b,j) => {
if (i<=j) return;
possibilities.push({
playerA:a,
playerB:b,
battles: battleCount(a.key,b.key),
rating: Math.max(latestRating(a.key),latestRating(b.key)),
difference:Math.abs(latestRating(a.key)-latestRating(b.key))});
})
})
possibilities = possibilities.sort((a,b)=> {
return a.battles!=b.battles ? a.battles-b.battles : a.difference!= b.difference ? a.difference-b.difference : b.rating-a.rating;
});
console.log(possibilities);

while (possibilities.length>0) {
const pA = possibilities[0].playerA;
const pB = possibilities[0].playerB;
b.push({playerA:pA,playerB:pB,result:null, timestamp:null});

console.log(possibilities);
console.log([pA,pB]);
possibilities = possibilities.filter(d=> ![pA.key,pB.key].includes(d.playerA.key) && ![pA.key,pB.key].includes(d.playerB.key));
console.log(possibilities);
// possibilities = [];
}



// for (let i=0; i<(players.length-1); i+=2) {
// b.push({playerA:players[i], playerB:players[i+1], result:null, timestamp:null});
// }
return b;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
battleCount = (p1,p2) => {
return battles.filter(b=>{
return (b.playerA.key == p1 && b.playerB.key == p2) || (b.playerA.key == p2 && b.playerB.key == p1)
}).length;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more