public int span3, span4, span5, span6, span7; // number correct for a span of 3, 4, 5, etc #region Test Creation public CorsiTest(int numTrials, bool isPractice, ref ArrayList nextIndexes) { this.rand = new Random(); this.numTrials = numTrials; this.trials = createTrials(numTrials, isPractice); this.span3 = 0; this.span4 = 0; this.span5 = 0; this.span6 = 0; this.span7 = 0; this.curTrialIndex = 0; nextIndexes = CogTest.createRandomList(0, 8, trials[0].spanLength, ref rand); }
/* generate 10 unique <key, value> string pairs, * as well as 5 questions: each question has 4 options, * only one of which is correct */ public Dictionary <string, string> generateGrid(out string[] answers, out string[,] options) { // create the main grid Dictionary <string, string> dict = new Dictionary <string, string>(10); for (int i = 1; i <= 10; i++) { FindRandoms: string num = rand.Next(1000, 10000).ToString(); string str = randString(); if (dict.Keys.Contains(num) || dict.Values.Contains(str)) { goto FindRandoms; } dict.Add(num, str); } // pick 5 unique answers ArrayList answerIndexes = CogTest.createRandomList(0, 9, 5, ref rand); options = new string[5, 4]; answers = new string[5]; // pick 4 options for each question (one of which is correct) for (int i = 0; i < 5; i++) { answers[i] = dict.ElementAt((int)answerIndexes[i]).Value; // choose which option will be the correct answer options[i, rand.Next(0, 4)] = dict.ElementAt((int)answerIndexes[i]).Key; // set other possible options (must be different from correct answer) GenerateOtherOptions: ArrayList dictIndexes = CogTest.createRandomList(0, 9, 3, ref rand); if (dictIndexes.Contains((int)answerIndexes[i])) { goto GenerateOtherOptions; } int arrayListIndex = 0; for (int j = 0; j < 4; j++) { if (options[i, j] == null) { options[i, j] = dict.ElementAt((int)dictIndexes[arrayListIndex++]).Key; } } } return(dict); }
// process input and return true if there are more trials public bool nextTrial(bool correct, ref ArrayList nextIndexes) { trials[curTrialIndex].correct = correct; // update global counter for appropriate span length if (correct == true) { switch (trials[curTrialIndex].spanLength) { case 3: span3++; break; case 4: span4++; break; case 5: span5++; break; case 6: span6++; break; case 7: span7++; break; } } curTrialIndex++; if (curTrialIndex == numTrials) { // no trials left - end of the current test return(false); } else { nextIndexes = CogTest.createRandomList(0, 8, trials[curTrialIndex].spanLength, ref rand); return(true); } }
/* ========== This is the top level execution sequence =========*/ void frmBase_Shown(object sender, EventArgs e) { // randomize the test ordering System.Collections.ArrayList order = CogTest.createRandomList(1, 4, 4, ref rand); frmSplash.mainSplash("Keyboard Training", this); frmKeyboardTutorial keyTut = new frmKeyboardTutorial(); keyTut.ShowDialog(this); dispatch((int)order[0]); frmSplash.breakSplash(this); dispatch((int)order[1]); frmSplash.breakSplash(this); dispatch((int)order[2]); frmSplash.breakSplash(this); dispatch((int)order[3]); frmSplash.finalSplash(this); Environment.Exit(0); }
private void frmRaven_Load(object sender, EventArgs e) { CogTest.setControlVisibility(this, false); rand = new Random(); btns = new Button[8]; btns[0] = btn0; btns[1] = btn1; btns[2] = btn2; btns[3] = btn3; btns[4] = btn4; btns[5] = btn5; btns[6] = btn6; btns[7] = btn7; lbls = new Label[8]; lbls[0] = lbl0; lbls[1] = lbl1; lbls[2] = lbl2; lbls[3] = lbl3; lbls[4] = lbl4; lbls[5] = lbl5; lbls[6] = lbl6; lbls[7] = lbl7; // align main picture box picBox.Width = 550; picBox.Height = Math.Min((int)(this.ClientSize.Height / 2.5), 440); picBox.Left = (ClientSize.Width - picBox.Width) / 2; picBox.Top = 20;//-20; // test summary data numCorrect = 0; switch (this.testStatus) { case CogTest.TEST_DEMO: // show what is currently on form for demo mode this.BackColor = CogTest.DEMO_COLOR; CogTest.enableDoubleEnterAdvance(this); alignButtons(8); CogTest.setControlVisibility(this, true); break; case CogTest.TEST_PRACTICE: questions = new ArrayList(2); questions.Add(-1); questions.Add(-2); numUnfinished = 2; CogTest.setControlVisibility(this, true); showNextQuestion(); break; case CogTest.TEST_OFFICIAL: questions = CogTest.createRandomList(1, 10, 10, ref rand); numUnfinished = 10; // set visibility before loading the question because the question may only need 6 butons CogTest.setControlVisibility(this, true); showNextQuestion(); testTimer.Start(); stopwatch.Start(); break; } picBox.Focus(); }