prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Submitting empty code leads to server error
  When sending empty program, we are getting:
  
  Traceback:
  File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
  1.                     response = wrapped_callback(request, _callback_args, *_callback_kwargs)
     File "/Library/Python/2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
  2.                 return view_func(request, _args, *_kwargs)
     File "/Users/paulina.koch/Documents/C4L/forks/aimmo/ui/players/views.py" in code
  3.             world.player_changed_code(request.user.id, request.user.player.code)
     File "/Users/paulina.koch/Documents/C4L/forks/aimmo/simulation/game_state.py" in player_changed_code
  4.             avatar.set_code(code)
     File "/Users/paulina.koch/Documents/C4L/forks/aimmo/simulation/avatar/avatar_wrapper.py" in set_code
  5.         self.avatar = Avatar()
  
  Exception Type: TypeError at /api/code/
  Exception Value: 'NoneType' object is not callable
  
  Simple check should be enough, but we could use it as a chance to implement an extension of validation or error handling/printing when submitting code.
  
  
  </issue>
  <code>
  [start of simulation/avatar/avatar_wrapper.py]
  1 import traceback
  2 import sys
  3 
  4 from simulation.action import WaitAction
  5 
  6 
  7 # This class will be implemented by the player
  8 Avatar = None
  9 
  10 
  11 class UserCodeException(Exception):
  12     def __init__(self, *args, **kwargs):
  13         super(Exception, self).__init__(*args, **kwargs)
  14         self.exc_type, self.exc_value, self.exc_traceback = sys.exc_info()
  15 
  16     def to_user_string(self):
  17         lines = traceback.format_exception(self.exc_type, self.exc_value, self.exc_traceback)
  18         return '<br/>'.join(lines)
  19 
  20 
  21 class AvatarWrapper(object):
  22     """
  23     The application's view of a character, not to be confused with "Avatar", the player-supplied code.
  24     """
  25 
  26     def __init__(self, initial_location, initial_code, player_id, avatar_appearance):
  27         self.location = initial_location
  28         self.health = 5
  29         self.score = 0
  30         self.events = []
  31         self.player_id = player_id
  32         self.avatar_appearance = avatar_appearance
  33         self.avatar = None
  34 
  35         self.set_code(initial_code)
  36 
  37     def handle_turn(self, state):
  38         try:
  39             next_action = self.avatar.handle_turn(state, self.events)
  40         except Exception as e:
  41             # TODO: tell user their program threw an exception during execution somehow...
  42             print('avatar threw exception during handle_turn:', e)
  43             traceback.print_exc()
  44             next_action = WaitAction()
  45         # Reset event log
  46         self.events = []
  47 
  48         return next_action
  49 
  50     def die(self, respawn_location):
  51         # TODO: extract settings for health and score loss on death
  52         self.health = 5
  53         self.score = max(0, self.score - 2)
  54         self.location = respawn_location
  55 
  56     def add_event(self, event):
  57         self.events.append(event)
  58 
  59     def set_code(self, code):
  60         self.code = code
  61         try:
  62             exec(code)
  63         except Exception as ex:
  64             raise UserCodeException("Exception in user code", ex)
  65         self.avatar = Avatar()
  66 
  67     def __repr__(self):
  68         return 'Avatar(id={}, location={}, health={}, score={})'.format(self.player_id, self.location,
  69                                                                         self.health, self.score)
  70 
  71
  [end of simulation/avatar/avatar_wrapper.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/simulation/avatar/avatar_wrapper.py b/simulation/avatar/avatar_wrapper.py
  --- a/simulation/avatar/avatar_wrapper.py
  +++ b/simulation/avatar/avatar_wrapper.py
  @@ -60,9 +60,9 @@
           self.code = code
           try:
               exec(code)
  +            self.avatar = Avatar()
           except Exception as ex:
               raise UserCodeException("Exception in user code", ex)
  -        self.avatar = Avatar()
   
       def __repr__(self):
           return 'Avatar(id={}, location={}, health={}, score={})'.format(self.player_id, self.location,
  
verification_info: {"golden_diff": "diff --git a/simulation/avatar/avatar_wrapper.py b/simulation/avatar/avatar_wrapper.py\n--- a/simulation/avatar/avatar_wrapper.py\n+++ b/simulation/avatar/avatar_wrapper.py\n@@ -60,9 +60,9 @@\n         self.code = code\n         try:\n             exec(code)\n+            self.avatar = Avatar()\n         except Exception as ex:\n             raise UserCodeException(\"Exception in user code\", ex)\n-        self.avatar = Avatar()\n \n     def __repr__(self):\n         return 'Avatar(id={}, location={}, health={}, score={})'.format(self.player_id, self.location,\n", "issue": "Submitting empty code leads to server error\nWhen sending empty program, we are getting:\n\nTraceback:\nFile \"/Library/Python/2.7/site-packages/django/core/handlers/base.py\" in get_response\n1.                     response = wrapped_callback(request, _callback_args, *_callback_kwargs)\n   File \"/Library/Python/2.7/site-packages/django/contrib/auth/decorators.py\" in _wrapped_view\n2.                 return view_func(request, _args, *_kwargs)\n   File \"/Users/paulina.koch/Documents/C4L/forks/aimmo/ui/players/views.py\" in code\n3.             world.player_changed_code(request.user.id, request.user.player.code)\n   File \"/Users/paulina.koch/Documents/C4L/forks/aimmo/simulation/game_state.py\" in player_changed_code\n4.             avatar.set_code(code)\n   File \"/Users/paulina.koch/Documents/C4L/forks/aimmo/simulation/avatar/avatar_wrapper.py\" in set_code\n5.         self.avatar = Avatar()\n\nException Type: TypeError at /api/code/\nException Value: 'NoneType' object is not callable\n\nSimple check should be enough, but we could use it as a chance to implement an extension of validation or error handling/printing when submitting code.\n\n", "before_files": [{"content": "import traceback\nimport sys\n\nfrom simulation.action import WaitAction\n\n\n# This class will be implemented by the player\nAvatar = None\n\n\nclass UserCodeException(Exception):\n    def __init__(self, *args, **kwargs):\n        super(Exception, self).__init__(*args, **kwargs)\n        self.exc_type, self.exc_value, self.exc_traceback = sys.exc_info()\n\n    def to_user_string(self):\n        lines = traceback.format_exception(self.exc_type, self.exc_value, self.exc_traceback)\n        return '<br/>'.join(lines)\n\n\nclass AvatarWrapper(object):\n    \"\"\"\n    The application's view of a character, not to be confused with \"Avatar\", the player-supplied code.\n    \"\"\"\n\n    def __init__(self, initial_location, initial_code, player_id, avatar_appearance):\n        self.location = initial_location\n        self.health = 5\n        self.score = 0\n        self.events = []\n        self.player_id = player_id\n        self.avatar_appearance = avatar_appearance\n        self.avatar = None\n\n        self.set_code(initial_code)\n\n    def handle_turn(self, state):\n        try:\n            next_action = self.avatar.handle_turn(state, self.events)\n        except Exception as e:\n            # TODO: tell user their program threw an exception during execution somehow...\n            print('avatar threw exception during handle_turn:', e)\n            traceback.print_exc()\n            next_action = WaitAction()\n        # Reset event log\n        self.events = []\n\n        return next_action\n\n    def die(self, respawn_location):\n        # TODO: extract settings for health and score loss on death\n        self.health = 5\n        self.score = max(0, self.score - 2)\n        self.location = respawn_location\n\n    def add_event(self, event):\n        self.events.append(event)\n\n    def set_code(self, code):\n        self.code = code\n        try:\n            exec(code)\n        except Exception as ex:\n            raise UserCodeException(\"Exception in user code\", ex)\n        self.avatar = Avatar()\n\n    def __repr__(self):\n        return 'Avatar(id={}, location={}, health={}, score={})'.format(self.player_id, self.location,\n                                                                        self.health, self.score)\n\n", "path": "simulation/avatar/avatar_wrapper.py"}]}