handle same number draw

This commit is contained in:
ddorn 2020-04-25 20:26:56 +02:00
parent 96bde31bb4
commit f64f5ed78d
1 changed files with 21 additions and 2 deletions

View File

@ -3,6 +3,7 @@ import enum
import os import os
import sys import sys
import traceback import traceback
from collections import defaultdict
from time import sleep from time import sleep
from typing import List, Dict from typing import List, Dict
@ -127,11 +128,29 @@ class OrderPhase(Phase):
async def next(self, ctx) -> "Phase": async def next(self, ctx) -> "Phase":
orders = [team.tirage_order for team in self.teams.values()] orders = [team.tirage_order for team in self.teams.values()]
# Check that order is unique
if len(set(orders)) == len(orders): if len(set(orders)) == len(orders):
# All dice are different: good
return self.NEXT return self.NEXT
else: else:
await ctx.send("crotte.") # Find dice that are the same
count = defaultdict(list)
for team in self.teams.values:
count[team.tirage_order].append(team)
re_do = []
for dice, teams in count.items():
if len(teams) > 1:
re_do.extend(teams)
teams_str = ", ".join(team.role.mention for team in re_do)
await ctx.send(
f"Les equipes {teams_str} ont fait le même résultat "
"et doivent relancer un dé. "
"Le nouveau lancer effacera l'ancien."
)
for team in re_do:
team.tirage_order = None
return self
bot = commands.Bot( bot = commands.Bot(