### Fixture Generating Algorithm Easiest Describe with Drawing

I will explain how to create a fixture algorithm regardless of the programming language. But if you want to see how I write in Java, you can check my GitHub link.

So, let's start.

When we are building a fixture-generating algorithm, we have to know two basic things;

- The teams will match one time or two times?
- How many teams are there? (n)

We can get the answers that we need with the above questions.

- How many teams will match every round? : All teams can bisect. (n/2)
- How many rounds will there be?

- If teams will match just once: All teams minus one. (n-1)

- If teams will match twice: All teams minus one and multiplied by two. ((n-1) x 2)

The last question means; What will be the size of our match list? When we create a loop, we will use just (n-1) and will not use the second one (n-1)x2

# The Algorithm with Drawing

For example, let's think at first algorithm had that below teams;

Then we can say we have 4 teams, which means n = 4 so in each round, the teams will match 4/2 = 2 times.

Let's think if someone sends to the algorithm just 3 teams, what can we do?

At that time, we could add a new team the name is "X" so it means which team matches with "X" will not play in that round. After that, we can calculate as above how many rounds will play. n = 4 and the teams will match 4/2 = 2 times each round.

Now we have to match the teams, but how? We can do it in many ways. For example, the simplest thing is we can match the teams respectively. But I want my algorithm to match the teams randomly.

Because of that, I need a temporary list.

For once, I want to shuffle them randomly with the assistance of the temp list. And after that, we can equal the temp list to the original list.

- Relocated the teams on the temp list.

- Then transferred the temp list to the original list. And clear the temp list.

- Now we can enter the team matching loop with the last original and temp list.

- The first loop is the main loop. It will loop total --> (team size -1) times.
- The teams will merge in double. The loop will repeat n/2 times. It means --> (total team / 2) as I said at first.
- The original list will transfer its own first and the last team to the temp list as you see in the drawing. After that, another loop will transfer the left behind in the original list to the temp list.
- The original list will get the new arrangement, and then the cells of the temp list will clear.
- If teams are to match only once, the main loop can end here. But if the teams are to match twice, the loop must continue.
- The loop will n/2 times like the second item. But there is one difference between them; for example, if the second loop match list had the teams from the original list like [a-b] here, teams have to write like [b-a]

And now you can write your matches whatever you want.

## Comments

## Post a Comment