def but(self, id_team): """retourne la position des cages/buts d'un joueur (self.cage)""" if self.est_team1(): return (Vector2D(0, GAME_HEIGHT / 2 - (GAME_GOAL_HEIGHT / 2))) else: return (Vector2D(GAME_WIDTH, GAME_HEIGHT / 2 - GAME_WIDTH, (GAME_GOAL_HEIGHT / 2)))
def aller_vers_but(self): essai = MyState(self.state, self.idt, self.idp) if essai.est_team1(): return SoccerAction(POS_DEFAUT - essai.my_position, Vector2D(3.14, 20)) return SoccerAction(POS_DEFAUT2 - essai.my_position, Vector2D(6.18, 20))
def vers_les_but_adv(self): """retourne """ mystate = MyState(self.state, self.idt, self.idp) if mystate.est_team1(): V = Vector2D(angle=6.18, norm=10) else: V = Vector2D(angle=3.14, norm=10) return V
def shoot(self, state, id_team, id_player): mystate = MyState(self.state, self.idt, self.idp) sh = Vector2D(0, 0) if mystate.distance_ball_player() < PLAYER_RADIUS + BALL_RADIUS: if mystate.distance_but_ball() < 40: sh = Vector2D(10, 10) if mystate.distance_but_ball() > 40: # and personne(): sh = Vector2D(20) return sh
def distance_but_ball(self): """retourne la distance entre la balle et les cages/buts""" if self.est_team1(): return self.ball_position.distance( Vector2D(0, GAME_HEIGHT / 2 - (GAME_GOAL_HEIGHT / 2))) else: return self.ball_position.distance( Vector2D(GAME_WIDTH, GAME_HEIGHT / 2 - GAME_WIDTH, (GAME_GOAL_HEIGHT / 2)))
def dribbler(self): pos = Position(self.state, self.idt, self.idp) mystate = MyState(self.state, self.idt, self.idp) liste_adversaire = [] for i in pos.position_tout_les_joueurs(): if self.idt == mystate.adv(): liste_adversaire.append(i) for j in range(0, len(liste_adversaire)): if (pos.joueur_le_plus_proche(1).x == liste_adversaire[j].x) and ( pos.joueur_le_plus_proche(1).y == liste_adversaire[j].y): SoccerAction(((liste_adversaire[j]) + Vector2D(10, 0)) - mystate.myposition, Vector2D(angle=0, norm=10))
def begin_round(self, team1, team2, state): ball = Vector2D.create_random(low=0, high=1) ball.y = ball.y * GAME_HEIGHT ball.x = ball.x * GAME_WIDTH * (3 / 5) + GAME_WIDTH * (3 / 5) self.simu.state.states[(1, 0)].vitesse = Vector2D() # Player accelerati self.simu.state.ball.position = ball.copy() # Ball position self.last_step = self.simu.step self.simu.state.states[(1, 0)].position = self.simu.state.ball.position # Last step of the game # Set the current value for the current parameters for key, value in self.cur_param.items(): setattr(self.strategy, key, value)
def aller_vers_balle_condition(self): mystate = MyState(self.state, self.idt, self.idp) #if( mystate.est_team1(self)): liste_players = self.idt.nb_players #team1.nb_players #else: # liste_players = team2.nb_players distance_self = mystate.distance_ball_player for player in liste_players: distance = mystate.ball_position - mystate.my_position( liste_players[player]) if distance <= mystate.PR_BR: return SoccerAction(mystate.en_attente) return SoccerAction(mystate.distance_ball_player, Vector2D(angle=3.14, norm=55))
def suivre_ball (state, id_team, id_player): return SoccerAction (acceleration = state.ball.position - state.player_state(id_team, id_player).position, shoot = Vector2D(0,0))
def shoot (state, id_team, id_player, X, Y): if (id_team == 2): return SoccerAction (acceleration = Vector2D(0,0), shoot = Vector2D(-(X - state.player_state(id_team, id_player).position.x), Y - state.player_state(id_team, id_player).position.y)) if (id_team == 1): return SoccerAction (acceleration = Vector2D(0,0), shoot = Vector2D( X - state.player_state(id_team, id_player).position.x, Y - state.player_state(id_team, id_player).position.y))
def miroir (id_team, v): if (id_team == 2): return Vector2D(-1*v.x , v.y) return Vector2D(v.x , v.y)
def aller(self, p): return SoccerAction(p - self.my_position, Vector2D())
def shoot(self, p): return SoccerAction(Vector2D(), p - self.my_position, Vector2D())
def passe(state, id_team, id_player) : for palyer in [ (it, ip) for (it, ip) in state.players if it == id_team] : if (est_demarque(state, it, ip)): return SoccerAction (acceleration = Vector2D(0,0), shoot = Vector2D(state.palyer(it, ip).position.x - state.player_state(id_team, id_player).position.x, state.palyer(it, ip).position.y - state.player_state(id_team, id_player).position.y)) return SoccerAction()
PLAYER_RADIUS = 1. BALL_RADIUS = 0.65 GAME_WIDTH = 150 # Longueur du terrain GAME_HEIGHT = 90 # Largeur du terrain GAME_GOAL_HEIGHT = 10 # Largeur des buts PLAYER_RADIUS = 1. # Rayon d un joueur BALL_RADIUS = 0.65 # Rayon de la balle MAX_GAME_STEPS = 2000 # duree du jeu par defaut maxPlayerSpeed = 1. # Vitesse maximale d un joueur maxPlayerAcceleration = 0.2 # Acceleration maximale maxBallAcceleration = 5 # #mes variables globales POS_DEFAUT = Vector2D(20, 45) #goal team 1 POS_DEFAUT2 = Vector2D(GAME_WIDTH + 45, GAME_WIDTH / 2) #goal team 2 # parametres utilisés ''' ########################################################### #LA BASE = outils ############################################################ ''' class MyState(object): def __init__( self, state, id_team, id_player ): #__init__ appelée automatiquement après la création de l'objet, pour creer l'état de départ= initilisation
def pos_attaquant(self): return SoccerAction( Vector2D(10, GAME_WIDTH - 60) - (self.state.player_state(self.idt, self.idp)).position)
def cage (id_team): if (id_team == 2): return Vector2D(145,45) if (id_team ==1): return Vector2D(5,45)
def aller_vers_balle(self): mystate = MyState(self.state, self.idt, self.idp) return SoccerAction(mystate.distance_ball_player, Vector2D(angle=3.14, norm=55))