Class ArenaMatchComposer
Decides which waiters fill which team of an arena match. Pure, so it is testable without a database and so the transaction that applies it has nothing to decide.
public static class ArenaMatchComposer
- Inheritance
-
ArenaMatchComposer
- Inherited Members
Remarks
Pre-made groups are kept together and only ever fill a team of their own size or larger. A group of three queued for 3v3 is one team; a group of three queued for 4v4 is three of a team's four seats and one solo player takes the fourth. A group larger than a team can never be seated and is skipped — it should have been refused at queue time, and the composer does not paper over that by splitting it.
First come, first served. Candidates arrive in queue order. Teams are filled in that order with a first-fit packing: each unit (a group, or a solo) goes on the lowest-numbered team it fits on. Two groups that could complete a match but were behind a solo who fits anywhere still get seated, because the solo takes one seat and leaves the rest. This is not an optimal bin packing and does not try to be; the queue is expected to be short and fairness by wait time matters more than squeezing one extra match out of an unlucky arrangement.
Banding and balancing are opt-in through ArenaComposeOptions. A rating band keeps the match within reach of whoever has waited longest — the caller widens it as they wait, so a lonely high rating eventually finds a game. Balancing assigns units, largest and highest-rated first, to whichever team currently has the lower total rating and room, which keeps the two sides' averages close without abandoning the fairness of first-come eligibility: who plays is still decided by the queue, only which side they play on moves.
A match is composed only when every team is exactly full. Nothing partial is ever returned, because a match with uneven teams is not a match.
Methods
TryCompose(IReadOnlyList<ArenaCandidate>, int, int, ArenaComposeOptions, out List<ArenaSeat>)
Tries to fill teamCount teams of teamSize from the
candidates, in order, within a rating band and balanced when asked.
public static bool TryCompose(IReadOnlyList<ArenaCandidate> candidates, int teamCount, int teamSize, ArenaComposeOptions options, out List<ArenaSeat> seats)
Parameters
candidatesIReadOnlyList<ArenaCandidate>teamCountintteamSizeintoptionsArenaComposeOptionsseatsList<ArenaSeat>
Returns
TryCompose(IReadOnlyList<ArenaCandidate>, int, int, out List<ArenaSeat>)
Tries to fill teamCount teams of teamSize from the
candidates, in order.
public static bool TryCompose(IReadOnlyList<ArenaCandidate> candidates, int teamCount, int teamSize, out List<ArenaSeat> seats)
Parameters
candidatesIReadOnlyList<ArenaCandidate>Eligible waiters in queue order (oldest first). Members of one group must all be present; a group missing members is treated as the members present.
teamCountintTeams to fill. At least 2.
teamSizeintSeats per team. At least 1.
seatsList<ArenaSeat>Receives one seat per player when a match was composed.
Returns
- bool
True when every team is exactly full.