-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnew.py
49 lines (37 loc) · 1.15 KB
/
new.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
from otree.api import (
models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer,
Currency as c, currency_range
)
import random
class Player(BasePlayer):
cooperate = models.BooleanField(
choices=[
[False, 'Defect'],
[True, 'Cooperate']
]
)
player_name = models.StringField(label="Please type in your name.")
def decision_label(self):
if self.cooperate:
return 'cooperate'
return 'defect'
def other_player(self):
return self.get_others_in_group()[0]
def set_payoff(self):
payoff_matrix = {
True:
{
True: Constants.both_cooperate_payoff,
False: Constants.betrayed_payoff
},
False:
{
True: Constants.betray_payoff,
False: Constants.both_defect_payoff
}
}
print ("Hey I'm here")
print (self.decision_label())
self.payoff = payoff_matrix[self.cooperate][self.other_player().cooperate]
player = Player()
print (player.cooperate)