Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Schedule Algorithm

Status
Not open for further replies.

meltdown

Programmer
May 1, 2002
7
0
0
CA
Has anyone ever generated a basic schedule maker algorithm in VB or anything else. I have 5 teams and need them all too play 10 games against each other. The games need to be staggered meaning not 10 against one team in a row. There can be 2 or 3 games in a row.

Any help would be great.
 
Couldn't you use a loop to generated games a bit like this:

Game A B C D E ¦ F G H J K
TeamA 1 2 3 4 5 ¦ 1 2 3 4 5
TeamB 5 1 2 3 4 ¦ 4 5 1 2 3

Game L M N P Q ¦ R S T U V
TeamA 1 2 3 4 5 ¦ 1 2 3 4 5
TeamB 3 4 5 1 2 ¦ 2 3 4 5 1
 
Try this. The Array uses numbers to represent the teams...but when you display it you could reference it with another array or database to display names.

(I haven't actually tested it myself, but I think it should just about work)

Public Type Game
GameNo As Integer
Team1 As Integer
Team2 As Integer
end type

Dim Games() As Game
dim i as integer

ReDim Games((totalTeams - 1)! - 1)
For i = 1 To (totalTeams - 1)!
With Games(i-1)
.GameNo = i

If i >= (totalteams - 1)!
exit for
else
'Cycle Team1: 1,2,3,4,5; 1,2,3,4,5 etc
.Team1 = i - (totalteams * int(i / totalteams))

'Cycle Team2 differently:
'5,1,2,3,4; 4,5,1,2,3; 3,4,5,1,2; etc
'Team2 = Team1 + 1 + LoopNo <-starts at zero
.team2 = i - (totalteams * int(i / totalteams)) +1 + int(i / totalteams)
end if
end with
next i
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top