random mutation + added flower value to Field.py
This commit is contained in:
parent
4946a7a15e
commit
22bbc8d0f7
@ -84,5 +84,6 @@ TREE = 100
|
|||||||
|
|
||||||
SHORT_VALUE = 1
|
SHORT_VALUE = 1
|
||||||
TALL_VALUE = 100
|
TALL_VALUE = 100
|
||||||
TREE_VALUE = 100
|
TREE_VALUE = 200
|
||||||
|
FLOWER_VALUE = 1
|
||||||
|
|
||||||
|
@ -154,8 +154,10 @@ class GA:
|
|||||||
def perform_mutation(self, individual):
|
def perform_mutation(self, individual):
|
||||||
# Perform mutation operation on the individual
|
# Perform mutation operation on the individual
|
||||||
index1 = random.randint(0, num_of_trees - 1)
|
index1 = random.randint(0, num_of_trees - 1)
|
||||||
index2 = random.randint(0, num_of_trees - 1)
|
new_x = random.randint(0, tilemapSizeX-1)
|
||||||
individual.genes[index1], individual.genes[index2] = individual.genes[index2], individual.genes[index1]
|
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):
|
def run(self):
|
||||||
self.initialize_population()
|
self.initialize_population()
|
||||||
|
Loading…
Reference in New Issue
Block a user