问题描述
嗨,我在python中使用整洁的模块制作了一只飞扬的小鸟AI,但AI的表现很怪异。 一半的鸟只飞起来,另一半什么也不做,直接掉下来。
def main(genomes,config):
nets = []
birds = []
ge = []
for _,genome in genomes:
genome.fitness = 0
net = neat.nn.FeedForwardNetwork.create(genome,config)
nets.append(net)
birds.append(Bird(50,WIDTH/2))
ge.append(genome)
floor = Floor()
pipes = [Pipe(WIDTH)]
score = 0
clock = pygame.time.Clock()
run = True
while run and len(birds):
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
pygame.quit()
sys.exit()
break
if event.type == Bird.BIRDFLAP:
for bird in birds:
bird.animate()
pipeIndex = 0
if len(birds):
if len(pipes) > 1 and birds[0].x > pipes[0].x + pipeWidth:
pipeIndex = 1
for i,bird in enumerate(birds):
genomes[i][1].fitness += 0.03
bird.move()
topPipedist = abs(bird.y - pipes[pipeIndex].topPipeY)
bottomPipedist = abs(bird.y - pipes[pipeIndex].bottomPipeY)
output = nets[i].activate((bird.y,topPipedist,bottomPipedist))
if output[0] > 0.5:
bird.jump()
floor.move()
rem = []
addPipe = False
for pipe in pipes:
pipe.move()
for bird in birds:
if bird.collide(pipe):
birdindex = birds.index(bird)
genomes[birdindex][1].fitness -= 1
nets.pop(birdindex)
ge.pop(birdindex)
birds.pop(birdindex)
if pipe.x + pipeWidth < 0:
rem.append(pipe)
if not pipe.passed and pipe.x < bird.x:
pipe.passed = True
addPipe = True
if addPipe:
score += 1
for i in range(len(ge)):
genomes[i][1].fitness += 5
pipes.append(Pipe(WIDTH))
for r in rem:
pipes.remove(r)
for bird in birds:
if bird.boundary():
birdindex = birds.index(bird)
nets.pop(birdindex)
ge.pop(birdindex)
birds.pop(birdindex)
screen.blit(bgSurface,(0,0))
for pipe in pipes:
pipe.draw(screen)
floor.draw(screen)
for bird in birds:
bird.draw(screen)
scoreText = FONT.render(f'score: {score}',1,(255,255,255))
screen.blit(scoreText,0))
pygame.display.flip()
clock.tick(100)
https://github.com/arduino-monkey/flappy-bird-NEAT
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)