1

I am trying to generate a round robin tournament schedule for an even number of teams in c sharp.

I was thinking of using an array but I am having a little trouble getting it to work. I want the first team to remain fixed, so I was just thinking of using an int for this team. Then I want the array to rotate, so that the fixed int will pair up with the first element in the array and all of the remaining elements will pair up together like this:

  • int Team1 vs array[0]
  • array[1] vs array[2]
  • array[3] vs array[4]
  • array[5] vs array[6]

etc. and then rotate so that Team1 plays against each member of the array and they all play each other as well. Thanks for any help you can provide!

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Jorge
  • 11
  • 2
  • 3
    Jorge: what is your question? What have you got so far, in terms of a solution? – Matt Ellen Apr 18 '11 at 14:00
  • See http://stackoverflow.com/questions/1293058/round-robin-tournament-algorithm-in-c – SwDevMan81 Apr 18 '11 at 14:02
  • Not homework...I am just trying to learn because I want to add it to a windows form application I am building. – Jorge Apr 18 '11 at 14:23
  • This is what I have so far.... – Jorge Apr 18 '11 at 14:24
  • static void generateSchedule() { int[] array = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 }; int[] result = array.Take(1) .Concat(Enumerable.Repeat(array.Last(), 1)) .Concat(array.Skip(1).Reverse().Skip(1).Reverse()) .ToArray(); for (int i = 0; i < array.Length; i++) { Console.Write(array[i] + " "); } Console.WriteLine(); – Jorge Apr 18 '11 at 14:26
  • 1
    Drawing the possibilities out on paper is the way I'd start approaching a problem like this. It's much easier to figure out the algorithm you need to implement it in code if you see it written down. – Cody Gray - on strike Apr 18 '11 at 14:27
  • @Jorge: you should put the code from your comment into your question. It will help people to answer your question. – Matt Ellen Apr 18 '11 at 14:53

1 Answers1

0

For a round robin, you want to choose combinations of length two (without repetition) from the list of teams.

Richie Cotton
  • 118,240
  • 47
  • 247
  • 360