-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeneticAlgorithm.py
More file actions
48 lines (31 loc) · 844 Bytes
/
geneticAlgorithm.py
File metadata and controls
48 lines (31 loc) · 844 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from Classes.Snake import *
from Classes.Food import *
import random
""""
- fitness function
- breeding function
- mutation function
- child maker
"""
"""
Given a snake and food, calculates a fitness function
"""
def fitness(snake, food, boarder):
fitness = 0
if pygame.sprite.collide_rect(snake[0], food):
fitness += 5000
for i in range(len(boarder)):
if pygame.sprite.collide_rect(snake[0], boarder[i]):
fitness -= 150
for i in range(1, len(snake)):
if pygame.sprite.collide_rect(snake[0], snake[1]):
fitness -= 150
if pygame.sprite.collide_rect(snake[0], snake[i]):
fitness -= 150
return fitness
def generateSingleChild():
pass
def generatePopulation(populationSize):
pass
def breed(child1, child2):
pass