blacked all
This commit is contained in:
32
main.py
32
main.py
@@ -10,15 +10,13 @@ from maps import map1
|
||||
from params import CELL_COLOR, screen
|
||||
|
||||
|
||||
|
||||
#https://medium.com/intel-student-ambassadors/demystifying-genetic-algorithms-to-enhance-neural-networks-cde902384b6e
|
||||
# https://medium.com/intel-student-ambassadors/demystifying-genetic-algorithms-to-enhance-neural-networks-cde902384b6e
|
||||
clock = pygame.time.Clock()
|
||||
|
||||
|
||||
map_lines = map1
|
||||
|
||||
|
||||
|
||||
all_cars = pygame.sprite.Group()
|
||||
|
||||
for x in range(100):
|
||||
@@ -28,47 +26,47 @@ for x in range(100):
|
||||
|
||||
def run_round(all_cars):
|
||||
running_cars = True
|
||||
while running_cars :
|
||||
while running_cars:
|
||||
running_cars = False
|
||||
screen.fill(CELL_COLOR)
|
||||
all_cars.draw(screen)
|
||||
for c in all_cars :
|
||||
for c in all_cars:
|
||||
c.show_features()
|
||||
if c.run :
|
||||
if c.run:
|
||||
running_cars = True
|
||||
c.probe_lines_proximity(map_lines)
|
||||
c.probe_brain()
|
||||
c.update()
|
||||
|
||||
for line in map_lines :
|
||||
pygame.draw.line(screen, (255,255,255), line[0], line[1])
|
||||
for line in map_lines:
|
||||
pygame.draw.line(screen, (255, 255, 255), line[0], line[1])
|
||||
|
||||
pygame.display.flip()
|
||||
clock.tick(48)
|
||||
|
||||
# for c in all_cars :
|
||||
# print(f"Car {id(c)} Fitness : {c.brain.fitness})")
|
||||
|
||||
print('Collecting brains')
|
||||
|
||||
print("Collecting brains")
|
||||
brains = [c.brain for c in all_cars]
|
||||
print(f"Max fitness = {max([b.fitness for b in brains])}" )
|
||||
print(f"Avg fitness = {sum([b.fitness for b in brains])/len(brains)}" )
|
||||
print('selecting')
|
||||
print(f"Max fitness = {max([b.fitness for b in brains])}")
|
||||
print(f"Avg fitness = {sum([b.fitness for b in brains])/len(brains)}")
|
||||
print("selecting")
|
||||
parents_pool = genetic_selection(brains)
|
||||
# import ipdb; ipdb.set_trace()
|
||||
print("breeding")
|
||||
new_brains = genetic_reproduction(parents_pool)
|
||||
print(f'building {len(new_brains)} cars with new brains')
|
||||
print(f"building {len(new_brains)} cars with new brains")
|
||||
all_cars.empty()
|
||||
for b in new_brains :
|
||||
for b in new_brains:
|
||||
all_cars.add(Car(brain=b))
|
||||
print("Waiting before new run")
|
||||
for x in range(1) :
|
||||
for x in range(1):
|
||||
time.sleep(0.5)
|
||||
pygame.display.flip()
|
||||
|
||||
|
||||
while True :
|
||||
while True:
|
||||
run_round(all_cars)
|
||||
pygame.display.flip()
|
||||
clock.tick(24)
|
||||
|
||||
Reference in New Issue
Block a user