-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.py
94 lines (77 loc) · 3.45 KB
/
player.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
#player class,
from datetime import datetime
from dist import *
class Player:
def __init__(self, name, age, gender, course, balloons, lossAversion, exp, seenGraphs, time=None):
self.fileName = None
self.name = name
self.age = age
self.gender = gender
self.balloons = balloons #number of balloons, N
self.N = balloons.N
self.dist = balloons.dist
self.pops = balloons.getBallons()
self.course = course
self.actions = [] #stores actions of player over time
self.lossAversion = lossAversion
self.now = time
self.exp=exp
self.folder = "data/exp{}/".format(self.exp)
self.seenGraphs = seenGraphs
self.finalScore = None
self.points = []
def nextBalloon(self, timeStamp, ):
'''update actions'''
def addAir(self, ):
'''update actions'''
def toString(self, ):
pass
def writeData(self):
'''store player data some where so we can retrieve and analyze'''
self.setFileName()
print("WRITING DATA")
print(self.actions)
f = open("{}{}".format(self.folder, self.fileName), "a")
for i in self.actions:
f.write("{} {} {} {} {}\n".format(i[0], i[1], i[2], i[3], i[4]))
f.close()
def writeStringToData(self, string):
self.setFileName()
f = open("{}{}".format(self.folder, self.fileName), "a")
f.write(string)
f.close()
def addActionData(self, index, size, action, time, score):
'index and size of of the balloon -> if we are on the first balloon and its size 3, it would be index 0 size 3, action is either a string of PUMP or PASS, time is the time since the last action (optional)'
'totalPoints is defined in accordance with lossAversion settings (so whatever is on screen)'
self.actions.append([index, size, action, time, score])
def setFileName(self):
now = datetime.now()
self.now = now
if(self.fileName == None):
self.fileName = "{}_{}_{}_{}_{}_{}_{}.txt".format(self.name, self.age, self.gender, self.N, self.course, now.strftime("%Y-%m-%d_%H:%M"), self.balloons.dist.shortString())
def playerinfotostring(self):
return "{} {} {} {} {} {} {} {} {}".format(self.name, self.age, self.gender, self.N, self.course, self.now.strftime("%Y-%m-%d_%H:%M"), self.balloons.dist.shortString(), self.lossAversion, self.seenGraphs)
def playerinfonotime(self):
return "{} {} {} {} {} {} {} lossAverse={} seenGraphs={}".format(self.exp, self.name, self.age, self.gender, self.N, self.course, self.balloons.dist.shortString(), self.lossAversion, self.seenGraphs)
def addDistributionData(self):
self.setFileName()
f = open("{}{}".format(self.folder, self.fileName), "a")
dist = self.balloons.dist
f.write(self.playerinfotostring())
f.write('\n')
for i in self.pops:
f.write("{},".format(i))
f.write("\n")
def __str__(self,):
result = self.balloons.__str__() + "\n" + "{}".format(self.pops) + "\n" + "score: {}".format(self.finalScore)
for i in self.actions:
result += "{}\n".format(i)
return result
def pointPerBalloon(self):
points = [-1] * self.N
for a in self.actions:
for i in range(self.N):
if(a[0] == i):
points[i] = a[-1]
self.points = points
return points