-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshow_game.py
112 lines (84 loc) · 2.29 KB
/
show_game.py
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import turtle
import random
import torch
import show_classes as c
import numpy as np
import copy
import time
def main(nBalls,kBalls, time_limit, limit, jump):
start=time.time()
delay = 1/30
window = turtle.Screen()
window.title("game")
window.bgcolor("black")
window.setup(width=800,height=600)
window.tracer(0)
Pipes = []
Balls = kBalls
window.listen()
#window.onkeypress(Balls[0].Up,"w")
count = 0
Pipes.append(c.Pipe(50,-300))
Game = True
while Game == True:
now = time.time()
if now-start>time_limit:
Game = False
time.sleep(delay)
window.update()
counter = 0
for i in Balls:
closet_pipe = Pipes[0]
if Pipes[0].getx()< -300:
closet_pipe = Pipes[1]
i.check_for_hit(Pipes[0])
i.move()
r = i.gety()
f = i.gety()-(closet_pipe.y1)
g = i.gety()-(closet_pipe.y2)
h = closet_pipe.getx()
j = closet_pipe.velocity
k = i.velocity
input=torch.tensor([r,f,g,h,j,k]).double()
'''
v1 = Ball.y
v2 = Ball.y-(closest_pipe.y1)
v3 = Ball.y-(closest_pipe.y2)
v4 = closest_pipe.x
v5 = closest_pipe.v
v6 = Ball.v
'''
if count%1==0:
a = i.brain_prediction(input)
if a<0.5:
i.velocity -= jump
if i.alive == True:
i.score = count
#if i.gety()<-300:
# i.sety(-290)
if limit == True:
if i.gety()>300:
i.sety(300)
i.velocity = 8
if i.alive == False:
counter +=1
i.update_color()
if counter == nBalls:
Game = False
if count % 70 == 0:
Pipes.append(c.Pipe(400,-300))
for i in Pipes:
i.move()
if i.getx() < -400:
i.pipe.reset()
i.pipe1.reset()
del i
del Pipes[0]
count = count+1
for i in Balls:
i.ball.reset()
del i
del Balls
window.clear()
window.bye()
return True