From 897fbea54b9136d09204eb6a2d3130f537bb3e81 Mon Sep 17 00:00:00 2001 From: hkc Date: Thu, 4 Jul 2024 17:42:47 +0300 Subject: [PATCH] Added a bit of sleeping every 100 attempts --- async-bot.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/async-bot.py b/async-bot.py index 4b337be..c9dbe2b 100644 --- a/async-bot.py +++ b/async-bot.py @@ -108,13 +108,17 @@ class AsyncBotManager: async with AsyncSimpleClient(http_session=http) as sio: await sio.connect(f"{self.base}/socket.io") while not self._shutdown: - index, expected = choice(list(self.difference.items())) - y, x = divmod(index, 1000) - current = self.canvas.getpixel((x, y)) > 0 # type: ignore - if current != expected: - print(bot_index, "swap", x, y) - await sio.emit("toggle_bit", {"index": index}) - await asyncio.sleep(0.25) + diff = list(self.difference.items()) + for _ in range(100): + index, expected = choice(diff) + y, x = divmod(index, 1000) + current = self.canvas.getpixel((x, y)) > 0 # type: ignore + if current != expected: + print(f"[{bot_index:2d}] swap {x:3d} {y:3d}") + await sio.emit("toggle_bit", {"index": index}) + await asyncio.sleep(0.25) + break + await asyncio.sleep(0.1) async def __aenter__(self): self._listener_task = asyncio.create_task(self.listener())