/////GLOBAL CODE////
//JAVASCRIPT FOR PSYCHOPY CGT
// add-on: list(s: string): string[]
function list(s) {
// if s is a string, we return a list of its characters
if (typeof s === 'string')
return s.split('');
else
// otherwise we return s:
return s;
}
////Functions////
//Sampling function (choice())
Array.prototype.sample = function(){
return this[Math.floor(Math.random()*this.length)];
}
function fillArray(value, len) {
var arr = ;
for (var i = 0; i < len; i++) {
arr.push(value);
}
return arr;
}
//Range array
function range(size, startAt = 0) {
return […Array(size).keys()].map(i => i + startAt);
}
//Shuffling stuff
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
// While there remain elements to shuffle…
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
////Variables////
var array_correct, array_desc, array_group, array_image, array_redprob, bankrupt, bet_asc, bet_des, num_items, range_items, reps, seq, seq_count, star_pos, starting_score, study_trial, total_score;
starting_score = 100;
total_score = starting_score;
bet_asc = [0.05, 0.25, 0.5, 0.75, 0.95];
bet_des = [0.95, 0.75, 0.5, 0.25, 0.05];
num_items = 16;
reps = 9;
seq = 4;
seq_count = 0;
bankrupt = 0;
study_trial = 0;
range_items = fillArray([1,2,3,4], 18);
range_items = .concat.apply(, range_items);
shuffle(range_items);
star_pos = [[(- 0.7), 0.25], [(- 0.54), 0.25], [(- 0.39), 0.25], [(- 0.235), 0.25], [(- 0.08), 0.25], [0.08, 0.25], [0.235, 0.25], [0.39, 0.25], [0.54, 0.25], [0.7, 0.25]];
array_image = [‘Blue_6-4.png’, ‘Blue_7-3.png’,
‘Blue_8-2.png’, ‘Blue_9-1.png’,
‘Red_6-4.png’, ‘Red_7-3.png’,
‘Red_8-2.png’, ‘Red_9-1.png’,
‘Blue_6-4.png’, ‘Blue_7-3.png’,
‘Blue_8-2.png’, ‘Blue_9-1.png’,
‘Red_6-4.png’, ‘Red_7-3.png’,
‘Red_8-2.png’, ‘Red_9-1.png’
];
array_redprob = [0.4, 0.3, 0.2, 0.1, 0.6, 0.7, 0.8, 0.9,
0.4, 0.3, 0.2, 0.1, 0.6, 0.7, 0.8, 0.9];
array_correct = [0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1];
array_group = [1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4];
array_desc = [0, 1];
function star_chos_red(temp){
switch(temp){
case ‘Red_9-1.png’:
return(range(9,0).sample());
case ‘Red_8-2.png’:
return(range(8,0).sample());
case ‘Red_7-3.png’:
return(range(7,0).sample());
case ‘Red_6-4.png’:
return(range(6,0).sample());
case ‘Blue_6-4.png’:
return(range(4,0).sample());
case ‘Blue_7-3.png’:
return(range(3,0).sample());
case ‘Blue_8-2.png’:
return(range(2,0).sample());
case ‘Blue_9-1.png’:
return(0);
}
}
function star_chos_blue(temp){
switch(temp){
case ‘Red_9-1.png’:
return(9);
case ‘Red_8-2.png’:
return(range(2,8).sample());
case ‘Red_7-3.png’:
return(range(3,7).sample());
case ‘Red_6-4.png’:
return(range(4,6).sample());
case ‘Blue_6-4.png’:
return(range(6,4).sample());
case ‘Blue_7-3.png’:
return(range(7,3).sample());
case ‘Blue_8-2.png’:
return(range(8,2).sample());
case ‘Blue_9-1.png’:
return(range(9,1).sample());
}
}
function group_swap_desc(temp) {
switch(temp) {
case 1:
return([0,4].sample());
case 3:
return([1,5].sample());
case 1:
return([2,6].sample());
case 1:
return([3,7].sample());
}
}
function group_swap_aes(temp) {
switch(temp) {
case 1:
return([8,12].sample());
case 3:
return([9,13].sample());
case 1:
return([10,14].sample());
case 1:
return([11,15].sample());
}
}
#Tutorial parameters
tutorial_range = [2, 6, 4, 1, 5, 0, 3, 7];
tutorial_rand_range = [0.5, 0.5, 0.5, 0.1, 0.5, 0.5, 0.5, 0.5];
tutorial_trial = 0;
total_score_tutorial = 100;
tutorial_range_bet = [7, 2, 1, 6, 4, 5, 4, 0, 3];
tutorial_bet_trial = 0;
tutorial_bet_rand = [0.5, 0.5, 0.2, 0.5, 0.5, 0.5, 0.8, 0.5, 0.5];