Update main.py
This commit is contained in:
@@ -7,8 +7,6 @@ POPULATION_SIZE = 20
|
|||||||
MUTATION_RATE = 0.5
|
MUTATION_RATE = 0.5
|
||||||
POPULATION_BEST = 0.2
|
POPULATION_BEST = 0.2
|
||||||
FRAME_RATE = 160 #TODO: FIX THE INCORRECT FRAME RATE CORRELATION
|
FRAME_RATE = 160 #TODO: FIX THE INCORRECT FRAME RATE CORRELATION
|
||||||
BARRIER_SPEED = 10
|
|
||||||
BARRIER_DELAY = 75
|
|
||||||
|
|
||||||
pygame.init()
|
pygame.init()
|
||||||
|
|
||||||
@@ -34,11 +32,8 @@ def init_game():
|
|||||||
grass = Background("images/Grass.jpg", 0, 0)
|
grass = Background("images/Grass.jpg", 0, 0)
|
||||||
grass.set_size(WIDTH, HEIGHT)
|
grass.set_size(WIDTH, HEIGHT)
|
||||||
|
|
||||||
<<<<<<< Updated upstream
|
|
||||||
=======
|
|
||||||
BARRIER_SPEED = 25
|
BARRIER_SPEED = 25
|
||||||
|
|
||||||
>>>>>>> Stashed changes
|
|
||||||
gameobjects = []
|
gameobjects = []
|
||||||
|
|
||||||
barriers = []
|
barriers = []
|
||||||
@@ -51,7 +46,7 @@ def init_game():
|
|||||||
horse.set_vspeed(0)
|
horse.set_vspeed(0)
|
||||||
horse.frame_counter = 0
|
horse.frame_counter = 0
|
||||||
horse.fitness = 0
|
horse.fitness = 0
|
||||||
spawner = Spawner("images/Barrier.png", BARRIER_DELAY)
|
spawner = Spawner("images/Barrier.png", 125)
|
||||||
new_barrier = spawner.spawn()
|
new_barrier = spawner.spawn()
|
||||||
barriers.append(new_barrier)
|
barriers.append(new_barrier)
|
||||||
gameobjects.extend(horses)
|
gameobjects.extend(horses)
|
||||||
@@ -70,12 +65,12 @@ def get_features(horse):
|
|||||||
last_barrier.rect.bottomright[0], last_barrier.rect.bottomright[1],
|
last_barrier.rect.bottomright[0], last_barrier.rect.bottomright[1],
|
||||||
horse.rect.topleft[0], horse.rect.topleft[1],
|
horse.rect.topleft[0], horse.rect.topleft[1],
|
||||||
horse.rect.bottomright[0], horse.rect.bottomright[1],
|
horse.rect.bottomright[0], horse.rect.bottomright[1],
|
||||||
0, HEIGHT, BARRIER_SPEED]
|
HEIGHT, BARRIER_SPEED]
|
||||||
return features
|
return features
|
||||||
|
|
||||||
|
genecticAlg = GeneticAlgorithm(POPULATION_SIZE, MUTATION_RATE, POPULATION_BEST, 10)
|
||||||
horses = [Horse("images/Horse_1.png", 50, HEIGHT/2 + 0 * i) for i in range(POPULATION_SIZE)]
|
horses = [Horse("images/Horse_1.png", 50, HEIGHT/2 + 0 * i) for i in range(POPULATION_SIZE)]
|
||||||
init_game()
|
init_game()
|
||||||
genecticAlg = GeneticAlgorithm(POPULATION_SIZE, MUTATION_RATE, POPULATION_BEST, len(get_features(horses[0])))
|
|
||||||
while True:
|
while True:
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT: # Handle window close event
|
if event.type == pygame.QUIT: # Handle window close event
|
||||||
@@ -120,6 +115,7 @@ while True:
|
|||||||
if horse.rect.colliderect(upper_bound_rect) or horse.rect.colliderect(lower_bound_rect):
|
if horse.rect.colliderect(upper_bound_rect) or horse.rect.colliderect(lower_bound_rect):
|
||||||
horse.stop()
|
horse.stop()
|
||||||
horse.count_fitness()
|
horse.count_fitness()
|
||||||
|
print(str(horse.color) + ' ' + str(horse.fitness))
|
||||||
|
|
||||||
|
|
||||||
for object in gameobjects:
|
for object in gameobjects:
|
||||||
|
|||||||
Reference in New Issue
Block a user