def __init__(self,x,y): self.x=x self.y=y self.potentiel=pt.Potentiel(-3,[self.x,self.y],x_grid,y_grid,2500) self.position=complex(x,y) self.x10=[x] self.y10=[y]
def champ_perso(self,x_depart,x_arrivee,a,b): self.Potentiel() Ex1,Ey1=pt.Gradient(self.potentiel) Ex1,Ey1=pt.Grad(Ex1,Ey1,self.x,self.y,x_depart,x_arrivee,a,b) potentiel_repulsion=pt.Potentiel(+10,[self.x,self.y],p.x_grid,p.y_grid,p.r_evit/1.5) Ex10,Ey10=pt.Gradient(potentiel_repulsion) self.Ex,self.Ey=p.k*Ex10+Ex1,p.k*Ey10+Ey1
def Position(self,ball): self.x,self.y=ball[6],ball[7] self.position=complex(self.x,self.y) self.potentiel=pt.Potentiel(-3,[self.x,self.y],x_grid,y_grid,2500) #potentiel négatif pour attirer les robots if len(self.x10)>9: self.x10.pop(0) self.y10.pop(0) self.x10.append(self.x) #on enregistre les 10 dernieres positions de la balle self.y10.append(self.y)
def champ_perso(self, x_depart, x_arrivee, a, b): #permet de calculer le champ produit par ce robot self.Potentiel() Ex1, Ey1 = pt.Gradient(self.potentiel) Ex1, Ey1 = pt.Grad(Ex1, Ey1, self.x, self.y, x_depart, x_arrivee, a, b) potentiel_repulsion = pt.Potentiel(+10, [self.x, self.y], x_grid, y_grid, r_evit / 1.5) Ex10, Ey10 = pt.Gradient(potentiel_repulsion) self.Ex, self.Ey = k * Ex10 + Ex1, k * Ey10 + Ey1
def Position(self, ball): self.x, self.y = ball[6], ball[7] self.position = complex(self.x, self.y) self.potentiel = pt.Potentiel(-3, [self.x, self.y], x_grid, y_grid, 2500) if len(self.x10) > 9: self.x10.pop(0) self.y10.pop(0) self.x10.append(self.x) self.y10.append(self.y)
def Potentiel(self): self.potentiel = pt.Potentiel(10, [self.x, self.y], x_grid, y_grid, r_evit)
def Potentiel(self): self.potentiel=pt.Potentiel(10,[self.x,self.y],p.x_grid,p.y_grid,p.r_evit)
def Potentiel(self): #calcul le potentiel créé par ce robot self.potentiel = pt.Potentiel(10, [self.x, self.y], x_grid, y_grid, r_evit)
hy=2*largeur/nbPoints balls, blueBots, yellowBots = getVision() ball=balls[0] xball,yball=ball[6],ball[7] def norme(Vx,Vy): return(Vx/sqrt(Vx**2+Vy**2),Vy/sqrt(Vx**2+Vy**2)) def Rotationnel(x,y,Fx,Fy): dFx = (diff(Fx,axis=0)/hy)[:,:-1] dFy = (diff(Fy,axis=1)/hx)[:-1,:] return dFy - dFx potentielBalle=pt.Potentiel(-3,[xball,yball],x,y,2500) for bot in blueBots: if bot[5]==0: botInfo=bot xbot,ybot,obot=botInfo[6],botInfo[7],botInfo[8] a,b=np.polyfit([xball,xbot],[yball,ybot],1) def grad(Ex,Ey,x,y): if (xball-xbot)<0: Ex,Ey=-Ex,-Ey if (a*x+b)>y: Ex,Ey=Ey,-Ex else : Ex,Ey=-Ey,Ex