Files
factorio-learning-environment/fle/env/tools/agent/sleep/client.py
2025-08-26 00:47:13 -07:00

31 lines
1.1 KiB
Python

from time import sleep
from fle.env.tools import Tool
class Sleep(Tool):
def __init__(self, connection, game_state):
super().__init__(connection, game_state)
def __call__(self, seconds: int) -> bool:
"""
Sleep for up to 15 seconds before continuing. Useful for waiting for actions to complete.
:param seconds: Number of seconds to sleep.
:return: True if sleep was successful.
"""
# Track elapsed ticks for appropriate sleep calculation
ticks_before = self.game_state.instance.get_elapsed_ticks()
# Update elapsed ticks on server
_, _ = self.execute(seconds)
# Sleep for the appropriate real-world time based on elapsed ticks
ticks_after = self.game_state.instance.get_elapsed_ticks()
ticks_added = ticks_after - ticks_before
if ticks_added > 0:
game_speed = self.game_state.instance.get_speed()
real_world_sleep = ticks_added / 60 / game_speed if game_speed > 0 else 0
sleep(real_world_sleep)
return True