public ExamNode examTypeOne() { Random rndQus = new Random(); Random rndChot = new Random(); Random rndChof = new Random(); ExamNode no = new ExamNode(); no.type = ExamNode.CHOICE; List<int[]> list = getEdges(2); if (list.Count < 2) return null; int c = 0; foreach (int[] l in list) { if (l[1] - l[0] - 1 < 3) { c++; } } if (c == list.Count) return null; int not = rndQus.Next(0, list.Count); int nof = rndQus.Next(0, list.Count); while (list[not][1] - list[not][0] - 1< 3 || not == nof) { not = rndQus.Next(0, list.Count); } int index = new Random().Next(4); no.ansIndex = index; no.qustion = "ข้อใดไม่ใช่ " + Regex.Replace(smartLines[list[not][0]],"[*]", "") + " ของ " + smartLines[0]; no.choice = new string[4]; no.choice[index] = Regex.Replace(smartLines[rndChot.Next(list[nof][0] + 1, list[nof][1] - 1)], "[*]", ""); index = (++index) % 4; for (int i = 0; i < 3; i++) { do { no.choice[index] = Regex.Replace(smartLines[rndChof.Next(list[not][0] + 1, list[not][1] - 1)], "[*]", ""); } while (no.choice[index] == no.choice[(index + 1) % 4] || no.choice[index] == no.choice[(index + 2) % 4] || no.choice[index] == no.choice[(index + 3) % 4]); index = (++index)%4; } return no; }
public ExamNode examTypeTwo() { Random rndQus = new Random(); ExamNode no = new ExamNode(); no.type = ExamNode.OBJ; List<int[]> list = getEdges(2); if (list.Count < 1) return null; int number = rndQus.Next(0, list.Count); no.qustion = "จงยกตัวอย่าง " + Regex.Replace(smartLines[list[number][0]], "[*]", "") + " ของ " + smartLines[0] + " มา 1 อย่าง"; int size = list[number][1] - list[number][0] - 1; no.choice = new string[size]; int c = 0; for (int i = list[number][0] + 1; i <= list[number][1] - 1; i++) { no.choice[c++] = Regex.Replace(smartLines[i], "[*]", ""); } return no; }
private void btnGenQuest_Click(object sender, EventArgs e) { int rndQus = new Random().Next(2); for (int i = 0; i < 2; i++) { if (rndQus == 0) // choice { no = exam.examTypeOne(); if (no != null) { lblAnswer.Visible = true; txtAnswer.Visible = false; btnCheck.Visible = false; grpChoice.Visible = true; txtQuestion.Text = no.qustion; radAnswer1.Text = no.choice[0]; radAnswer2.Text = no.choice[1]; radAnswer3.Text = no.choice[2]; radAnswer4.Text = no.choice[3]; radAnswer1.Checked = false; radAnswer2.Checked = false; radAnswer3.Checked = false; radAnswer4.Checked = false; return; } else { rndQus = 1; continue; } } else { // OBJ no = exam.examTypeTwo(); if (no != null) { lblAnswer.Visible = true; txtAnswer.Visible = true; btnCheck.Visible = true; grpChoice.Visible = false; txtQuestion.Text = no.qustion; return; } else { rndQus = 0; continue; } } } MessageBox.Show("Can't generate question"); }