-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
71 lines (48 loc) · 1.47 KB
/
main.py
File metadata and controls
71 lines (48 loc) · 1.47 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import random
import pygame
import Evolution
pygame.init()
window_w = 1600
window_h = 800
black = (0, 0, 0)
white = (255, 255, 255)
FPS = 120
window = pygame.display.set_mode((window_w, window_h))
pygame.display.set_caption("Generation Learning")
clock = pygame.time.Clock()
number_of_balls = 1000
starting_moves = 500
min_max_velocity = 2
target = [random.randrange(window_w), random.randrange(window_h)]
# target = [0, 0]
generation_saved = 20
best_parent_saved = 10
mutation_rate = 10
starting_x = window_w / 2
starting_y = window_h / 2
# starting_x = 0
# starting_y = 0
def game_loop():
hidden = False
running = True
evolution = Evolution.Evolution(starting_moves, number_of_balls, [starting_x, starting_y], window_w, window_h,
window, target,
generation_saved, best_parent_saved, mutation_rate, min_max_velocity)
while running:
freeze = False
keys = pygame.key.get_pressed()
if keys[pygame.K_SPACE]:
freeze = True
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_r:
if not hidden:
hidden = True
else:
hidden = False
evolution.Step(freeze, hidden)
clock.tick(FPS)
game_loop()