Here's an actual demo.
This was tested using Firefox. I just made some minor changes in support of Chrome. This definitely does not work in IE. HTML templates are not supported by IE.
Edit: I relinked to a new version that just eliminated some dead code and added auto-promotion after match promotion/demotion in addition to before match promotion/demotion.
I should probably note that it's possible to promote matches to an empty tier. If you're coupling a tiered match with a tiered level structure, then it stops making much sense. I'd expect, in order to maintain the present social aspects of sparring, that the tier structure should be coupled with the level structure.
Presently, the logic goes:
- If a sparrer wins, they get promoted to the next highest active tier.
- If a sparrer wins and they're already on the absolute highest tier, they maintain their position.
- If a sparrer loses, they get demoted to the next lowest active tier.
- If a sparrer loses and they're already on the lowest active tier, they are retired.
- If a sparrer leaves a match without a result, they are retired.
- If a sparrer leaves a match without a result, their opponent returns to the front of the queue.
- If a sparrer leaves a queue, they are retired.
- If a sparrer joins, they are promoted to the lowest active tier if it has capacity.
- If a sparrer joins and the lowest active tier is at capacity, they are promoted to the tier below it
- If a sparrer joins and the absolute lowest tier is at capacity, they are added to the queue of the absolute lowest tier.
- Auto-promotion? (see-below)
Putting the core of the concept that way, I probably should have written this in CLIPS instead of Javascript.
With the vacancy issue I decided to take a different approach from the original idea of promoting all queued sparrers, which proved particularly problematic.
A sparrer that is the only participant queued in a particular tier is automatically promoted in the event that a match ends (before and after other promotion/demotion) or a player quits (after removal). Whether or not this makes much sense, feel free to play around and present other ideas.
Present auto-promotion reasoning breakdown:
Players are automatically promoted if they are the only person on the roster of their tier, from the lowest tier to the highest tier.
- Reasons for doing it after a retirement: Tier 1 consists of P1 and P2. Tier 2 consists of only P3. P2 retires. Therefore P1 should fight P3.
- Reasons for doing it before a match promotion/demotion: Tier 1 consists of P1 and P2. Tier 2 consists of only P3. If P2 loses, P3 immediately fights P1 instead of having to fight P2 first.
- Reasons for doing it after a match promotion/demotion: Tier 1 consists of P1. Tier 2 consists of P2 and P3 and P4. P2 and P3 draw and are retired. P1 should therefore participate in a match with P4.