diff --git a/gameobjects.py b/gameobjects.py index 9c24911..c1c003a 100644 --- a/gameobjects.py +++ b/gameobjects.py @@ -46,7 +46,7 @@ class GameObject: self.image.set_colorkey(None) # Explicitly disable colorkey class Horse(GameObject): - default_vacceleration = 0.3 # Default acceleration value + default_vacceleration = 0.2 # Default acceleration value vspeed = 0 # Vertical speed vacceleration = 0 # Vertical acceleration stopped = False # Whether the horse is stopped diff --git a/genetic_alg.py b/genetic_alg.py index 82bc4e0..4ed99f5 100644 --- a/genetic_alg.py +++ b/genetic_alg.py @@ -49,7 +49,7 @@ class GeneticAlgorithm: def mutate(self, model: NeuralNetwork): for param in model.parameters(): if torch.rand(1).item() < self.mutationRate: - param.data += torch.randn_like(param.data) * 0.1 * (1 if torch.rand(1).item() >= 0.5 else -1) + param.data += torch.randn_like(param.data) * 0.1 return model def learn(self, fitness: list): diff --git a/main.py b/main.py index 4163487..6a24934 100644 --- a/main.py +++ b/main.py @@ -3,10 +3,10 @@ import sys from gameobjects import * from genetic_alg import GeneticAlgorithm -POPULATION_SIZE = 50 +POPULATION_SIZE = 100 MUTATION_RATE = 0.5 POPULATION_NEW = 0.1 -POPULATION_BEST = 0.2 +POPULATION_BEST = 0.3 FRAME_RATE = 160 # TODO: FIX THE INCORRECT FRAME RATE CORRELATION BARRIER_SPEED = 10 BARRIER_DELAY = 100 @@ -60,12 +60,12 @@ def init_game(): UI.add_horses(horses) -def get_features(horse): +def get_features(horse: Horse): features = [last_barrier.rect.topleft[0], last_barrier.rect.topleft[1], 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], - 0, HEIGHT, BARRIER_SPEED] + 0, HEIGHT, horse.vspeed, horse.vacceleration, BARRIER_SPEED] return features