Add fitness counter.
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user