-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprisonersDilemmaBaseStructure.boxs
215 lines (192 loc) · 6.82 KB
/
prisonersDilemmaBaseStructure.boxs
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
// set the number of games - ATTENTION: this variable (including 'i') will not be seen inside
games = 3
// play the game
for (i=1; i<=games; i=i+1)
{
// we can only play within the matching environment
matchStranger(A,B)
// update gameCounter to detect last round (because 'i' is not available inside the matching environment)
gameCounter = gameCounter + 1
// initialize variables in the very first round
if (firstGame==0)
{
display("This is the beginning of the game")
display("Some instructions here")
// firstGame is a boolean that we need to enter this if block only once
firstGame = 1
// set # of rounds per game
rounds = 1
// first game will be set here, updating will take place above
gameCounter = 1
// new style for tables
style("body{ padding: 0px; font-size: 12px; } h1{font-size: 130%; margin-top: 0px; margin-bottom: 3px; font-weight: normal;} h2{font-size: 115%; margin-top: 0px; margin-bottom: 3px; font-weight: normal; } table{border-collapse:collapse;} th{text-align:center; background:#fff4c6; color:#333; padding:8px 16px 8px 8px; border-right:1px solid #fff; border-bottom:1px solid #fff;} td{text-align:center; color:#333; padding:8px; border-right:1px solid #f3f0e4; border-bottom:1px solid #f3f0e4;}")
// C D
// _______ _______
// | | |
// C |200/200| 50/300|
// |_______|_______|
// | | |
// D |300/50 |100/100|
// |_______|_______|
// WinMatrix[Zeile][Spalte][Spieler]
WinMatrix[0][0][0] = 200
WinMatrix[0][0][1] = 200
WinMatrix[0][1][0] = 50
WinMatrix[0][1][1] = 300
WinMatrix[1][0][0] = 300
WinMatrix[1][0][1] = 50
WinMatrix[1][1][0] = 100
WinMatrix[1][1][1] = 100
// we save all data in an array corresponding to our vpnumbers
// vp[vpnumber][datafield][roundnumber]
// -- where vpnumber is in {1..12},
// datafield{1-choice, 2-win, 3-totalwin (without roundnumber)} and
// roundnumer {1..rounds}
*.*.vp[0][0][0] = 0
// welcome screen
display("<h1>Willkommen beim Experiment</h1>")
display("Warten Sie auf die Instruktionen der Versuchsleiter ")
inputNumber(checkExperimenter)
assert(checkExperimenter == 222)
wait()
}
// here takes place the game
for(j=1; j<=rounds; j=j+1)
{
// first round
if(j==1)
{
// do some stuff in the first round
display("Dies ist die erste Runde im " + gameCounter + ". Spiel")
display("HIER SOLLTEN INSTRUKTIONEN FÜR DIE ERSTE RUNDE EINES NEUEN SPIELS STEHEN")
wait()
//VPN Code
display("Bitte geben Sie nun Ihre VP-Nummer ein:")
inputString(vpnumber)
// start the eyetracker
if (username == "S1")
{
// init eyetracker
eyetrackerInitialise("localhost",4444,5555)
display("Mit weiter gelangen Sie zur Kalibrierung")
wait()
display("<h1>Bitte bewegen Sie sich nun nicht mehr und verfolgen Sie bitte die erscheinenden Punkte</h1>")
wait()
// calibrate eyetracker and start tracking
eyetrackerCalibrate()
display("Danke - Die Kalibrierung war erfolgreich")
filename = "PrisonersDilemma_" + vpnumber + ".dat"
eyetrackerStart(60,filename)
// send trigger
eyetrackerTrigger("Calibration Done")
}
// only a normal wait - we don't need to hold on the fast players
wait()
}
// presenting the matrix and options
table = "<table>"
table = table + " <thead>"
table = table + " <tr>"
table = table + " <th> </th>"
table = table + " <th>cooperate</th>"
table = table + " <th>defect</th>"
table = table + " </tr>"
table = table + " </thead>"
table = table + " <tbody>"
table = table + " <tr>"
table = table + " <th>cooperate</th>"
table = table + " <td>" + winmatrix[0][0][0] + " / " + winmatrix[0][0][1] + "</td>"
table = table + " <td>" + winmatrix[0][1][0] + " / " + winmatrix[0][1][1] + "</td>"
table = table + " </tr>"
table = table + " <tr>"
table = table + " <th>defect</th>"
table = table + " <td>" + winmatrix[1][0][0] + " / " + winmatrix[1][0][1] + "</td>"
table = table + " <td>" + winmatrix[1][1][0] + " / " + winmatrix[1][1][1] + "</td>"
table = table + " </tr>"
table = table + " <tr>"
table = table + " </tbody>"
table = table + "</table>"
display(table)
choice(action,"cooperate", "defect")
waitForPlayers("weiter") // we need to calculate the payoffs here -> so wait for the opponent
// calculate Payoff
if (A.action == "Cooperate")
{
if(B.action == "Cooperate")
{
A.win = WinMatrix[0][0][0]
B.win = WinMatrix[0][0][1]
}
if(B.action == "Defect")
{
A.win = WinMatrix[0][1][0]
B.win = WinMatrix[0][1][1]
}
}
if (A.action == "Defect")
{
if(B.action == "Cooperate")
{
A.win = WinMatrix[1][0][0]
B.win = WinMatrix[1][0][1]
}
if(B.action == "Defect")
{
A.win = WinMatrix[1][1][0]
B.win = WinMatrix[1][1][1]
}
}
// present actions and payoff
display("Sie haben '" + action + "' gewählt" )
if (role == "B")
{
display("Ihr Gegener hat '" + A.action + "' gewählt" )
}
if (role == "A")
{
display("Ihr Gegener hat '" + B.action + "' gewählt" )
}
display("Ihr Rundengewinn beträgt somit " + win)
// save win and actions into the global array 'vp'
if (vpnumber % 100 == 1)
{
*.*.vp[1][1][j+gameCounter-1] = action
*.*.vp[1][2][j+gameCounter-1] = win
// in the first round of the first game, there was no win before
if(j==1 && gameCounter == 1)
{
*.*.vp[1][3][j+gameCounter-1] = win
}
if (j>1 || gameCounter > 1)
{
*.*.vp[1][3][j+gameCounter-1] = vp[1][3][j+gameCounter-2] + win
}
}
// next round can start without waiting for the opponent
wait()
// last round
if (j==rounds)
{
display("This was the last Round of the " + gameCounter + ". game")
display("Presenting information of this game")
// stop the eyetracker
if (username=="S1")
{
display("Stop Eyetracker")
eyetrackerStop()
}
wait()
}
}
// end of game ATTENTION: HARD CODED NUMBER!!!!!!!!
if (gameCounter == 10)
{
display("<h1>Das Experiment ist nun beendet. Bitte klicken Sie weiter um die Auszahlung anzuzeigen</h1>")
wait()
display("Sie haben insgesamt folgende Anzahl an Talern verdient: " + totalwin)
display("Dies entspricht einem Betrag von: " + totalwin / 200)
display("<br><br> Bitte verständigen Sie nun die Versuchsleitung per Handzeichen")
waitForPlayers("Beenden")
}
matchDone()
}