Pick/Ban Draft
MediumOnline Assessment
Run the pick/ban draft of an esports match: two teams alternately remove and choose heroes from a shared pool, on a fixed phase order, with timeouts.
The pool lists the heroes as "name:role" strings; the order of the list matters for auto-picks. The draft follows phases, a list such as "A ban", "B pick", played strictly in order; phase i + 1 starts when phase i finishes. The draft then receives events, a list of [team, hero] in the order they happen:
- An event for a team that does not own the current phase is ignored completely. So is every event once all phases are finished.
hero = ""is a timeout for the current phase.- Otherwise the team chooses
hero(a name, without the role). The choice is valid if the hero is in the pool, has not already been banned or picked (by either team), and, in a *pick* phase only, the team does not already hold two heroes of that role. A valid choice completes the phase and is recorded. - An invalid choice changes nothing, but it counts as a strike for the current phase; the team keeps the turn. The third strike in the same phase counts as a timeout. Strikes do not carry over to the next phase.
- A timeout in a *ban* phase bans nobody and records
"-". A timeout in a *pick* phase makes an auto-pick: the first hero inpoolorder that is still available and satisfies the role limit, picked for the team; if no hero qualifies, it records"-"as the pick instead. Either way, the phase completes.
Input: pool, phases, events.
Output: three lists of names (or "-"): team A's picks in order, team B's picks in order, and all bans (both teams) in order. If the events run out mid-draft, the remaining phases simply have not happened.
Example 1
- Input:
- [["ember:mage","nova:mage","tank:tank","bolt:rogue","ivy:healer","rex:tank"],["A ban","B ban","A pick","B pick","B pick","A pick"],[["A","nova"],["B","ember"],["B","tank"],["A","nova"],["A","tank"],["B","bolt"],["B","ivy"],["A","rex"]]]
- Output:
- [["tank","rex"],["bolt","ivy"],["nova","ember"]]
- Explanation
- A bans nova and B bans ember. B's
tankarrives during A's pick phase, so it is ignored. A's second try atnovais a strike (already banned) but A keeps the turn and takestank. B then picksboltandivy, and A closes withrex: its second tank, which is within the limit of two per role.
Example 2
- Input:
- [["ash:mage","bram:mage","cole:mage","dax:tank","edda:rogue","fen:rogue"],["A pick","B pick","A pick","B pick","A pick","B pick"],[["A","ash"],["B","fen"],["A","bram"],["B","edda"],["A",""],["B","cole"],["A","dax"]]]
- Output:
- [["ash","bram","dax"],["fen","edda","cole"],[]]
- Explanation
- A takes two mages,
ashandbram. At A's third pick the timeout makes an auto-pick:coleis the first available hero in pool order but would be A's third mage, so it is skipped anddaxis picked. B then takescole(B has no mages yet) and the draft is over; the finaldaxevent is ignored. B's picks arefen,edda,cole.
Example 3
- Input:
- [["ash:mage","bram:tank","cole:rogue","dax:healer"],["B ban","A ban","A pick","B pick"],[["B","zed"],["B","zed"],["B","zed"],["A",""],["A","ash"],["B",""]]]
- Output:
- [["ash"],["bram"],["-","-"]]
- Explanation
- B's three invalid choices (
zedis not in the pool) make the third strike a timeout, so the first ban is-. A times out on its ban:-again. A picksash. B's timeout auto-picks the first available hero in pool order:ashis taken, sobram.
Constraints
- 1 ≤ pool.length ≤ 30; hero names are unique lowercase words; roles are lowercase words
- 0 ≤ phases.length ≤ 24; each phase is "A ban", "B ban", "A pick" or "B pick"
- 0 ≤ events.length ≤ 200; team is "A" or "B"; hero is a pool name, any other lowercase word, or ""