For turn based games, Swiss system can take very long to complete. Currently round robin only supports 2 players. The following javascript demonstrates one of the many ways to arrange matches for one round:
It ensures that everyone plays the same number of matches and if turn order is important everyone gets to start first at least once (only if ppm * 2 < ttl, else generate mch for ppm = ttl-ppm). But it doesn't try to avoid repeatedly pitting the same players against each other.
Anybody has any better algorithms?
Code: Select all
const ttl=60; // total participants
const ppm=4; // participant per match
const mch=Array(ttl).fill().map(q=>[]);
for(let q=0;q<ppm;)Array(ttl).fill().map((j,k)=>[Math.random(),k]).sort().every((j,k)=>mch[k].indexOf(mch[k][q]=j[1])==q)&&q++;
console.table(mch);Anybody has any better algorithms?