I am looking for algorithms to make single elimination and double elimination brackets.
The first step was figuring out the seeding algorithm, byes included, which I found in several places in SO: here (where byes can be introduced simply b replacing the last n excess teams and shifting the seed positions n times) and here (byes are baked in, and I only need to shift the positions).
Which is an improvement over the algorithm I was using which paired teams like this:
[(x, -x - 1) for x in range(num_players / 2)] and instead of defining the next round as one would expect:
Winner Match_i vs Winner Match_i+1 it would be
Winner Match_i vs Winner Match_n-i, quite unintuitive and harder to maintain.
But now I am trying to define the algorithms to make the brackets. I am having trouble to find actual algorithms to generate single elimination brackets and double elimination brackets.
I am not too worried about single elimination bracket generation because it is pretty straightforward, even with byes and also considering I am supporting different consolation modes.
But the double elimination brackets are throwing me off. Everywhere I look at they are being built in a different manner. And it is not just that I cannot choose one of them, it is also that I cannot figure out how to make the associations between matches, especially when byes are involved because they break the bracket structure and makes the problem harder to solve.
I would post my code but it is pretty long, messy and it has some bugs where teh bracket is not being generated correctly, that is why I am looking for more reliable bracket generation algorithms.