From 8258945c0fd578bc50f541ba8f048cf1886769e4 Mon Sep 17 00:00:00 2001 From: WP_MOS Date: Mon, 7 Feb 2022 18:09:15 +0700 Subject: [PATCH] create-valueupdate-function --- index.html | 118 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 104 insertions(+), 14 deletions(-) diff --git a/index.html b/index.html index 65bf460..c42d7ab 100644 --- a/index.html +++ b/index.html @@ -486,10 +486,84 @@ } } + //#region Randomized background change + function updateBGX(ansState,consCorr){ + /** + * Update prompting background color + * @param {Boolean} ansState Answer state of previous trial: True for correct + * @param {Int} consCorr Consecutive correct trial + **/ + const rampProb = 0.2; //Ramping rate for switching probability of consecutive correct trial + const initProb = 0.2; //Inititial switching probability for correct trial + const falseProb = 1.0; + + var switchingNum = Math.random(); + var thresholdNum; + + // If correctly answer the trial question + if (ansState === true) { + thresholdNum = initProb + (consCorr-1)*rampProb; + } + else if (ansState === false) { + thresholdNum = falseProb; + } else { + throw "Wrong ansState"; + } + + //#region log + console.log(switchingNum); + console.log(thresholdNum); + //#endregion + + if (switchingNum < thresholdNum) { + bgx = Math.abs(bgx-1); + //#region log + console.log("bgx flipped"); + //#endregion + } + } + //#endregion + + //#region Update answer states (for visualization) + function updateAnsState(ansState,consCorr) { + if (typeof(ansState)=='boolean') { + if (ansState) { + consCorr+= 1; + } else { + consCorr = 0; + } + } else { + throw "Wrong answer states" + } + } + //#endregion + + //#region stacking logic + var stackLog = false; //Stacking logic for wrong answer (for repeating trials) + function flipStackingLogic() { + stackLog = stackLog ? false : true; + } + //#endregion + + //#region Update the length of the sequences + function updateNSeq(ansState,consCorr) { + if (typeof(ansState)=="boolean") { + if ((ansState) && (consCorr ==2)) { + nSeq +=1; + } else if (!ansState) { + //Do nothing + } + } else { + throw "Wrong answer states" + } + + } + //#endregion + function showTrial(){ - isTest = false; - // bgx = Math.abs(bgx-1); + // isTest indicator for testing state: true for playable, and false for instruction and others. + isTest = false; if (curTrial == 0) { bgx = 1; } @@ -502,27 +576,41 @@ // Shuffle(soundlist); var xx = Math.floor(Math.random()*360); - const dotid = []; for (var idot =0; idot