def get_right(self): return [ Auxiliars.angle_to_vector(self.physics.get_angle() + math.pi / 2.0)[0], Auxiliars.angle_to_vector(self.physics.get_angle() + math.pi / 2.0)[1] ]
def __init__(self, pars, player_pos, wih=None, who=None): self.pars = pars v = random.uniform(0, pars['v_max']) # velocity [0, v_max] # orientation [0, 360] self.pars["ang"] = random.uniform(0, 360) front = Auxiliars.angle_to_vector(self.pars["ang"]) self.pars["vel"] = [v * front[0], v * front[1]] # self.pars["pos"] = [uniform(0, pars['WIDTH']), uniform(0, pars['HEIGHT'])] Ship.__init__(self, self.pars, True, self.pars["acc"], self.pars["ang_acc"], self.pars["fr"]) self.delay = 0 # self.dv = pars["acc_max"] self.d_player = 0 # distance to player self.angle_front = 0 self.angle_right = 0 self.facing(player_pos) # orientation to player Ship.set_score(self, pars["score"]) # fitness (score) self.wih = wih self.who = who af = lambda x: np.tanh(x) # activation function h1 = af( np.matmul( self.wih, np.mat(np.array([1.0, self.angle_front, self.d_player])).transpose())) # hidden layer out = af( np.matmul( self.who, np.mat(np.append(np.mat(np.ones(np.size(h1, 1))), h1, axis=0)))) # output layer
def get_front(self): return [ Auxiliars.angle_to_vector(self.physics.get_angle())[0], Auxiliars.angle_to_vector(self.physics.get_angle())[1] ]
def get_right(self): return [Auxiliars.angle_to_vector(self.kinematic_dict["ang"]+math.pi/2.0)[0], Auxiliars.angle_to_vector(self.kinematic_dict["ang"]+math.pi/2.0)[1]]
def get_front(self): return [Auxiliars.angle_to_vector(self.kinematic_dict["ang"])[0], Auxiliars.angle_to_vector(self.kinematic_dict["ang"])[1]]
def shoot(self): self.missile_group.add(Sprite([self.pos[0]+self.radius*Auxiliars.angle_to_vector(self.values["angle"])[0],\ self.pos[1]+self.radius*Auxiliars.angle_to_vector(self.values["angle"])[1]], \ [self.vel[0]+(Auxiliars.angle_to_vector(self.values["angle"])[0])*7 , self.vel[1]+(Auxiliars.angle_to_vector(self.values["angle"])[1])*7], \ 0, 0, self.pars["missile_image"], self.pars["missile_info"], self.WIDTH, self.HEIGHT, self.pars["missile_sound"]))
def get_right(self): return [Auxiliars.angle_to_vector(self.values["angle"]+math.pi/2.0)[0], Auxiliars.angle_to_vector(self.values["angle"]+math.pi/2.0)[1]]
def get_front(self): return [Auxiliars.angle_to_vector(self.values["angle"])[0], Auxiliars.angle_to_vector(self.values["angle"])[1]]