Skip to content

Commit

Permalink
Merge branch 'master' of github.com:jcxl/flock_game
Browse files Browse the repository at this point in the history
  • Loading branch information
jxcl committed Nov 9, 2013
2 parents 4251750 + a8e2863 commit 83f54fa
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions GeneticAlgorithm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import math
import random

MUTATION_CHANCE = 0.5
def select_parent(survivor_hash):
selection_list = []
key_list = survivor_hash.keys()

for x in key_list:
i = 0
while survivor_hash[x] > i:
selection_list.append(survivor_hash[x])
i += 1

index = random.randint(0, len(selection_list))
return selection_list(index)

def mutate_parent(parent_weights):
new_weights = []

for w in parent_weights:
if random.random() > MUTATION_CHANCE:
w = random.gauss(w,w * .1)
new_weights.append(w)
else:
new_weights.append(w)

return new_weights.reverse()


0 comments on commit 83f54fa

Please sign in to comment.