From de9a623e7e8c08f4dd9a69434636531d4759d3bf Mon Sep 17 00:00:00 2001 From: Giulio Date: Mon, 10 May 2021 12:02:39 +0200 Subject: [PATCH] fix bot repeated names --- backend/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/__init__.py b/backend/__init__.py index 1ee5666..6edded9 100644 --- a/backend/__init__.py +++ b/backend/__init__.py @@ -194,7 +194,9 @@ def chat_message(sid, msg): # ses.game.add_player(Player(f'AI_{random.randint(0,1000)}', 'bot', sio, bot=True)) sio.emit('chat_message', room=ses.game.name, data={'color': f'red','text':f'Only 1 bot at the time'}) else: - bot = Player(f'AI_{random.randint(0,1000)}', 'bot', sio, bot=True) + bot = Player(f'AI_{random.randint(0,10)}', 'bot', sio, bot=True) + while any([p for p in ses.game.players if p.name == bot.name]): + bot = Player(f'AI_{random.randint(0,10)}', 'bot', sio, bot=True) ses.game.add_player(bot) bot.bot_spin() elif '/removebot' in msg and not ses.game.started: