Ejemplo n.º 1
0
 def perform(self, comms):
     position = self.robot.get_blocking_position(self.world)
     if utils.find_obstacle(self.world, self.robot.vector, position):
         # Do nothing
         return
     dx = position.x - self.robot.x
     dy = position.y - self.robot.y
     d = math.sqrt(dx**2 + dy**2)
     comms.move(d)
Ejemplo n.º 2
0
 def get_goal(self, world, robot):
     '''
     Selects a goal for robot
     '''
     '''        if robot.has_ball(world.ball):
         return attacker.Score(world, robot)
     else:
         return attacker.GetBall(world, robot)'''
     if self.current_task == 'move-grab':
         return attacker.GetBall(world, robot)
     elif self.current_task == 'turn-move-grab':
         return attacker.GetBall(world, robot)
     elif self.current_task == 'turn-shoot':
         if robot.has_ball(world.ball):
             return attacker.Score(world, robot)
         else:
             info("Trying to turn-shoot without ball. Using GetBall instead.")
             return attacker.GetBall(world, robot)
     elif self.current_task == 'receive-pass':
         if world.our_defender.has_ball(world.ball):
             return attacker.AttackPosition(world, robot)
         else:
             return attacker.GetBall(world, robot)
     elif self.current_task == 'receive-turn-pass':
         if world.their_robots[0].has_ball(world.ball) or world.their_robots[1].has_ball(world.ball):
             return attacker.AttackPosition(world, robot)
         elif robot.has_ball(world.ball):
             return attacker.AttackerPass(world, robot)
         else:
             return attacker.GetBall(world, robot)
     elif self.current_task == 'intercept':
         return attacker.AttackerBlock(world, robot)
     elif self.current_task == 'score-zone':
         return attacker.AttackPosition(world, robot)
     elif world.game_state == 'normal-play':
         if world.our_attacker.has_ball(world.ball):
             info("Attacker has ball so trying to score")
             return attacker.Score(world, robot)
         elif world.our_defender.has_ball(world.ball):
             info("Defender has ball so going to attack position")
             return attacker.AttackPosition(world, robot)
         elif any([r.has_ball(world.ball) for r in world.their_attackers]):
             info("Opponent in our half has ball so going to score position")
             return attacker.AttackPosition(world, robot)
         elif any([r.has_ball(world.ball) for r in world.their_defenders])\
              and world.is_possible_vector_position(world.our_attacker, world.our_attacker.get_blocking_position(world)):
             info("Opponent in their half has ball so blocking")
             return attacker.AttackerBlock(world, robot)
         elif world.is_possible_position(world.our_attacker, world.ball.x, world.ball.y):
             info("Ball is in possible position so getting ball")
             return attacker.GetBall(world, robot)
         else:
             info("All else failed so going to attack position")
             return attacker.AttackPosition(world, robot)
     elif self.current_task == 'test-obstacle':
         print(math.degrees(utils.get_avoiding_angle_to_point(world,
                                                 world.our_attacker.vector,
                                                 world.ball.vector)))
         from position import Vector
         print(utils.find_obstacle(world, robot.vector, world.ball.vector))
         return attacker.GetBall(world, robot)