-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBrain.py
More file actions
29 lines (25 loc) · 888 Bytes
/
Brain.py
File metadata and controls
29 lines (25 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#imports
import random
import math
import Direction_Vector as DV
import copy
class brain:
def __init__(self):
self.direction_length = 250
self.brain_step = 0
self.directions = []
self.randomize()
def randomize(self):
for i in range(self.direction_length):
rand_angle = (random.randint(0,359)*math.pi)/180
self.directions.append(DV.vector(0, 0))
self.directions[i].from_angle(rand_angle)
def clone(self, parent):
self.directions = copy.deepcopy(parent.brain.directions)
def mutate(self, gen):
mutation_rate = 0.01/(0.5 *gen)
for i in range(self.direction_length):
rand = random.uniform(0, 1)
if rand <= mutation_rate:
rand_angle = (random.randint(0,359)*math.pi)/180
self.directions[i].from_angle(rand_angle)