Ejemplo n.º 1
0
def tire_basStrat(etat):
    V = Vector2D(angle = -45, norm = 2)
    if not((etat.ball_position - etat.my_position).angle < -42 and (etat.ball_position - etat.my_position).angle > -48):
        res =  etat.go(etat.ball_position - 0.1 *V)
    else:
        res =  SoccerAction(etat.ball_position - etat.my_position,Vector2D(angle=-45, norm=2))
    res.name = "tire_basStrat"
    return res
Ejemplo n.º 2
0
def dribleStrat(etat):
    V = (etat.ball_position - etat.adv_but)*1.05
    if not(etat.dans_zone(zone(etat.adv_but + V - Vector2D(5,5), etat.adv_but + V + Vector2D(5,5)),etat.my_position)):
        res =  SoccerAction((etat.adv_but + V) - etat.my_position, Vector2D(0,0))
    else:
        res = SoccerAction(etat.ball_position - etat.my_position,0.030*(etat.adv_but - etat.my_position))
    res.name = "dribleStrat"
    return res
Ejemplo n.º 3
0
def passe(me):
	res=SoccerAction(Vector2D(),Vector2D())
	res.name="passe"
	if me.test_peut_shooter:
		res=me.shoot_vers_norm(me.pos_equi_pr_ball,3.0)
		return res
	else:
		res=me.courir_vers_ball2
		return res
Ejemplo n.º 4
0
def degage_cote(a):
    dep=a.ball_position-a.my_position            #--> bloquer le passage de la balle 
    dep.x=0
    
    if a.can_shoot() == 0:  # Shoot ou pas        
        if a.my_position.y >= settings.GAME_HEIGHT/2: 
            res= SoccerAction(dep,Vector2D((3.14),4.5)) # angle a modifie
            res.name="degage_cote_haut"
            return res
        else:
            res=SoccerAction(dep,Vector2D(-(3.14),4.5))
            res.name="degage_cote_bas"
            return res
    return SoccerAction(dep,Vector2D())
Ejemplo n.º 5
0
def degager(app):       
    hisg = Vector2D((2-app.key[0])*settings.GAME_WIDTH,settings.GAME_HEIGHT/2.)
    shoot=hisg-app.ball_position
    
    s=SoccerAction(app.ball_position-app.my_position, shoot)
    s.shoot.norm=4
    
    if app.key[0]==2: #miroir fail 
        s.acceleration.x=-s.acceleration.x
        s.shoot.x=-s.shoot.x
        
    if app.can_shoot() == 0:
        s.name="degager"
        return s

    return SoccerAction(Vector2D(),Vector2D())
Ejemplo n.º 6
0
 def compute_strategy(self, state, player, teamid):
     test = Outils(state, teamid, player)
     if (test.canshoot()):
         tir = Vector2D.create_polar(player.angle + 2.5, 100)
     else:
         tir = Vector2D(0, 0)
     return SoccerAction(Vector2D(0, 0), tir)
Ejemplo n.º 7
0
    def shoot_intercepter_contrecarE(self):
        vect_input = self.state.ball.vitesse
        vect_output_x = -vect_input.x
        vect_output_y = -vect_input.y
        vect_output = Vector2D(vect_output_x, vect_output_y)

        return SoccerAction(Vector2D(), vect_output)
Ejemplo n.º 8
0
def defenseur3(state):
    if state.v4v4[0]:
        return defenseur2(state)
    else:
        return SoccerAction(
            Vector2D(state.coequipier1.x, state.coequipier22.y) - state.player,
            state.coequipier22 - state.player)
Ejemplo n.º 9
0
 def compute_strategy(self, state, player, teamid):
     g = state.get_goal_center(2)
     dis = (state.ball.position - player.position)
     b = state.ball.position + state.ball.speed
     p = player.position
     bp = b - p
     bp.x = bp.x * 1.2
     bp.y = bp.y * 1.2
     if teamid == 2:
         bp.x = bp.x + 0.5
     else:
         bp.x = bp.x - 0.5
     if (p.y > (GAME_HEIGHT / 2)):
         shoot = Vector2D(GAME_WIDTH, GAME_HEIGHT / 2 + GAME_GOAL_HEIGHT / 2
                          - 0.5) - state.ball.position - state.ball.speed
     else:
         shoot = Vector2D(GAME_WIDTH, GAME_HEIGHT / 2 - GAME_GOAL_HEIGHT / 2
                          + 0.5) - state.ball.position - state.ball.speed
     if (teamid == 2):
         if (p.y > (GAME_HEIGHT / 2)):
             shoot = Vector2D(0, GAME_HEIGHT / 2 + GAME_GOAL_HEIGHT / 2 -
                              0.5) - state.ball.position - state.ball.speed
         else:
             shoot = Vector2D(0, GAME_HEIGHT / 2 - GAME_GOAL_HEIGHT / 2 +
                              0.5) - state.ball.position - state.ball.speed
     if ((PLAYER_RADIUS + BALL_RADIUS) < (dis.norm)):
         shoot = Vector2D(0, 0)
     return SoccerAction(bp, shoot)
Ejemplo n.º 10
0
 def compute_strategy(self, state, player, teamid):
     g = state.get_goal_center(need.get(teamid))
     b = state.ball.position
     dist = b - player.position
     gb = state.get_goal_center(need.get(teamid)) - player.position
     shoot = Vector2D.create_polar(gb.angle + random.uniform(-1, 1), g.norm)
     return SoccerAction(dist, shoot)
Ejemplo n.º 11
0
def QuickCatch(mystate):
    d=mystate.state.ball.position-mystate.state.player(mystate.id_team,mystate.id_player).position
    #print state.ball.position-state.player(2,0).position
    if mystate.state.ball.vitesse._x==0 and d.norm<2:
        d.scale(0.009)
    return SoccerAction(d,
                        Vector2D(0,45)-mystate.state.ball.position)
Ejemplo n.º 12
0
    def compute_strategy(self, state, id_team, id_player):
        # id_team is 1 or 2
        # id_player starts at 0

        return SoccerAction(
            Vector2D(random.randint(-1, 1), random.randint(-1, 1)),
            Vector2D(random.randint(-1, 1), random.randint(-1, 1)))
Ejemplo n.º 13
0
 def entreballetbut(self):
     vecteurballbut = Vector2D(
         ((2 - self.id_team) * settings.GAME_WIDTH) - self.ball_positionx,
         settings.GAME_HEIGHT / 2. - self.ball_positiony)
     vecteurballjoueur = Vector2D(self.my_positionx - self.ball_positionx,
                                  self.my_positiony - self.ball_positiony)
     return SoccerAction(vecteurballbut - vecteurballjoueur)
Ejemplo n.º 14
0
def kickAt(state, dest, powerShoot=maxPlayerShoot):
    """
    Frappe la balle en direction de dest avec
    une puissance de powerShoot
    """
    return SoccerAction(Vector2D(),
                        normalise_diff(state.ball_pos, dest, powerShoot))
Ejemplo n.º 15
0
def defenseur4(state):
    if state.v4v4[1]:
        return defenseur2(state)
    else:
        return SoccerAction(
            Vector2D(state.coequipier0.x, state.coequipier3.y) - state.player,
            state.coequipier3 - state.player)
Ejemplo n.º 16
0
 def compute_strategy(self, state, id_team, id_player):
     label = self.tree.predict(
         [self.get_features(state, id_team, id_player)])[0]
     if label not in self.dic:
         self.logger.error("Erreur : strategie %s non trouve" % (label, ))
         return SoccerAction()
     return self.dic[label].compute_strategy(state, id_team, id_player)
Ejemplo n.º 17
0
 def compute_strategy(self, state, id_team, id_player):
     t = Tools(state, id_team, id_player)
     c = Comportement(state, id_team, id_player)
     if state.get_score_team(1) + state.get_score_team(2) > self.cpt2:
         self.cpt2 = state.get_score_team(1) + state.get_score_team(2)
         self.cpt = 0
     if self.cpt > 100:
         if t.test_shoot():
             if not t.closest_ennemi_behind():
                 if t.ennemi_in_my_small_perimeter():
                     return c.dribble(5.)
                 return c.dribble(1.5)
             if t.ball_in_his_goal_perimeter():
                 return c.shoot()
             return c.shoot3(2.)
         else:
             return c.run_anticipe()
     else:
         self.cpt += 1
         if t.ball_in_my_half():
             if t.test_shoot():
                 if not t.closest_ennemi_behind():
                     if t.ennemi_in_my_small_perimeter():
                         return c.dribble(5.)
                     return c.dribble(1.5)
                 if t.ball_in_his_goal_perimeter():
                     return c.shoot()
                 return c.petit_shoot2(2.)
             else:
                 return c.run_anticipe()
         else:
             return SoccerAction(Vector2D(0, 0), Vector2D(0, 0))
Ejemplo n.º 18
0
 def compute_strategy(self,state,id_team,id_player):
     d=state.ball.position-state.player(id_team,id_player).position
     #print state.ball.position-state.player(2,0).position
     if state.ball.vitesse._x==0 and d.norm<1:
         d.scale(0)
     return SoccerAction(d,
                         Vector2D(0,45)-state.ball.position)
Ejemplo n.º 19
0
    def compute_strategy(self, state, id_team, id_player):
        act = Action(state, id_team, id_player)
        mystate = MyState(state, id_team, id_player)
        qui = Qui_a_la_balle(state, id_team, id_player)
        distance = mystate.distance_ball_player
        #distance entre la balle et le but
        distance_but = mystate.distance_but_ball

        if distance > 20:
            if (mystate.adv() == 2):
                position = Vector2D(
                    (0.5 / 5) * GAME_WIDTH,
                    state.ball.position.y) - mystate.my_position
            else:
                position = Vector2D(
                    (3.5 / 5) * GAME_WIDTH,
                    state.ball.position.y) - mystate.my_position
        else:
            position = state.ball.position - mystate.my_position
            #return SoccerAction(position,V-mystate.my_position)


#            if qui.mon_equipe_a_la_b():
#                return mystate.en_attente
#            else:
        return SoccerAction(state.ball.position-state.player_state(id_team,id_player).position,\
                    Vector2D((2-id_team)*settings.GAME_WIDTH,settings.GAME_HEIGHT/2.)-state.ball.position)
Ejemplo n.º 20
0
 def compute_strategy(self, state, player, teamid):
     p = (GAME_HEIGHT / 2 + GAME_GOAL_HEIGHT / 2) - 0.5
     if teamid == 1:
         direct = Vector2D(0.75, p) - player.position
     else:
         direct = Vector2D(GAME_WIDTH - 1.0, p) - player.position
     return SoccerAction(direct, Vector2D())
Ejemplo n.º 21
0
 def compute_strategy(self, state, player, teamid):
     need = Need(state, teamid, player)
     gp = state.get_goal_center(need.get()) - player.position
     padv = need.posPlayeradv()
     gpadv = state.get_goal_center(need.get()) - padv
     if need.CanIshoot():
         if need.Playeradv():
             if (gp.norm < gpadv.norm):
                 shoot = Vector2D(3, 3)
                 return SoccerAction(Vector2D(), shoot)
             else:
                 return SoccerAction(Vector2D(), gp)
         else:
             #shoot = state.get_goal_center(need.get(teamid))
             return SoccerAction(Vector2D(), gp)
     return SoccerAction(Vector2D(), Vector2D())
Ejemplo n.º 22
0
 def compute_strategy(self, state, id_team, id_player):
     qui = Qui_a_la_balle(state, id_team, id_player)
     act = Action(state, id_team, id_player)
     #if qui.j_ai_la_balle()==True:
     #p=act.passe_test(state,id_team,id_player)
     return SoccerAction(state.ball.position-state.player_state(id_team,id_player).position ,\
            Vector2D((2-id_team)*settings.GAME_WIDTH,settings.GAME_HEIGHT/2.)-state.ball.position)
Ejemplo n.º 23
0
def attaquant5(state):
    if state.teamatt2[0]:
        return gobetteratt(state)
    else:
        return SoccerAction(
            acceleration=Vector2D(state.teamatt2[1], (state.milieuloin).y) -
            state.player)
Ejemplo n.º 24
0
 def compute_strategy(self, state, id_team, id_player):
     s = SuperState(state, id_team, id_player)
     if (s.ball.x == GAME_WIDTH / 2 and s.ball.y == GAME_HEIGHT / 2):
         self.engage = 0
     # id_team is 1 or 2
     # id_player starts at 0
     if (self.engage == 0):
         if (s.dir_ball.norm < CAN_SHOOT + 1.784):
             self.engage = 1
             return SoccerAction(
                 s.dir_ball.normalize().scale(5.0),
                 s.shoot((s.goal_e - s.player)).normalize().scale(5))
     if (s.dir_ball.norm < CAN_SHOOT):
         return SoccerAction(
             s.dir_ball.normalize().scale(5.0),
             s.shoot((s.goal_e - s.player)).normalize().scale(5))
     return SoccerAction(s.dir_ball.normalize().scale(5.0), Vector2D(0, 0))
Ejemplo n.º 25
0
 def avancertoutdroit(self):
     s = SuperState(self.state, self.id_team, self.id_player) 
     if self.id_team == 1 :
         shoot = Vector2D(GAME_WIDTH, s.player.y) - s.player
     else :
         shoot = Vector2D(0, s.player.y) - s.player
         
     return SoccerAction(shoot = shoot.normalize()*1)
Ejemplo n.º 26
0
def attaquant(state):
    if state.teamatt[1]:
        return SoccerAction(
            Vector2D(GAME_WIDTH * (state.teamatt[0]),
                     (state.ballameliorer.y + state.goal.y) / 2) -
            state.player, state.goal - state.player)
    else:
        return gobettervolley(state)
Ejemplo n.º 27
0
def defenseur(state):
    if state.teamdef[1]:
        return SoccerAction(
            Vector2D(GAME_WIDTH * (state.teamdef[0]),
                     (state.ballameliorer.y + state.goal.y) / 2) -
            state.player, state.goal - state.player)
    else:
        return gobetterdef(state)
Ejemplo n.º 28
0
    def goal(self):
        if (self.id_team == 1):
            back = Vector2D(5, GAME_HEIGHT / 2.) - self.pos()
            if ((self.ball_pos.x < GAME_WIDTH / 10)
                    and (self.dist_ball() < 8)):
                return self.suivre_balle() + self.shoot_def()
            else:
                return SoccerAction(back, Vector2D())

        else:
            back = Vector2D(GAME_WIDTH - 5, GAME_HEIGHT / 2.) - self.pos()

            if ((self.ball_pos.x > 9 * GAME_WIDTH / 10)
                    and (self.dist_ball() < 8)):
                return self.suivre_balle() + self.shoot_def()
            else:
                return SoccerAction(back, Vector2D())
Ejemplo n.º 29
0
 def revenir_posi_def(self, id_team):
     if (id_team == 1):
         return SoccerAction(
             self.vect_player_posi(
                 GAME_WIDTH * self.cst_defense,
                 (((self.posi_ball().y) -
                   (GAME_HEIGHT / 2)) / self.posi_ball().x) *
                 (GAME_WIDTH * self.cst_defense) + GAME_HEIGHT / 2), 0)
     return SoccerAction(
         self.vect_player_posi(
             GAME_WIDTH - (self.cst_defense * GAME_WIDTH),
             ((((self.posi_ball().y) - (GAME_HEIGHT / 2)) /
               ((self.posi_ball().x) - (GAME_WIDTH))) *
              (GAME_WIDTH -
               (self.cst_defense * GAME_WIDTH)) + GAME_HEIGHT / 2 -
              (((self.posi_ball().y) - (GAME_HEIGHT / 2)) /
               ((self.posi_ball().x) - (GAME_WIDTH))) * GAME_WIDTH)), 0)
Ejemplo n.º 30
0
    def compute_strategy(self, state, id_team, id_player):
        # id_team is 1 or 2
        # id_player starts at 0
        s = SuperState(state, id_team, id_player)
        balle = s.ball
        joueur = s.player

        if (id_team == 1):
            if s.can_shoot:
                return SoccerAction(shoot=s.goal_opponent - s.player)
            else:
                return SoccerAction(acceleration=balle - s.player)
        else:
            if s.can_shoot:
                return SoccerAction(shoot=s.goal_opponent - s.player)
            else:
                return SoccerAction(acceleration=balle - s.player)
Ejemplo n.º 31
0
def aller_defense(state, id_t, id_p, decalage):
        e=Etat(state)
        pos_def= e.poscage(id_t)
        if pos_def.x==0:
                pos_def.x+=decalage
        elif pos_def.x==GAME_WIDTH:
                pos_def.x-=decalage
        return SoccerAction(dirpos(e, id_t, id_p, 5, pos_def))
Ejemplo n.º 32
0
    def compute_strategy(self, state, id_team, id_player):
        p = state.player_state(id_team, id_player)
        MyState = PlayerDecorator(state, id_team, id_player)

        if (MyState.distanceAll() < 10):
            return SoccerAction(
                Vector2D(settings.GAME_WIDTH - 70, state.ball.position.y) -
                p.position, Vector2D(0, 0))

        if (MyState.position_balle() > 75):
            return SoccerAction((state.ball.position - p.position),
                                Vector2D(-(settings.GAME_HEIGHT), 0))

        else:
            return SoccerAction(
                Vector2D(settings.GAME_WIDTH - 70, state.ball.position.y) -
                p.position, Vector2D(0, 0))
Ejemplo n.º 33
0
 def compute_strategy(self, state, id_team, id_player):
     t = Tools(state, id_team, id_player)
     c = Comportement(state, id_team, id_player)
     if t.test_shoot():
         return c.shoot()
     if t.in_my_third():
         return SoccerAction(Vector2D(0, 0), Vector2D(0, 0))
     return c.run()
Ejemplo n.º 34
0
    def compute_strategy(self, state, id_team, id_player):
        s = SuperState(state, id_team, id_player)

        if s.player.distance(s.ball) < PLAYER_RADIUS + BALL_RADIUS:
            if s.closest_opponent.distance(s.player) < (PLAYER_RADIUS * 20):
                return s.dribble
            elif s.getDistanceTo(s.goal_opponent) < (
                    PLAYER_RADIUS * 20
            ):  #Si il est dans la surface de tir : shoot, sinon avance
                shoot = s.goal_opponent - s.player
                return SoccerAction(shoot=shoot.normalize() * 115)
            else:
                shoot = s.goal_opponent - s.player
                return SoccerAction(shoot=shoot.normalize() * 1.2)
        else:
            deplacement = s.ball - s.player
            return SoccerAction(acceleration=deplacement.normalize() * 1500)
Ejemplo n.º 35
0
    def compute_strategy(self, state, id_team, id_player):
        s = SuperState(state, id_team, id_player)

        if s.milieu:
            if s.can_shoot:
                return SoccerAction(shoot=s.goal_opponent - s.player)
            else:
                return SoccerAction(acceleration=s.balleamelioree - s.player)
        else:
            if s.can_shoot:
                if s.testjoueurdevant:
                    return SoccerAction(shoot=s.coequipierprochedevant -
                                        s.player)
                else:
                    return SoccerAction(shoot=s.goal_opponent - s.player)
            else:
                return SoccerAction(acceleration=s.balleamelioree - s.player)
Ejemplo n.º 36
0
def attend(etat):
    res = SoccerAction(Vector2D(0,0),Vector2D(0,0))
    res.name = "attend"
    return res