Exemplo n.º 1
0
 def get_random_location_near_point(self, point, radius):
     while True:
         random_direction = Direction.get_random()
         random_radius = randint(2, radius + 1)
         scaled_vector = random_direction.to_scaled_vector(random_radius)
         random_point = point.plus_vector(scaled_vector)
         if self.on_map(random_point):
             return random_point
Exemplo n.º 2
0
    def calculate_orientation(self):
        """
        Calculates the orientation of the avatar (ie. what direction the avatar is pointed
        towards) for rendering in the front end of the game.
        :return: A string representation of a cardinal direction.
        """
        _current_location = self.location
        _previous_location = self.previous_location

        direction_of_orientation = Direction(_current_location.x - _previous_location.x,
                                             _current_location.y - _previous_location.y)

        if _current_location == _previous_location:
            return self.orientation

        return direction_of_orientation.cardinal
 def update_mission_map(self, messages_received):
     """Update game state (mission_map) from agent subprocess messages"""
     bullets_live = False
     for message in messages_received:
         logging.debug("Simulation:  Received message: {}".format(message))
         if message[MESSAGE_TYPE] == TAKE_TURN:
             agent = message[FROM]
             action = message[ACTION]
             if action == MOVE_TO:
                 location = Point.from_dict(message[LOCATION])
                 self.mission_map.move_agent(agent, location)
             elif action == FIRE_AT:
                 location = Point.from_dict(message[LOCATION])
                 direction = Direction.from_str(message[DIRECTION])
                 self.mission_map.create_bullet(location, direction)
                 bullets_live = True
         elif message[MESSAGE_TYPE] == MISSION_COMPLETE:
             self.mission_complete = True
             return
     if bullets_live:
         while len(self.mission_map.bullets) > 0:
             self.update_bullets()
             self.mission_map.move_bullets()
Exemplo n.º 4
0
 def __init__(self, avatar, direction):
     self.direction = Direction(**direction)
     super(MoveAction, self).__init__(avatar)
Exemplo n.º 5
0
 def __init__(self, avatar, direction):
     # Untrusted data!
     self.direction = Direction(**direction)
     super(MoveAction, self).__init__(avatar)
Exemplo n.º 6
0
 def test_repr(self):
     txt = repr(Direction(1, 0))
     self.assertRegexpMatches(txt, 'x *= *1')
     self.assertRegexpMatches(txt, 'y *= *0')
Exemplo n.º 7
0
 def test_good_data(self):
     d = Direction(0, 1)
     self.assertEqual(d.x, 0)
     self.assertEqual(d.y, 1)
Exemplo n.º 8
0
 def test_low_y(self):
     with self.assertRaises(ValueError):
         Direction(0, -1.5)
Exemplo n.º 9
0
 def test_too_far(self):
     with self.assertRaises(ValueError):
         Direction(1, 1)
Exemplo n.º 10
0
 def test_low_x(self):
     with self.assertRaises(ValueError):
         Direction(-1.5, 0)
Exemplo n.º 11
0
 def test_high_y(self):
     with self.assertRaises(ValueError):
         Direction(0, 1.5)
Exemplo n.º 12
0
 def test_high_x(self):
     with self.assertRaises(ValueError):
         Direction(1.5, 0)
Exemplo n.º 13
0
 def get_random_location_one_away(self, location):
     return location.plus_direction(Direction.get_random())
Exemplo n.º 14
0
 def __init__(self, direction):
     # Untrusted data!
     self.direction = Direction(**direction)
Exemplo n.º 15
0
 def test_incorrect_equality(self):
     d1 = Direction(0, 1)
     l1 = Location(0, 1)
     self.assertFalse(d1 == l1)
Exemplo n.º 16
0
 def test_repr(self):
     txt = repr(Direction(1, 0))
     self.assertRegex(txt, "x *= *1")
     self.assertRegex(txt, "y *= *0")