-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpredictor.py
More file actions
31 lines (23 loc) · 819 Bytes
/
predictor.py
File metadata and controls
31 lines (23 loc) · 819 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
import common as c
class Predictor:
def __init__(self):
self.data = []
self.last_pred = c.WIN_X
self.pred = 0
def simple_predict(self, data, scale=3000):
arr = max(data)
pred_paddle_pos = ((sum(arr[:])/scale) * c.WIN_X) - c.PADDLE_X
# Stop small gitters
if ( abs(pred_paddle_pos-self.last_pred) /c.WIN_X > 0.03 ):
# We have made a big change, so its worth updating the position
self.pred = pred_paddle_pos
self.last_pred = pred_paddle_pos
return self.pred
def predict(self, left_data, right_data):
pred_paddle_pos = c.WIN_X * max(right_data)/800
# Stop small gitters
if ( abs(pred_paddle_pos-self.last_pred)/c.WIN_X > 0.1 ):
# We have made a big change, so its worth updating the position
self.pred = pred_paddle_pos
self.last_pred = pred_paddle_pos
return self.pred