Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async rollback #17

Merged
merged 1 commit into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ def after_close(self):
pass

@final
async def on_message(self, message): # do not override
def on_message(self, message): # do not override
if self.last_message_time is None or time.time() - self.last_message_time >= 0.045:
self.last_message_time = time.time()
await self.send_message(message)
self.send_message(message)

@abstractmethod
async def send_message(self, message):
def send_message(self, message):
raise NotImplementedError


Expand Down
12 changes: 6 additions & 6 deletions src/bots.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


class PongBot(BaseHandler):
async def send_message(self, message):
def send_message(self, message):
data = json.loads(message)
player = data['playerId']
state = data['state']
Expand All @@ -20,11 +20,11 @@ async def send_message(self, message):
else:
move = -1

await self.write_message(json.dumps({'move': move, 'start': 1}))
self.write_message(json.dumps({'move': move, 'start': 1}))


class FlappybirdBot(BaseHandler):
async def send_message(self, message):
def send_message(self, message):
state = json.loads(message)['state']
jump = 0

Expand All @@ -38,11 +38,11 @@ async def send_message(self, message):
if state['birdY'] > nearest_obstacle['centerGapY']:
jump = 1

await self.write_message(json.dumps({'jump': jump}))
self.write_message(json.dumps({'jump': jump}))


class SkijumpBot(BaseHandler):
async def send_message(self, message):
def send_message(self, message):
state = json.loads(message)['state']

space = 0
Expand All @@ -58,4 +58,4 @@ async def send_message(self, message):
if state['jumperInclineRad'] < 0.7:
up = 1

await self.write_message(json.dumps({'space': space, 'up': up, 'down': down}))
self.write_message(json.dumps({'space': space, 'up': up, 'down': down}))
4 changes: 2 additions & 2 deletions src/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def initialize(
def after_close(self):
self.agent.states.clear()

async def send_message(self, message):
def send_message(self, message):
data = json.loads(message)
action = self.agent.return_prediction(data)
await self.write_message(json.dumps(action))
self.write_message(json.dumps(action))
Loading