From 9b1e9f6f2fed3ad08e334edfcf53a53a74d5fe76 Mon Sep 17 00:00:00 2001 From: AlberLC Date: Sun, 13 Nov 2022 01:36:59 +0100 Subject: [PATCH] Fix Connect4Bot ai --- flanabot/bots/connect_4_bot.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/flanabot/bots/connect_4_bot.py b/flanabot/bots/connect_4_bot.py index 2ff7a2d..f3ef3c6 100644 --- a/flanabot/bots/connect_4_bot.py +++ b/flanabot/bots/connect_4_bot.py @@ -56,7 +56,11 @@ class Connect4Bot(MultiBot, ABC): return self.insert_piece(j, player_2_symbol, message) allowed_positions = {j for _, j in available_positions_} - banned_columns - return self.insert_piece(random.choice(list(allowed_positions)), player_2_symbol, message) + if allowed_positions: + j = random.choice(list(allowed_positions)) + else: + j = random.choice(list(available_positions_)) + return self.insert_piece(j, player_2_symbol, message) @staticmethod def _available_positions(message: Message) -> list[tuple[int, int]]: