File size: 8,034 Bytes
e7dce60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
223
224
225
226
%*****PRACTICE STIM SETUP****

% the number of trials of each stim pairing
practrials_perType = 2;


% build the practice trial list
Ayi_trials = repmat([ A,y,i ], practrials_perType, 1);
Ayc_trials = repmat([ A,y,c ], practrials_perType, 1);
Abi_trials = repmat([ A,b,i ], practrials_perType, 1);
Abc_trials = repmat([ A,b,c ], practrials_perType, 1);
Byi_trials = repmat([ B,y,i ], practrials_perType, 1);
Byc_trials = repmat([ B,y,c ], practrials_perType, 1);
Bbi_trials = repmat([ B,b,i ], practrials_perType, 1);
Bbc_trials = repmat([ B,b,c ], practrials_perType, 1);

% bind all the trial types to define the block's trials
practice_trialList = [Ayi_trials; Ayc_trials; Abi_trials; Abc_trials; Byi_trials; Byc_trials; Bbi_trials; Bbc_trials];

% read in the images and create the required textures:  {A,B}{y,b}
prac_images = [];
prac_images{1}{1} = imread('./images/1_Y.bmp');
prac_images{1}{2} = imread('./images/1_B.bmp');
prac_images{1}{3} = imread('./images/1_1.bmp');
prac_images{1}{4} = imread('./images/1_0.bmp');
prac_images{1}{5} = imread('./images/1.bmp');
prac_images{2}{1} = imread('./images/2_Y.bmp');
prac_images{2}{2} = imread('./images/2_B.bmp');
prac_images{2}{3} = imread('./images/2_1.bmp');
prac_images{2}{4} = imread('./images/2_0.bmp');
prac_images{2}{5} = imread('./images/2.bmp');

% % % randomize the images  -  No keep them known for practice.
% % randx_i=randperm(size(prac_images,2));
% % count=1;
% % for randx=1:size(prac_images)
% %     prac_images{count} = prac_images{randx_i(randx)};
% %     count=count+1;
% % end

% load all the textures
prac_textures = [];
for pracTexture_index = 1 : size(prac_images, 2) % Number of stims
    for color_index = 1 : size(prac_images{pracTexture_index}, 2) %1=Y, 2=B, 3=1, 4=0, 5=k
        prac_textures{pracTexture_index}{color_index} = Screen('MakeTexture', wPtr, prac_images{pracTexture_index}{color_index});
    end
end

% load the textures into an array mapping onto corresponding choice ids
textures = [];
textures(A,y,i) = prac_textures{1}{1}; % {A,B}{y,b}
textures(A,y,c) = prac_textures{1}{1};
textures(A,b,i) = prac_textures{1}{2};
textures(A,b,c) = prac_textures{1}{2};
textures(B,y,i) = prac_textures{2}{1};
textures(B,y,c) = prac_textures{2}{1};
textures(B,b,i) = prac_textures{2}{2};
textures(B,b,c) = prac_textures{2}{2};

FBtextures(A,1) = prac_textures{1}{3}; % {A,B}{rew,norew}
FBtextures(A,2) = prac_textures{1}{4};
FBtextures(B,1) = prac_textures{2}{3};
FBtextures(B,2) = prac_textures{2}{4};

%****BEGIN PRE-PRACTICE*****

practiceComplete = false;
numPracticeBlocks = 1; %*******Determines # of Blocks*******
pracblock_index = 0;
no_response = false;

% loop through the pracitce phase
while ~practiceComplete
    
     % track trial ids
    trial_ids = [];
    % track trial type
    trial_stimuli = [];
    %track response
    trial_response = [];
    % track which stim was choosen
    trial_selectedStim = [];
    % track the rt
    trial_RT = [];
    % track the accuracy
    trial_accuracy = [];
    % track the feedback
    trial_feedback = [];
    no_response = [] ;
    
    % increment the block index
    pracblock_index = pracblock_index + 1;
    
    random_index = randperm(size(practice_trialList, 1));
    randomized_trialList = practice_trialList(random_index,:);
    
    trial_index = 1;
    while trial_index <= size(randomized_trialList, 1)
        
        % Fixation
        fixation_text = '+';
        Screen('TextFont',wPtr,'Times');
        Screen('TextStyle',wPtr,0);
        Screen('TextColor',wPtr,[255 255 255]);
        Screen('TextSize',wPtr,80);
        DrawFormattedText(wPtr,fixation_text,'center','center');
        Screen(wPtr, 'Flip');
        % show the fixation for 1 sec
        WaitSecs(1);
        
        % get the current trial's info
        type = randomized_trialList(trial_index, 1);
        color = randomized_trialList(trial_index, 2);
        congru = randomized_trialList(trial_index, 3);
        
        % NetStation('Event',trial_pair,EventTime+offset - (1.81e-05)*(EventTime -
        % Synchtime)););
        
        % define the correct choice
        if  color==1
            correct_choice = left_button;
        elseif color==2
            correct_choice = right_button;
        end
        % define the window side based on congruency
        if  color==1 && congru==1     %(yellow-congruent==left)
            rect = left_rect;
        elseif color==1 && congru==2  %(yellow-incongruent==right)
            rect = right_rect;
        elseif color==2 && congru==1  %(blue-congruent==right)
            rect = right_rect;
        elseif color==2 && congru==2  %(blue-incongruent==left)
            rect = left_rect;
        end
        
        % now draw the stim
        Screen('DrawTexture', wPtr, textures(type,color,congru), [], rect);
        Screen(wPtr, 'Flip');
        
        % start the trial timer;
        startTime = GetSecs();
        
        wait_stamp=GetSecs;
        while 1
            [ keyIsDown, seconds, keyCode ] = KbCheck(GPindx);
            if keyIsDown
                if keyCode(left_button) &&  left_button==correct_choice
                    subject_choice = left_button;
                    no_response = false;
                    trlResponse = 1;
                    trlAccuracy = 1;
                    break;
                elseif keyCode(right_button) &&  right_button==correct_choice
                    subject_choice = right_button;
                    no_response = false;
                    trlResponse = 1;
                    trlAccuracy = 1;
                    break;
                elseif keyCode(left_button) &&  left_button~=correct_choice % ERROR!
                    subject_choice = left_button;
                    no_response = false;
                    trlResponse = 1;
                    trlAccuracy = 0;
                    break;
                elseif keyCode(right_button) &&  right_button~=correct_choice % ERROR!
                    subject_choice = right_button;
                    no_response = false;
                    trlResponse = 1;
                    trlAccuracy = 0;
                    break;
                end
            elseif(GetSecs-wait_stamp) > PREPRACT_RESPDEADLINE,
                subject_choice = no_response;
                no_response = true;
                trlResponse = -1;
                trlAccuracy = -1;
                break;
            end
        end
        
        % stop the trial timer
        RT = GetSecs() - startTime;
        
        % determine if they selected the right or left stim
        if subject_choice == correct_choice
            trlselectedStim = 1;
        else
            trlselectedStim = 0;
        end
        
        % determine the reward feedback
        Screen('TextSize',wPtr,70);
        Screen('TextFont',wPtr,'Times');
        Screen('TextStyle',wPtr,1);
        if no_response == true
            Screen('TextColor',wPtr,[255 0 0]);
            reward_text = 'Respond Faster';
        elseif no_response == false
            if trlAccuracy == 0
                Screen('TextColor',wPtr,[255 0 0]);
                reward_text = 'ERROR!';
            elseif trlAccuracy == 1
                Screen('TextColor',wPtr,[0 255 0]);
                reward_text = 'Good';
            end
        end
        
        % now show feedback based on response and stim contingencies
        DrawFormattedText(wPtr,reward_text,'center','center');
        Screen(wPtr, 'Flip');
        
        % show the feedback for 1 sec
        WaitSecs(1);
        
        % increment the trial index
        trial_index = trial_index + 1;
        
    end
    
    % check to see if practice is done
    if pracblock_index >= numPracticeBlocks
        practiceComplete = true;
    end
end

% *****END OF PRE-PRACTICE*****