Advertisement
Deduction42

TeamAssignment.jl

Apr 2nd, 2018
855
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 1.16 KB | None | 0 0
  1. function TeamAssignment( Players , MMR , Option)
  2.   #Option 1 does a swapping algorithm to balance teams
  3.   #Option 2 does a fully random assignment
  4.   #Option 3 does a quasi-random assignment based on player number
  5.  
  6. if Option == 1
  7.   iP = sortperm(MMR)
  8.   nTeam1 = iP[[1,2,5,7,9]];
  9.   nTeam2 = iP[[2,4,6,8,10]];
  10.  
  11.   m1 = mean( MMR[nTeam1] )
  12.   m2 = mean( MMR[nTeam2] )
  13.   d = m2-m1
  14.   done = false
  15.  
  16.   while !done
  17.     Team1 = nTeam1
  18.     Team2 = nTeam2
  19.  
  20.     Md  = abs.( (MMR[Team1] .- MMR[Team2]') + d )
  21.    ind = vcat( ind2sub( Md , indmin( Md )) ... )
  22.    nTeam1[ind[1]] = Team2[ind[2]]
  23.    nTeam2[ind[2]] = Team1[ind[1]]
  24.    d1 = mean( MMR[nTeam2] ) - mean( MMR[nTeam1] )
  25.  
  26.    if abs(d1) >= abs(d)
  27.       done = true
  28.    end
  29.    d = d1
  30.  end
  31.  Team1 = Players[Team1]
  32.  Team2 = Players[Team2]
  33.  
  34.  elseif Option == 2
  35.    Players = MMR_Sort( Players, rand(10) );
  36.    Team1 = Players[1:5];
  37.    Team2 = Players[6:10];
  38.  
  39.  elseif Option == 3
  40.    Players = sort(Players);
  41.    Team1 = Players[1:5];
  42.    Team2 = Players[6:10];
  43.  
  44.  end
  45.  
  46.  return Team1 , Team2
  47.  
  48. end
  49.  
  50. function MMR_Sort(Players,MMR)
  51.    Ind = sortperm(MMR);
  52.    return Players[Ind];
  53. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement