-
Notifications
You must be signed in to change notification settings - Fork 2
/
regretpriming.m~
222 lines (181 loc) · 9.29 KB
/
regretpriming.m~
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
214
215
216
217
218
219
220
221
222
clear all;
sca;
close all;
clearvars;
%% Setup
% addpath(matlabroot,'REGRET_task');
% addpath(matlabroot,'patentTaskBTMP');
% addpath(matlabroot,'ratingslider');
% addpath(matlabroot,'games');
% addpath(matlabroot,'games/stimoli');
% addpath('REGRET_task');
% addpath('patentTaskBTMP');
% addpath('ratingslider');
% addpath('games');
% addpath('games/stimoli');
addpath('REGRET_task', 'patentTaskBTMP', 'ratingslider', 'instructions', 'games', 'games/stimoli');
KbName('UnifyKeyNames');
showUp = 5; % fee for coming to the experiment; base payment amount
%% VARIABLES
player1maxbid=5; % Patent Race Role
gamestrials = 12; % Trials for 2x2 games
prtrials = 10; % Trials for Patent Race
DateTime=datestr(now,'ddmm-HHMM'); % Get date and time for log file
%% check what OS the software is running on; limit keyboard/mouse input
if ismac
% Code to run on Mac plaform
disp('Mac');
disabledKeys=[];
skipSyncTest=[];
screenRes=[];
enabledKeys = RestrictKeysForKbCheck([30, 44, 79, 80, 81,82]); % limit recognized presses to 1!, space, left, right, up, down arrows MAC
% enabledKeys = RestrictKeysForKbCheck([]); % for debugging
elseif isunix
% Code to run on Linux plaform
disp('Unix');
elseif ispc
% Code to run on Windows platform
disp('PC');
enabledKeys = RestrictKeysForKbCheck([37,38,39,40,32,49]); % limit recognized presses to 1!, space, left, right, up, down arrows PC
else
disp('Platform not supported')
end
% Hide cursor, stop input in command screen
% uncomment INLAB
HideCursor;
ListenChar(2); %disable transmission of keypresses to Matlab command window; press CTRL+C to reenable
%% Psychtoolbox setup
PsychDefaultSetup(2);
% Screen('Preference', 'SkipSyncTests', 1); %Uncomment INLAB
% Get the screen numbers
screens = Screen('Screens');
% Draw to the external screen if avaliable
% screenNumber = max(screens);
screenNumber = 0;
white = WhiteIndex(screenNumber);
black = BlackIndex(screenNumber);
% Open an on screen window
% [window, windowRect] = PsychImaging('OpenWindow', screenNumber, white, [0 0 640 480]); % for one screen setup
[window, windowRect] = PsychImaging('OpenWindow', screenNumber, white); % for two-screen setup
[xCenter, yCenter] = RectCenter(windowRect);
%% Creat cfg structure to be passed into subsequent functions
[screenXpixels, screenYpixels] = Screen('WindowSize', window);
cfg.screenSize.x = screenXpixels;
cfg.screenSize.y = screenYpixels;
cfg.font = 'Courier New';
cfg.fontSize = round(screenYpixels * 2/40);
% Colors
cfg.textColor = [0, 0, 0]; % black
% cfg.bgColor = [255, 255, 255];
cfg.bgColor = [1, 1, 1]; % white
cfg.instColA = [0, 0.4078, 0.5451]; %DeepSkyBlue4
cfg.instColB = [0.8039, 0.5843, 0.0471]; %DarkGoldenRod3
cfg.p1Col = [0, 0, 0.8039]; %MediumBlue
cfg.p2Col = [0.4314, 0.4824, 0.5451]; % LightSteelBlue4
cfg.winCol = [.1333, .5451, .1333]; %ForestGreen
% Positions
cfg.screenCenter = [xCenter, yCenter]; % center coordinatesf
cfg.topTextYpos = screenYpixels * 2/40; % Screen Y positions of top/instruction text
cfg.botTextYpos = screenYpixels * 35/40; % Screen Y positions of bottom/result text
cfg.waitTextYpos = screenYpixels * 38/40; % Y position of lowest "Please Wait" text
%% Screen 0: Participant number entry
Screen('TextFont', window, cfg.font);
Screen('TextSize', window, cfg.fontSize);
Screen('TextStyle', window);
Screen('TextColor', window, cfg.textColor);
inputReq1 = 'Tasti il numero sopra il tuo computer come due cifre \n e premi ''Enter'': '; % ITALIAN
fail1='Si prega tastere esattamente due cifre \n e premi ''Enter'': '; % ITALIAN
inputReq2 = 'Tasti il dato come e'' scritto su lavagna \n e premi ''Enter'': '; % ITALIAN
fail2='Si prega tastere quattro numeri \n e premi ''Enter'': '; % ITALIAN
[nx, ny1, textRect1]=DrawFormattedText(window, inputReq1, 0, 0, cfg.bgColor); % draws a dummy version of text just to get measurements
[nx, ny2, textRect2]=DrawFormattedText(window, inputReq2, 0, ny1, cfg.bgColor); % draws a dummy version of text just to get measurements
textWidth1 = textRect1(3)-textRect1(1); % figures width of bounding rectangle of text
textWidth2 = textRect2(3)-textRect2(1); % figures width of bounding rectangle of text
xPos1 = cfg.screenCenter(1) - textWidth1/2; % sets x position half the text length back from center
xPos2 = cfg.screenCenter(1) - textWidth2/2; % sets x position half the text length back from center
yPos = cfg.screenCenter(2);
yPos2 = yPos + ny1;
Screen('Flip', window)
aOK=0; % initial value for aOK
while aOK ~= 1
compNum = GetEchoStringForm(window, inputReq1, xPos1, yPos, cfg.textColor); % displays string in PTB; allows backspace
% HOW TO GET THIS TO ALLOW REPEATED INPUT?
% TRY BREAK OR RETURN
% TRY CATCH INSTEAD - step back in a while loop
% compNum = input('Enter the number of your computer and then press "Enter": ') % ENGLISH
% compNum = input('Tasti il numero sopra il tuo computer e poi premi "Enter": ') % ITALIAN
switch isempty(compNum)
case 1 %deals with both cancel and X presses
Screen('Flip', window)
compNum = GetEchoStringForm(window, fail1, xPos1, yPos, cfg.textColor); % displays string in PTB; allows backspace
case 0
if length(compNum) ~= 2 || str2num(compNum) <= 0 || str2num(compNum) >= 25
% aOK = 0;
Screen('Flip', window)
% compNum = GetEchoStringForm(window, fail1, xPos1, yPos, cfg.textColor); % displays string in PTB; allows backspace
% break
else
aOK = 1;
Screen('Flip', window)
end
end
Screen('Flip', window)
end
aOK=0; % initial value for aOK
while aOK ~= 1
insertDate = GetEchoStringForm(window, inputReq2, xPos2, yPos2, cfg.textColor); % displays string in PTB; allows backspace
% HOW TO GET THIS TO ALLOW REPEATED INPUT?
% TRY BREAK OR RETURN
% compNum = input('Enter the date as written on the whiteboard and then press "Enter": ') % ENGLISH
% compNum = input('Tasti il dato come ? scritto su lavagna e poi premi "Enter": ') % ITALIAN
switch isempty(insertDate)
case 1 %deals with both cancel and X presses
Screen('Flip', window)
insertDate = GetEchoStringForm(window, fail2, xPos2, yPos2, cfg.textColor); % displays string in PTB; allows backspace
case 0
if length(insertDate) ~= 4;
aOK = 0;
Screen('Flip', window)
insertDate = GetEchoStringForm(window, fail2, xPos2, yPos2, cfg.textColor); % displays string in PTB; allows backspace
else
aOK = 1;
Screen('Flip', window)
end
end
Screen('Flip', window)
end
particNum = [insertDate, compNum];
%% call scripts
% TEMP VARIABLES FOR TESTING
% total1shotEarnings = 8;
% winnings2x2 = 1;
% p1GameEarnings = 8.85;
% gamesdatafilename = 'sub123422-0809-1426_4games2x2.dat';
winningsMPL = 3.85;
earningsRaven = 6;
[gamesdatafilename]=games(particNum, DateTime, window, windowRect, gamestrials, enabledKeys, cfg);
% [gamesdatafilename]=games(subNo, anni, w, wRect, NUMROUNDS, enabledKeys, cfg)
% patentTaskInstructions(window, windowRect, enabledKeys, cfg, player1maxbid);
[totalEarnings] = regretTask(particNum, DateTime, window, windowRect, enabledKeys, 10);% Clear the workspace and the screen
% regretTask(particNum, DateTime, window, windowRect, enabledKeys,
% trials); % trials should be no more than 10
[total1shotEarnings, wof1shotRatingDuration] = regretTask1shot(particNum, DateTime, window, windowRect, enabledKeys, screenNumber, cfg);
% [total1shotEarnings, wof1shotRatingDuration] = regretTask1shot(particNum, DateTime, window, windowRect, enabledKeys, screenNumber, cfg)% Clear the workspace and the screen
% [p1GameEarnings] = patentTaskBTMP(particNum, DateTime, window, windowRect, enabledKeys, 'fictive', player1maxbid, prtrials);
% [p1GameEarnings] = patentTaskBTMP(particNum, DateTime, window, windowRect, enabledKeys, player2Strategy, player1maxbid, trials);
% [player1Earnings] = patentTaskBTMP(particNum, DateTime, window, windowRect, player2Strategy, player1maxbid, enabledKeys)
% [rating, ratingDuration, normalizedChoice, computerSide] = debrief_slider(particNum, DateTime, window, windowRect, enabledKeys)
% [rating, ratingDuration, normalizedChoice, computerSide] = debrief_slider(particNum, DateTi me, wi n dow, windowRect, enabledKeys)
% [cit] = CITquestionnaire(cfg, particNum, DateTime, window, windowRect, enabledKeys);
% [winningsMPL, earningsRaven] = questionnaires(particNum, DateTime, window, windowRect)
[winnings2x2, chosenGame, opponentChoice]=games2x2winnings(gamesdatafilename, cfg, window);
[totalEarnings]=payouts(cfg, window, showUp, 'Show-up pagamento', winnings2x2, 'Righe e Colonne', total1shotEarnings, ...
'Ruota della fortuna', p1GameEarnings, 'Patent Race', winningsMPL, 'Lista dei Prezzi', ...
earningsRaven, 'Puzzles');
% payouts(cfg, window, varargin) % must follow pattern of (amount1, label1, amount2, label2, ? amountn, labeln)
% big log file
% rating, ratingDuration, normalizedChoice, computerSide
sca; % clear all, clear screen
RestrictKeysForKbCheck([]); % re-recognize all key presses
ListenChar(0); % reenable transmission of keypresses to Matlab command window
ShowCursor; % reveal mouse cursor