Added a bit of sleeping every 100 attempts

This commit is contained in:
Casey 2024-07-04 17:42:47 +03:00
parent b61dc0efa8
commit 897fbea54b
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
1 changed files with 11 additions and 7 deletions

View File

@ -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()))
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(bot_index, "swap", x, y)
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())