**WorstBest System**

**Goal**

Create a matchmaking system that creates closest rating matches within the context of BB2's matchmaking needs. Specifically, maximizing the number of matches made out of each pool, accommodating both multiple queuing (one coach queuing multiple teams) with multiple leagues (the teams need not all be from the same league) as well as secondary restrictions (such as a maximum TV difference of 500) and prioritization (ensuring certain coaches get a match even if they would otherwise be excluded... eg, if they had been excluded during the last pool).

**Method**

All teams in a pool are checked against all other teams in the pool to find valid potential matches. The shortest distance between any team for a coach and any other possible team is recorded for each coach, as are the potential number of matches, and the sum of all the rating differences.

Then a coach is selected based on the following (ordered) criteria:

- The coach only has 1 possible pairing.
- The coach is flagged as having priority.
- The coach has the largest minimum rating distance*,**

-* When there are only 3 coaches remaining, it switches from largest to smallest.

** When there is a tie, the coach with the largest sum of differences is used (meaning they have worse overall potential pairings beyond this one).

The selected coach's best match (one with shortest rating difference) is added to the matches, and both coaches (and all their teams) are removed from the pool. The method is applied again to the reduced pool, until there are no possible matches to be made.

**Explanation**

Rather than try to find the shortest total distance between ratings for everyone, the system tries to minimize the largest distance, creating a match from the worst of the best possible pairings. This minimizes the *largest* distance of any match made. In general this creates close to optimal pairings, with the one contentious aspect being that when there is an odd number of coaches in a pool, it is NOT the farthest from the pack that is excluded - often it is one that would make a closer pairing.

The reason for that choice is the farthest out team/coach would likely also be the farthest one out in the next pool. The one we do end up excluding will be closer to the mean rating, and have the priority flag, getting the optimal match next time around.

So long as the pools are combined (all leagues thrown into the same pool instead of having independent pools) this system allows for a coach to queue multiple teams across multiple leagues, and finds that coach the best match across all leagues and teams (usually - it may create less optimal if one of that coach's teams is the only team another coach can possible play with).

Similarly, if a coach can only make a single match out of the pool that match is prioritized rather than letting that coach fall out of the queue, even if there are better matches to be made with other pool participants.

**Examples**

Using the following format: coachname,teamname,tv,zsum(,league,priority) -- when left out league is "default" and priority is 0 (false).

We can start with the example from the OP:

CoachA,Da Stompin Tribez,1400,6

CoachB,Da Blacktoofz,960,0

CoachC,Hungry Sun,1160,1

CoachD,Blessed Mongrels,1070,1

CoachE,Dethbridge Destroyers,980,0

CoachF,Big Foot Little Foot,1000,0

The WorstBest system outputs:

[CoachA] Da Stompin Tribez (1400/1700) vs [CoachC] Hungry Sun (1160/1210)

[CoachD] Blessed Mongrels (1070/1120) vs [CoachF] Big Foot Little Foot (1000/1000)

[CoachE] Dethbridge Destroyers (980/980) vs [CoachB] Da Blacktoofz (960/960)

If we add in second team for coachA that has a slightly lower zSum

CoachA,Da Stompin Tribez,1400,6

CoachA,Da Thumpin Tribez,1200,8 <--

CoachB,Da Blacktoofz,960,0

CoachC,Hungry Sun,1160,1

CoachD,Blessed Mongrels,1070,1

CoachE,Dethbridge Destroyers,980,0

CoachF,Big Foot Little Foot,1000,0

We end up with

[CoachA] Da Thumpin Tribez (1200/1600) vs [CoachC] Hungry Sun (1160/1210)

[CoachD] Blessed Mongrels (1070/1120) vs [CoachF] Big Foot Little Foot (1000/1000)

[CoachE] Dethbridge Destroyers (980/980) vs [CoachB] Da Blacktoofz (960/960)

If we made one of coachA's teams in a different league, and put a distant team (say, coachF's team) in that league

CoachA,Da Stompin Tribez,1400,6,otherLeague

CoachA,Da Thumpin Tribez,1200,8

CoachB,Da Blacktoofz,960,0

CoachC,Hungry Sun,1160,1

CoachD,Blessed Mongrels,1070,1

CoachE,Dethbridge Destroyers,980,0

CoachF,Big Foot Little Foot,1000,0,otherLeague

We see that the two "otherLeague" teams get matched first, as coachF only has one possible match ensuring that coachF isn't left out of the pairings even though it means a less optimal match for coachA:

[CoachF] Big Foot Little Foot (1000/1000) vs [CoachA] Da Stompin Tribez (1400/1700)

[CoachC] Hungry Sun (1160/1210) vs [CoachD] Blessed Mongrels (1070/1120)

[CoachE] Dethbridge Destroyers (980/980) vs [CoachB] Da Blacktoofz (960/960)

If we take a coach out, leaving us with an odd number of coaches:

CoachA,Da Stompin Tribez,1400,6

CoachA,Da Thumpin Tribez,1200,8

CoachB,Da Blacktoofz,960,0

CoachC,Hungry Sun,1160,1

CoachD,Blessed Mongrels,1070,1

CoachF,Big Foot Little Foot,1000,0

We see that the odd-man out is not the one with the largest difference, but the one with the middle difference, getting the largest and smallest distance matches made while leaving the middle team/coach to pick up a prioritized match next pool:

[CoachA] Da Thumpin Tribez (1200/1600) vs [CoachC] Hungry Sun (1160/1210)

[CoachF] Big Foot Little Foot (1000/1000) vs [CoachB] Da Blacktoofz (960/960)

The system can be tested using BB2Match.exe, which is an AIR program that implements the system and takes teams in the )case sensitive) format used above. No doubt there's some way to break it, I just haven't figured out how yet. Overall it manages to do the job quickly and effectively, and solves the multi-queue and multi-league issues without abandoning the ability to give priority to excluded coaches, and creating the most possible matches within the confines of the MM criteria. It also doesn't need to create a preference matrix like the stable roommate system does, only tracking one match per coach in each iteration.

The system *does* require that all leagues use the same pool rather than have independent pools. It really should be that way anyway.