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())