Exemplo n.º 1
0
 def __init__(self,
              size=50,
              width=600,
              height=600,
              graphics=True,
              brain=None):
     self.size = size
     self.rotation_angle = 0
     self.x, self.y = width / 2, height / 2
     vertices = [(0.5, 0), (-0.25, -0.25), (-0.25, 0.25)]
     #convert x-y vertices to polar
     self.points = [pc.to_polar(v) for v in vertices]
     #scale up ship by self.size
     self.points = [[self.size * r, theta] for [r, theta] in self.points]
     self.color = GREEN
     self.score = 0  #game score
     self.alive = True
     self.life = 0  #number of frames survived
     self.dpoints = [0] * 8  #points for testing distance measurements
     self.create_asteroids = False
     self.shoot_bullet = False  #True when key pressed or AI chooses
     self.createBullet = True  #Off when bullet has been created, creates delay
     self.bullet_wait = 0
     self.graphics = graphics
     self.fitness = 0
     #for neural net
     if brain:
         self.brain = brain.replicate()
     else:
         self.brain = nn.NeuralNetwork(8, 12, 3, 0.3)
     self.inputs = [0] * 5
     self.output = numpy.zeros(3)
Exemplo n.º 2
0
 def __init__(self,size=50,width=600,height=600,graphics=True):
     self.bullets = []
     self.asteroid_count = 30
     self.asteroids = []
     self.size = size
     self.rotation_angle = 0
     self.x, self.y = width / 2, height / 2
     vertices = [(0.5,0),(-0.25,-0.25),(-0.25,0.25)]
     #convert x-y vertices to polar
     self.points = [pc.to_polar(v) for v in vertices]
     #scale up ship by self.size
     self.points = [[self.size*r,theta] for [r,theta] in self.points]
     self.color = GREEN
     self.score = 0 #game score
     self.alive = True
     self.life = 0 #number of frames survived
     self.dpoints = [0]*8 #[[0,0,0]] * 8 #points for testing distance measurements
     self.create_asteroids = False
     self.shoot_bullet = False #True when key pressed or AI chooses
     self.createBullet = True #Off when bullet has been created, creates delay
     self.bullet_wait = 0
     self.graphics = graphics
     self.fitness = 0
     #for neural net
     self.brain = NeuralNet(8, 12,12, 3)
     self.inputs = torch.zeros(8)
     self.output = torch.zeros(3)
     #for tracking improvements
     self.mutated = 0
     self.crossovers = 0
Exemplo n.º 3
0
 def __init__(self,size,width,height,graphics):
     self.size = size
     self.rotation_angle = 0
     self.x, self.y = width / 2, height / 2
     vertices = [(0.5,0),(-0.25,-0.25),(-0.25,0.25)]
     #convert x-y vertices to polar
     self.points = [pc.to_polar(v) for v in vertices]
     #scale up ship by self.size
     self.points = [[self.size*r,theta] for [r,theta] in self.points]
     self.color = GREEN
     self.score = 0
     self.lives = 3
     self.dpoints = [] #points for testing distance measurements
     self.create_asteroids = False
     self.graphics = graphics