February 2nd, 2012, 08:38 AM
Game Schedule, logic
I know I can't be the only game scheduler in the world with this problem...
I need to write a tool that schedules games for x number of weeks with x number of teams that ensures every team plays each other (if possible).
The basics of the functionality is this:
* There can be an even or odd number of teams, if odd there will of course be a "bye" week where one team is not playing (buy could be considered a team when doing the algorithm).
* The number of weeks can be either even or odd, basically the algorithm should just run until the number of weeks run out.
* The rotation should be so that every team plays every team but never itself (if number of weeks permits)
Basically for 4 teams the result would look like this:
A vs B
C vs D
A vs C
B vs D
A vs D
B vs C
I would like the code to be able to handle the number of games as input, but honestly if the rotation is solved, I can limit the number of games myself.
I do appreciate any help or direction I can get.
February 3rd, 2012, 10:16 AM
Re: Game Schedule, logic
Off the top of my head I think I would use a random number generator. I would have a list of teams and for each team I would store a list of teams each team has played/scheduled so far another list that would hold the teams not yet scheduled for the current week. The random number generator would be used to pick from one of the remaining teams making sure it is not the current team then removing the team from the teams remaining for the week list and adding the team to the teams played/scheduled list.
Should not be that hard but will require a little thought.
Always use [code][/code] tags when posting code.
Tags for this Thread
Click Here to Expand Forum to Full Width