From 22bbc8d0f7b5a4805fecba1f953224ab75bf7b42 Mon Sep 17 00:00:00 2001 From: yanny Date: Sun, 18 Jun 2023 16:07:03 +0200 Subject: [PATCH] random mutation + added flower value to Field.py --- src/Field.py | 3 ++- src/GeneticAlgorithm.py | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Field.py b/src/Field.py index 89735257..65096105 100644 --- a/src/Field.py +++ b/src/Field.py @@ -84,5 +84,6 @@ TREE = 100 SHORT_VALUE = 1 TALL_VALUE = 100 -TREE_VALUE = 100 +TREE_VALUE = 200 +FLOWER_VALUE = 1 diff --git a/src/GeneticAlgorithm.py b/src/GeneticAlgorithm.py index d17d3c95..e2d491ec 100644 --- a/src/GeneticAlgorithm.py +++ b/src/GeneticAlgorithm.py @@ -154,8 +154,10 @@ class GA: def perform_mutation(self, individual): # Perform mutation operation on the individual index1 = random.randint(0, num_of_trees - 1) - index2 = random.randint(0, num_of_trees - 1) - individual.genes[index1], individual.genes[index2] = individual.genes[index2], individual.genes[index1] + new_x = random.randint(0, tilemapSizeX-1) + new_y = random.randint(0,tilemapSizeY) + if (new_x,new_y) not in individual.genes: + individual.genes[index1] = (new_x,new_y) def run(self): self.initialize_population()