Skip to content

Instantly share code, notes, and snippets.

@abdullah
Last active January 22, 2019 08:37
Show Gist options
  • Save abdullah/f64e8bcb734b3886f7b1c8ce04d2d0d8 to your computer and use it in GitHub Desktop.
Save abdullah/f64e8bcb734b3886f7b1c8ce04d2d0d8 to your computer and use it in GitHub Desktop.
/*
BODEV Office
1 July 2016
@author : Abdullah mara
Bu script 1 Temmuz 2016'da bodevoffice developer'larının langırt turnuvasındaki takımları
belirlemek için yazılmıştır
*/
// Participant names.
var players = [
"Abdullah",
"Bircan",
"Özge",
"Süleyman",
"Burak",
"George",
"Can",
"Yusuf",
"Lütfi",
"Nukhet"
];
// Teams
var teams = [];
// They will not be on the same team.
// Because they very good player.
var notSameTeam = ["Abdullah","Said","George"];
// Random players
function tombala() {
var index = Math.floor(Math.random() * players.length);
return {index:index , players : players[index]};
}
var state = true;
while(state){
if (players.length) {
var player_first = tombala();
var player_second = tombala();
var firstexp = notSameTeam.indexOf(player_first.players)
var secondexp = notSameTeam.indexOf(player_second.players)
var exp = firstexp != -1 && secondexp != -1;
if (player_first.index == player_second.index || exp) {
state = true
}else{
players = filterPlayers(player_first.players);
players = filterPlayers(player_second.players);
teams.push({
first:player_first,
second:player_second
});
}
}else{
state = false;
Object.keys(teams).map(function(index, elem) {
console.log(teams[elem].first.players ," + " , teams[elem].second.players)
})
}
}
function filterPlayers(ob) {
return players.filter(function(index) {
return index != ob;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment