Exemplo n.º 1
0
 def Kick(player, dest, spd):
     Util.Assert(Util.PositionValid(dest))
     Util.Assert(spd > 0 and spd <= 100)
     return {
         'action': 'KICK',
         'playerNumber': player.Number,
         'destination': {
             'x': dest[0],
             'y': dest[1]
         },
         'speed': spd
     }
Exemplo n.º 2
0
 def __CalculateBestYPosition(self) :
     
     def ModifyDir(direction, dirMod) :
         direction += dirMod
         if direction >= 360 :
             direction -= 360
         elif direction < 0 :
             direction += 360
         Util.Assert(Util.DirectionValid(direction))
         return direction
     
     direction = Util.Direction(self.Position, self.__ai.Ball.Position)
         
     if Util.IsNearlyVertical(direction, 10) :
         dirModAmount = 90
         if self.__ai.Ball.Position[1] > self.Position[1] :
             dirMod = -dirModAmount if self.__ai.DirectionRight else dirModAmount
             direction = ModifyDir(direction, dirMod)
             return self.__ai.MyGoalPosition(False)[1], direction
         else :
             dirMod = dirModAmount if self.__ai.DirectionRight else -dirModAmount
             direction = ModifyDir(direction, dirMod)
             return self.__ai.MyGoalPosition(True)[1], direction
     
     topCornerDistance = Util.DistanceLimitForSave( Util.Distance(self.__ai.Ball.Position, self.__ai.MyGoalPosition(True)))
     bottomCornerDistance = Util.DistanceLimitForSave( Util.Distance(self.__ai.Ball.Position, self.__ai.MyGoalPosition(False)))
     
     s = topCornerDistance - (topCornerDistance + bottomCornerDistance - Class.Pitch.GoalWidth) / 2
     #self.__ai.LogErr('SAVE DISTANCES :   %.2f | %.2f' % (topCornerDistance, bottomCornerDistance))
     y =  Class.Pitch.GoalY[0] + s
     Util.Assert(Util.DirectionValid(direction))
     return y, direction
Exemplo n.º 3
0
 def Turn(player, direction):
     Util.Assert(Util.DirectionValid(direction))
     return {
         'playerNumber': player.Number,
         'action': 'TURN',
         'direction': direction
     }
Exemplo n.º 4
0
 def Pass(self, passFromPlayer, passToPlayer, xAdjust = 0, yAdjust = 0) :
     Util.Assert(passFromPlayer.Number != passToPlayer.Number)
     if xAdjust is None :
         xAdjust = 0
     if not self.DirectionRight :
         xAdjust *= -1
     passFromPlayer.SetActionGen( Util.PassBall(self, passFromPlayer, passToPlayer.Position, (xAdjust, yAdjust)) )
     passToPlayer.SetActionGen( Util.ReceiveBall(self, passFromPlayer.Position, passToPlayer ) )
Exemplo n.º 5
0
 def ModifyDir(direction, dirMod) :
     direction += dirMod
     if direction >= 360 :
         direction -= 360
     elif direction < 0 :
         direction += 360
     Util.Assert(Util.DirectionValid(direction))
     return direction
Exemplo n.º 6
0
 def PassQuick(self, passFromPlayer, passToPlayer, xAdjust = 0, yAdjust = 0) :
     Util.Assert(passFromPlayer.Number != passToPlayer.Number)
     # pass by kicking immediately - no time to turn.
     if not self.DirectionRight :
         xAdjust *= -1
     destination = (passToPlayer.Position[0] + xAdjust, passToPlayer.Position[1] + yAdjust)
     distance = Util.Distance(passFromPlayer.Position, destination)
     speed = self.Ball.GetSpeedForDistance(distance*1.2)
     def OneOffKickGen(pl, dest, sp) :
         yield Class.Action.Kick(pl, dest, sp)
     passFromPlayer.SetActionGen( OneOffKickGen(passFromPlayer, destination, speed) )
     passToPlayer.SetActionGen( Util.ReceiveBall(self, passFromPlayer.Position, passToPlayer ) )
Exemplo n.º 7
0
    def Move(player, dest):
        try:
            Util.Assert(
                Util.PositionValid(dest, player.IsGoalkeeper,
                                   player.PlayDirectionRight))
        except:
            # usually occurs because a pass goes into the goal circle and I request to intercept the ball
            msg = 'GK[%r]. Right[%r] Invalid position %s' % (
                player.IsGoalkeeper, player.PlayDirectionRight, str(dest))
            Util.Debug('Move requested to invalid position. ' + msg)
            pass

        return {
            'action': 'MOVE',
            'playerNumber': player.Number,
            'destination': {
                'x': dest[0],
                'y': dest[1]
            }
        }
Exemplo n.º 8
0
 def TranslatePos(self, pos) :
     '''Return true x,y position. The x axis origin at the centre and +ve is towards opponent goal'''
     ret = (pos[0] + 50, pos[1]) if self.DirectionRight else (50 - pos[0], pos[1])
     Util.Assert(Util.PositionValid(ret))
     return ret