Skip to content

Commit

Permalink
Merge 435df97 into aba05bb
Browse files Browse the repository at this point in the history
  • Loading branch information
OlafSzmidt committed Jul 18, 2018
2 parents aba05bb + 435df97 commit c0aa0da
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
18 changes: 10 additions & 8 deletions aimmo-game-worker/avatar_runner.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import logging
import traceback
from simulation.action import WaitAction

LOGGER = logging.getLogger(__name__)


class AvatarRunner(object):
def __init__(self, avatar=None):
if avatar is None:
from avatar import Avatar
self.avatar = Avatar()
else:
self.avatar = avatar
self.avatar = avatar

def handle_turn(self, world_map, avatar_state):
def process_avatar_turn(self, world_map, avatar_state):
try:
return self.avatar.handle_turn(avatar_state, world_map)
if self.avatar is None:
from avatar import Avatar
self.avatar = Avatar()
return self.avatar.handle_turn(world_map, avatar_state)

except Exception as e:
LOGGER.error("Code failed to run")
LOGGER.error(e)
LOGGER.error(traceback.print_exc())
action = WaitAction()

return action
2 changes: 1 addition & 1 deletion aimmo-game-worker/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def process_turn():
world_map = WorldMap(**data['world_map'])
avatar_state = AvatarState(**data['avatar_state'])

action = avatar_runner.handle_turn(world_map, avatar_state)
action = avatar_runner.process_avatar_turn(world_map, avatar_state)

return flask.jsonify(action=action.serialise())

Expand Down
2 changes: 1 addition & 1 deletion aimmo-game-worker/tests/test_avatar_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ def handle_turn(self, world_map, avatar_state):
return None

runner = AvatarRunner(Avatar())
action = runner.handle_turn({}, {})
action = runner.process_avatar_turn({}, {})
self.assertIsInstance(action, WaitAction)

0 comments on commit c0aa0da

Please sign in to comment.