From fe6242cbbfadacd53616f58c6dd0ec8837988bf5 Mon Sep 17 00:00:00 2001 From: Kai Vogelgesang Date: Sat, 29 Oct 2022 13:09:39 +0200 Subject: [PATCH] Fix some buttons having priority --- backend/backend/arbiter.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/backend/backend/arbiter.py b/backend/backend/arbiter.py index 8d9a576..f28fcc4 100644 --- a/backend/backend/arbiter.py +++ b/backend/backend/arbiter.py @@ -2,7 +2,6 @@ import asyncio from datetime import datetime, timedelta from dataclasses import dataclass import random -from socket import socket from typing import Callable, Awaitable from fastapi import WebSocket, WebSocketDisconnect @@ -177,15 +176,13 @@ async def _(get_input: InputGetter, set_output: OutputSetter): # cursed python syntax vote["none"] += 1 - max_choice = None - max_votes = -1 - for (choice, votes) in vote.items(): - if votes > max_votes: - max_votes = votes - max_choice = choice + max_vote = max(vote.values()) + choice = random.choice( + [key for (key, value) in vote.items() if value == max_vote] + ) output = {button: False for button in Button} - if max_choice != "none": - output[max_choice] = True + if choice != "none": + output[choice] = True set_output(output)