views:

554

answers:

3

I am in the process of converting my Tournament Organizer software, which allows the creation and manipulation of Double Elimination Tournaments, to use the MVVM design pattern so that it can be more easily tested. In doing so, I'm separating out the 'model' from some code in the UI that directly manipulates the bracket structure.

This will be the third iteration of software I've written to handle tournaments. The first was written in PHP and stored the data in a database. The second version is the WPF version I made, and it stores the data in memory, and then serializes it to an XML file. However, in both versions, there are aspects of the implementation that I feel aren't clean, and seem like they break the law of DRY.

If you were creating a data structure from scratch to handle double elimination brackets, how would you do it?

Note that it doesn't need to be able to automatically generate the brackets algorithmically (loading from a pre-made double-elimination with 4/8/16/32 people is how I'm doing it now), just the main use case of setting winners of matches and 'advancing' them through the bracket.

Edit: To make it clear, the data structure needs to handle double elimination tournaments, so potentially, the winner of one match could end up competing against the loser of another.

A: 

What about a full Binary tree where first round starts at the leaf nodes and then moves up.

Pete
Unfortunately, that doesn't handle double elimination tournaments :(
FryGuy
+1  A: 

So, at the end points, you have 64 teams. So there's a collection, somehow, of 64 Teams.

But they're paired off, and for each pair, there's a winner. And in the middle brackets, that winner actually emerged from a bracket, so I think your bracket object actually looks like:

public class Bracket
{
    Team winner;  //if this is null or whatever, then we don't have a winner yet
    Bracket topBracket;  
    Bracket bottomBracket;
}

...and when you're instantiating your ends, you'd just leave the two sub-Brackets null, with only a winner.

To handle double-elimination, there's a second bracket, which is a losers bracket. It would be nice if you could automatically handle the addition of losers into this bracket (design a bracket that starts with 32, who play down to 16, add in the 16 losers from winner bracket round 2, etc.) but that's all implementation. The data structure doesn't need to change to accommodate that, you just need more of them.

dnord
That works good, except for the fact that it needs to be for double elimination (see edit)
FryGuy
A: 

I just noticed this question in the side bar of another question I was on, and thought I'd chime in:

I am in the process of developing a full featured Tournament API, and I am open-sourcing it.

It doesn't yet create double elimination tournaments, but the data structure for the single-elimination tournaments was recently revised to support the double-elim tree structure.

http://tournaments.codeplex.com/

John Gietzen
Yes, I saw that and downloaded it. Unfortunately (fortunately?), I've already gone ahead and implemented it, so it'd be difficult to go back and re-use something else at this point :(
FryGuy