random mutation + added flower value to Field.py

This commit is contained in:
yanny 2023-06-18 16:07:03 +02:00
parent 4946a7a15e
commit 22bbc8d0f7
2 changed files with 6 additions and 3 deletions

View File

@ -84,5 +84,6 @@ TREE = 100
SHORT_VALUE = 1
TALL_VALUE = 100
TREE_VALUE = 100
TREE_VALUE = 200
FLOWER_VALUE = 1

View File

@ -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()