diff --git a/gameobjects.py b/gameobjects.py index 3d18860..36c8179 100644 --- a/gameobjects.py +++ b/gameobjects.py @@ -65,6 +65,7 @@ class Horse(GameObject): self.vspeed = 0 self.vacceleration = 0 self.stopped = False + self.fitness = 0 self.color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) # Random color for the mark self.ribbon_fill = GameObject("images/Ribbon_fill.png", self.x, self.y, (16, -1)) self.ribbon_fill.recolor(self.color) @@ -102,6 +103,9 @@ class Horse(GameObject): self.frame_counter = 0 self.current_frame = (self.current_frame + 1) % len(self.images) self.image = self.images[self.current_frame] + def count_fitness(self): + if self.stopped == False: + self.fitness += 1 class Background(GameObject): def __init__(self, image_path, x, y): diff --git a/main.py b/main.py index 8e71d87..a354162 100644 --- a/main.py +++ b/main.py @@ -42,7 +42,7 @@ def get_features(horse): last_barrier.rect.bottomright[0], last_barrier.rect.bottomright[1], horse.rect.topleft[0], horse.rect.topleft[1], horse.rect.bottomright[0], horse.rect.bottomright[1], - HEIGHT, BARRIER_SPEED] + HEIGHT, BARRIER_SPEED, 0] return features genecticAlg = GeneticAlgorithm(POPULATION_SIZE, MUTATION_RATE, POPULATION_BEST) @@ -89,6 +89,7 @@ while True: horse.stop() # Stop the horse if horse.rect.colliderect(upper_bound_rect) or horse.rect.colliderect(lower_bound_rect): horse.stop() + horse.count_fitness for object in gameobjects: