View Single Post
  #13   Spotlight this post!  
Unread 09-04-2009, 12:52
JesseK's Avatar
JesseK JesseK is offline
Expert Flybot Crasher
FRC #1885 (ILITE)
Team Role: Mentor
 
Join Date: Mar 2007
Rookie Year: 2005
Location: Reston, VA
Posts: 3,640
JesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond repute
Re: 2009 Division Algorithm

Code:
private List<Team> mTeamList = new ArrayList<Team>();
private final static int sNUM_DIVISIONS = 4;
private static Timer t = new Timer("Randomizer");
private static TimerTask divTask = new TimerTask(){
    Integer division = -1;

    @Override
    public void run(){
       synchronized(division){
           division = (int)(new Random(System.nanoTime()).nextDouble() * sNUM_DIVISIONS);  
           //Indexes the divisions from 0 to 3, which would match the ordinals of division enums
       }
    }

    public int getDivision(){
       synchronized(division){
           return division;
       }
    }
}

static{
   initTeamList();  // Populates the team list with teams who are attending Atlanta
   t.schedule(divTask, 0, Math.random()*1000);
   Iterator<Team> it = mTeamList.iterator();
   Timer teamDivTimer = new Timer("Division Assignment");
   TimerTask teamTT = new TimerTask(){
       public void run(){
          if(it.hasNext())
             it.next().setDivision(divTask.getDivision();
          else
             cancel();
       }
   }
   teamDivTimer.schedule(teamTT, 0, Math.random()*1000);
}
Run it, the select random teams to even out the number of teams in each division. 'nuff said
__________________

Drive Coach, 1885 (2007-present)
CAD Library Updated 5/1/16 - 2016 Curie/Carver Industrial Design Winner
GitHub

Last edited by JesseK : 09-04-2009 at 12:59. Reason: ::doh::: forgot synchronization...