Вот мой основной код. Idk, как его хорошо отформатировать ...
```
import sys
print(sys.path)
import pygame
import klase
import funkcije
import os
import neat
<p>WIN_W = 800
WIN_H = 400</p>
<p>gen = -1</p>
<p>def main(genomes, config):</p>
<pre><code>global gen
gen += 1
nets = []
ge = []
floor = klase.Floor(0)
dinos = []
cactis = []
for _, g in genomes:
net = neat.nn.FeedForwardNetwork.create(g, config)
nets.append(net)
dinos.append(klase.Dino(-55))
g.fitness = 0
ge.append(g)
clock = pygame.time.Clock()
score = 0
run = True
win = pygame.display.set_mode((WIN_W, WIN_H))
while run:
clock.tick(30)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
pygame.quit()
quit()
cacti_ind = 0
if len(dinos) > 0:
if len(cactis) > 1 and dinos[0].x > cactis[0].x + cactis[0].img.get_width():
cacti_ind = 1
else:
run = False
break
if len(cactis) == 0:
funkcije.spawn_cacti(cactis)
for x, dino in enumerate(dinos):
ge[x].fitness += 0.01
if dino.y < dino.init_y + dino.dy:
ge[x].fitness -= 0.4
try:
next_cacti = cactis[cacti_ind + 1]
except IndexError:
next_cacti = cactis[cacti_ind]
output = nets[x].activate((dino.x, dino.y, abs(dino.x - cactis[cacti_ind].x), abs(dino.x - (cactis[cacti_ind].x + cactis[cacti_ind].img.get_width())), abs(dino.x - next_cacti.x)))
if output[0] > 0.5:
dino.jump()
add_score = False
for cacti in cactis:
for x, dino in enumerate(dinos):
if cacti.collide(dino):
ge[x].fitness -= 1
dinos.pop(x)
nets.pop(x)
ge.pop(x)
if not add_score and cacti.x + cacti.img.get_width() < dino.x:
add_score = True
rem = []
for cacti in cactis:
if cacti.x + cacti.img.get_width() < 0:
rem.append(cacti)
for r in rem:
cactis.remove(r)
if add_score:
score += 1
for g in ge:
g.fitness += 5
add_score = False
funkcije.move(floor, dinos, cactis)
funkcije.draw_window(win, floor, dinos, cactis, score, gen)
def run (config_path): config = neat.config.Config (neat.DefaultGenome, neat.DefaultReproduction, neat.DefaultSpeciesSet, neat.DefaultStagnation , config_path)
p = neat.Population(config)
p.add_reporter(neat.StdOutReporter(True))
stats = neat.StatisticsReporter()
p.add_reporter(stats)
winner = p.run(main, 50)
if name == ' main ': local_dir = os.path.dirname ( file ) config_path = os.path.join (local_dir, 'config-feedforward.txt') запустить (config_path)
</code>
</code>