public bool CheckAnswer(string answer) { return(answer.ToLower().Contains(CorrectAnswer.ToLower()) && (!(answer.ToLower().Contains("true") && answer.ToLower().Contains("false")))); /*above line is to remove case sensitivity in answers and make it so answers that contain the answer (like a duck instead of duck) still work while * While still disallowing the use of both true and false in the same answer to buypass the true false questions*/ }
void ReleaseDesignerOutlets() { if (CorrectAnswer != null) { CorrectAnswer.Dispose(); CorrectAnswer = null; } if (false1 != null) { false1.Dispose(); false1 = null; } if (false2 != null) { false2.Dispose(); false2 = null; } if (false3 != null) { false3.Dispose(); false3 = null; } if (QuestionField != null) { QuestionField.Dispose(); QuestionField = null; } }
public void StartGame() { for (int i = 1; i <= 4; i++) { CorrectAnswer.Add(i, random.Next(1, 7)); } }
public override double CalculateScore(string answerProvided, out bool isCorrectAnswer, out bool isCompleteAnswer) { isCorrectAnswer = false; isCompleteAnswer = false; if (string.IsNullOrEmpty(answerProvided)) { return(0); } var answerIds = answerProvided.ToLowerInvariant().Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); var correctIds = CorrectAnswer.ToLowerInvariant().Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (answerIds.Length > correctIds.Length) { return(0); } var distance = answerIds.LevenshteinDistance(correctIds); var penaltyWeights = new [] { 1, 0.75, 0.5, 0.4, 0.3, 0.25, 0.2 }; var startIndex = correctIds.Length - 1; var score = ScoreAwarded; for (var i = distance - 1; i >= 0; i--) { score -= penaltyWeights[i]; } isCompleteAnswer = answerIds.Length == correctIds.Length; isCorrectAnswer = distance == 0; return(Math.Max(0, score)); }
public override double CalculateScore(string answerProvided, out bool isCorrectAnswer, out bool isCompleteAnswer) { isCorrectAnswer = false; isCompleteAnswer = false; if (string.IsNullOrEmpty(answerProvided)) { return(0); } var score = ScoreAwarded; var provided = new HashSet <string>(answerProvided.ToLowerInvariant().Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)); var correct = new HashSet <string>(CorrectAnswer.ToLowerInvariant().Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)); if (provided.Count > correct.Count) { return(0); } var penaltyWeights = new [] { 1, 0.75, 0.5, 0.4, 0.3, 0.25, 0.2 }; var penaltyIndex = Math.Min(penaltyWeights.Length, correct.Count) - 1; foreach (var c in correct) { if (!provided.Contains(c)) { score -= (ScoreAwarded * penaltyWeights[penaltyIndex]); penaltyIndex = Math.Max(0, penaltyIndex - 1); } } isCorrectAnswer = score == ScoreAwarded; isCompleteAnswer = provided.Count == correct.Count; return(Math.Max(0, score)); }
public ActionResult Index(InstructorModels.AddQuestionsModel model) { var course = db.Courses.Single(x => x.Id == model.CourseId); Question que = new Question { QuestionText = model.QuestionText, Course = course }; Answer ans1 = new Answer { AnswerText = model.Answer1, Question = que }; Answer ans2 = new Answer { AnswerText = model.Answer2, Question = que }; Answer ans3 = new Answer { AnswerText = model.Answer3, Question = que }; CorrectAnswer corAns = new CorrectAnswer { AnswerText = model.CorrectAnswer, Question = que }; que.QuestionText = model.QuestionText; var user = db.AspNetUsers.Single(u => u.UserName == "*****@*****.**"); db.Questions.Add(que); db.Answers.Add(ans1); db.Answers.Add(ans2); db.Answers.Add(ans3); db.CorrectAnswers.Add(corAns); db.SaveChanges(); return(RedirectToAction("Index")); }
public void ValidateAnswer(CorrectAnswer opt) { if (actualState != TriviaGameplayState.QUESTION) { return; } timeToCompleteCounter = 0; if (opt == correctAnswer) { cantQuestionsAnswered++; questionsAnswered.Add(randomQuestion); Checks[cantQuestionsAnswered - 1].sprite = OkIcon; SFXManager.SharedInstance.PlaySFX(SFXType.SoundType.CORRECT); if (Checks.Count == cantQuestionsAnswered) { actualState = TriviaGameplayState.END; uiManager.WinGame(); GameManager.SharedInstance.ChangeGameManager(GameManager.GameState.GAME_OVER); } else { NewQuestion(); } } else { FailAnswer(); } }
private void CopyAnswerArray() { for (int i = 0; i < 4; i++) { CheckForDoubles[i] = CorrectAnswer.ElementAt(i).Value; } }
public void SaveQuestionEditModelIntoDb(QuestionEditModel _model) { Question _question; Answer _answer; CorrectAnswer _correctAnswer; List <Answer> _answers; _question = new Question() { Text = _model.Name, TestId = _model.Id, }; _dataManager.Questions.SetQuestionIntoDb(_question); for (int i = 0; i < _model.AnswerEditModels.Count; i++) { _answer = new Answer(); _answer.Text = _model.AnswerEditModels[i].Name; _answer.QuestionId = _question.Id; _dataManager.Answers.SaveAnswer(_answer); if (_model.AnswerEditModels[i].Correct) { _correctAnswer = new CorrectAnswer() { QuestionId = _question.Id, AnswerId = _answer.Id, }; _dataManager.CorrectAnswers.SetCorrectAnswerIntoDb(_correctAnswer); } } }
public bool GetCorrectPropertyByQuestionAndAnswerIds(int questionId, int answerId) { List <CorrectAnswer> _answers = _dataManager.CorrectAnswers.GetAllCorrectAnswersByQuestionId(questionId); CorrectAnswer currentAnswer = _answers.Find(x => x.AnswerId == answerId); bool correct = currentAnswer != null ? true : false; return(correct); }
public ActionResult DeleteConfirmed(int id) { CorrectAnswer correctAnswer = db.CorrectAnswers.Find(id); db.CorrectAnswers.Remove(correctAnswer); db.SaveChanges(); return(RedirectToAction("Index")); }
protected override void InternalValidate() { base.InternalValidate(); if (CorrectAnswer.IsNull()) { AddError(CORRECT_ANSWER_PROPERTY, CORRECT_ANSWER_PROPERTY_ERROR_TEXT); } }
public override object GetQuestionData(string randomizationSeed) { return(new { Choose = CorrectAnswer.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length, Options = SortList(Options, randomizationSeed) }); }
internal virtual void Grade() { if (UserInput.ToLower() == CorrectAnswer.ToLower()) { IsCorrect = true; } else { IsCorrect = false; } }
public ActionResult Edit([Bind(Include = "Id,Answer,PracticePracticeId")] CorrectAnswer correctAnswer) { if (ModelState.IsValid) { db.Entry(correctAnswer).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PracticePracticeId = new SelectList(db.Practices, "PracticeId", "PracticeName", correctAnswer.PracticePracticeId); return(View(correctAnswer)); }
public void SetCorrectAnswerIntoDb(CorrectAnswer correct) { if (correct.QuestionId == 0 && correct.AnswerId == 0) { IsSetCorrectAnswerIntoDb = true; } else { IsSetCorrectAnswerIntoDb = false; } }
public ActionResult Create([Bind(Include = "Id,Answer,PracticePracticeId")] CorrectAnswer correctAnswer) { if (ModelState.IsValid) { db.CorrectAnswers.Add(correctAnswer); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PracticePracticeId = new SelectList(db.Practices, "PracticeId", "PracticeName", correctAnswer.PracticePracticeId); return(View(correctAnswer)); }
private void SetBlackPegs() { int counter = 0; for (int i = 0; i < CorrectAnswer.Count; i++) { if (SortedAnswerArray[i] == CorrectAnswer.ElementAt(i).Value) { HintToAnswer[counter] = Brushes.Black; counter++; } } }
// GET: CorrectAnswers/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CorrectAnswer correctAnswer = db.CorrectAnswers.Find(id); if (correctAnswer == null) { return(HttpNotFound()); } return(View(correctAnswer)); }
// GET: CorrectAnswers/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CorrectAnswer correctAnswer = db.CorrectAnswers.Find(id); if (correctAnswer == null) { return(HttpNotFound()); } ViewBag.PracticePracticeId = new SelectList(db.Practices, "PracticeId", "PracticeName", correctAnswer.PracticePracticeId); return(View(correctAnswer)); }
private void CheckIfCorrect() { if (UserAnswer == null) { IsCorrect = false; } else if (CorrectAnswer.Equals(UserAnswer)) { IsCorrect = true; } else { IsCorrect = false; } }
public ExamBuilder WithQuestion(string text, CorrectAnswer correctAnswer) { _prototype.AddQuestion( order: _prototype.Questions.Count + 1, text: text, a: "a1", b: "b1", c: "c1", d: "d1", correctAnswer: correctAnswer, explanation: Guid.NewGuid().ToString() ); return(this); }
public void Unbase64ify() { Category = Category.FromBase64(); Type = Type.FromBase64(); Difficulty = Difficulty.FromBase64(); Question = Question.FromBase64(); CorrectAnswer = CorrectAnswer.FromBase64(); if (WrongAnswers != null) { var answers = new List <string>(); foreach (var answer in WrongAnswers) { answers.Add(answer.FromBase64()); } WrongAnswers = answers; } }
public bool AddCorrectAnswer(CorrectAnswerVM model) { if (model == null) { throw new Exception("There is no Entry!"); } var answer = new CorrectAnswer { QuestionBankId = model.questionBankId, QuestionOptionId = model.questionOptionId, QuestionOptionTypeId = model.questionOptionTypeId, }; _context.CorrectAnswer.Add(answer); return(_context.SaveChanges() > 0); }
public void IsMatchTest() { { var rightAnswer = new CorrectAnswer("This is an apple."); rightAnswer.CorrectAnswerHelper = new CorrectAnswerHelperUsingRegex(rightAnswer); string s = null; Assert.False(rightAnswer.IsMatch(s)); Assert.False(rightAnswer.IsMatch("")); Assert.False(rightAnswer.IsMatch(" ")); } { var rightAnswer = new CorrectAnswer("This is an apple."); rightAnswer.CorrectAnswerHelper = new CorrectAnswerHelperUsingNormalizer(rightAnswer); string s = null; Assert.False(rightAnswer.IsMatch(s)); Assert.False(rightAnswer.IsMatch("")); Assert.False(rightAnswer.IsMatch(" ")); } }
public ActionResult CorrectAnswerPDF(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var categorie = db.QuestionToCategories.Where(i => i.CategorieId == id); if (categorie == null) { throw new HttpException(404, "Not found"); } CorrectAnswerViewModel correctAnswerViewModel = new CorrectAnswerViewModel(); correctAnswerViewModel.Categorie = db.Categories.Find(id); foreach (var item in categorie.ToList()) { Question question = db.Questions.Find(item.QuestionId); CorrectAnswer correctAnswer = new CorrectAnswer(); correctAnswerViewModel.CorrectAnswer.Add(new CorrectAnswer() { Question = question.Contents, Answer = question.CorrectAnswer }); } if (correctAnswerViewModel.CorrectAnswer.Count == 0) { throw new HttpException(404, "Not found"); } return(new ViewAsPdf(correctAnswerViewModel) { FileName = "Odpowiedzi.pdf" }); }
public override double CalculateScore(string answerProvided, out bool isCorrectAnswer, out bool isCompleteAnswer) { isCorrectAnswer = false; isCompleteAnswer = false; if (string.IsNullOrEmpty(answerProvided)) { return(0); } var coordinates = answerProvided.Split(','); if (coordinates.Length != 2) { return(0); } if (!int.TryParse(coordinates[0], out int userX)) { return(0); } if (!int.TryParse(coordinates[1], out int userY)) { return(0); } isCompleteAnswer = true; var answerCoordinates = CorrectAnswer.Split(',').Select(c => int.Parse(c)).ToArray(); if (userX < answerCoordinates[0] || userX > answerCoordinates[0] + answerCoordinates[2]) { return(0); } if (userY < answerCoordinates[1] || userY > answerCoordinates[1] + answerCoordinates[3]) { return(0); } isCorrectAnswer = true; return(ScoreAwarded); }
internal void FillDialog() { /* * 0 - content, 1 .. 5 - answer, 6 - points, 7 - id*/ Name = QuestionString[0]; for (int i = 0; i < 5; i++) { string[] splitted = QuestionString[i + 1].Split('_'); if (splitted.Length == 2) { Answers.Add(splitted[0]); CorrectAnswer.Add(splitted[1] == "1" ? true : false); } else { Answers.Add(""); CorrectAnswer.Add(false); } } Length = Int32.Parse(QuestionString[6].Replace("-", "")); }
private void NewQuestion() { do { randomQuestion = Random.Range(0, Questions.Count); }while (questionsAnswered.Contains(randomQuestion)); txtQuestion.text = Questions[randomQuestion].QuestionString; int randomOrder = Random.Range(0, 2); correctAnswer = (CorrectAnswer)randomOrder; if (correctAnswer == CorrectAnswer.LEFT) { txtAnswer1.text = Questions[randomQuestion].CorrectAnswer; txtAnswer2.text = Questions[randomQuestion].FakeAnswer; } else { txtAnswer2.text = Questions[randomQuestion].CorrectAnswer; txtAnswer1.text = Questions[randomQuestion].FakeAnswer; } }
public Question( Guid id, Exam exam, int order, string text, string a, string b, string c, string d, CorrectAnswer correctAnswer, string explanation ) { Id = id; Exam = exam; Order = order; Text = text; A = a; B = b; C = c; D = d; CorrectAnswer = correctAnswer; Explanation = explanation; }
public void StartsWithTest() { var mondaiWords0 = new [] { new MondaiWord("This"), new MondaiWord("is"), }; var mondaiWords1 = new [] { new MondaiWord("this"), new MondaiWord("is"), }; var mondaiWords2 = new [] { new MondaiWord("aaa"), new MondaiWord("This"), new MondaiWord("is"), }; var mondaiWords3 = new [] { new MondaiWord("This is"), new MondaiWord("an apple."), }; { var rightAnswer = new CorrectAnswer("This is an apple."); rightAnswer.CorrectAnswerHelper = new CorrectAnswerHelperUsingRegex(rightAnswer); { var s = MondaiWord.SimplyJoin(mondaiWords0); Assert.AreEqual("This is", s); var p = "^" + MondaiWord.GetRegexPattern(s); Assert.AreEqual(@"^This\s+is", p); StringAssert.IsMatch(p, rightAnswer.Text); } Assert.Throws<ArgumentNullException>(() => { rightAnswer.StartsWith(null); }); Assert.True(rightAnswer.StartsWith(new MondaiWord[0])); Assert.True(rightAnswer.StartsWith(mondaiWords0)); Assert.False(rightAnswer.StartsWith(mondaiWords1)); Assert.False(rightAnswer.StartsWith(mondaiWords2)); Assert.True(rightAnswer.StartsWith(mondaiWords3)); } { var rightAnswer = new CorrectAnswer("This is an apple."); rightAnswer.CorrectAnswerHelper = new CorrectAnswerHelperUsingNormalizer(rightAnswer); Assert.Throws<ArgumentNullException>(() => { rightAnswer.StartsWith(null); }); Assert.True(rightAnswer.StartsWith(new MondaiWord[0])); Assert.True(rightAnswer.StartsWith(mondaiWords0)); Assert.False(rightAnswer.StartsWith(mondaiWords1)); Assert.False(rightAnswer.StartsWith(mondaiWords2)); Assert.True(rightAnswer.StartsWith(mondaiWords3)); } }
public Question(int id, QuestionType qt, string text, CorrectAnswer ca) : this(id, qt, text) { CorrectAnswers = ca; }
public void SetCorrectAnswer(CorrectAnswer letter) => CorrectAnswers = letter;
public void Test0() { { var rightAnswer = new CorrectAnswer("This is an apple."); rightAnswer.CorrectAnswerHelper = new CorrectAnswerHelperUsingRegex(rightAnswer); Assert.AreEqual("This is an apple.", rightAnswer.Text); Assert.AreEqual(@"This\s+is\s+an\s+apple\s*\.", ((CorrectAnswerHelperUsingRegex)rightAnswer.CorrectAnswerHelper).RegexPattern); Assert.True(rightAnswer.IsMatch("This is an apple.")); Assert.True(rightAnswer.IsMatch(new [] { new MondaiWord("This"), new MondaiWord("is"), new MondaiWord("an"), new MondaiWord("apple"), new MondaiWord("."), })); } { var rightAnswer = new CorrectAnswer("This is an apple."); rightAnswer.CorrectAnswerHelper = new CorrectAnswerHelperUsingNormalizer(rightAnswer); Assert.AreEqual("This is an apple.", rightAnswer.Text); Assert.True(rightAnswer.IsMatch("This is an apple.")); Assert.True(rightAnswer.IsMatch(new [] { new MondaiWord("This"), new MondaiWord("is"), new MondaiWord("an"), new MondaiWord("apple"), new MondaiWord("."), })); } { var rightAnswer = new CorrectAnswer(@"""Aren't you swim?"" ""No, I can't."""); Assert.True(rightAnswer.IsMatch(@"""Aren't you swim ?"" ""No , I can't.""")); } }
private void NextIssue(object o) { CurrentIssue.IsAnswered = true; // Save answer var isCorrect = false; switch (IssueType) { case IssueTypes.Selection: { // ReSharper disable PossibleNullReferenceException var selectedByUserIssueIndex = Answers.IndexOf(Answers.First(a => a.SelectedByUser)) + 1; var correctIssueIndex = CurrentIssue.Answers.IndexOf(CurrentIssue.Answers.First(a => a.IsCorrect)) + 1; // ReSharper restore PossibleNullReferenceException AppController.UserInfo.Answers[_currentSet].Add(new UserAnswer { IsCorrect = (isCorrect = selectedByUserIssueIndex == correctIssueIndex), Answer = selectedByUserIssueIndex.ToString("0"), CorrectAnswer = correctIssueIndex.ToString("0"), Points = CurrentIssue.CorrectAnswerPoints }); } break; case IssueTypes.SelectionInImage: AppController.UserInfo.Answers[_currentSet].Add(new UserAnswer { IsCorrect = (isCorrect = UserAnswer == CorrectAnswer), Answer = UserAnswer.ToString("0"), CorrectAnswer = CorrectAnswer.ToString("0"), Points = CurrentIssue.CorrectAnswerPoints }); break; case IssueTypes.ImageSelection: { // ReSharper disable AssignNullToNotNullAttribute var userSelection = Answers.Where(a => a.SelectedByUser).Select(a => a.OriginalImageFileName).ToList(); var correctSelection = CurrentIssue.Answers.Where(a => a.Selected).Select(a => a.ImageFileName).ToList(); // ReSharper restore AssignNullToNotNullAttribute AppController.UserInfo.Answers[_currentSet].Add(new UserAnswer { IsCorrect = (isCorrect = userSelection.Count == correctSelection.Count && userSelection.All(correctSelection.Contains)), Answer = string.Empty, CorrectAnswer = string.Empty, Points = CurrentIssue.CorrectAnswerPoints }); } break; case IssueTypes.Order: AppController.UserInfo.Answers[_currentSet].Add(new UserAnswer { // ReSharper disable AssignNullToNotNullAttribute IsCorrect = (isCorrect = !Answers.Where((answer, index) => answer.OrderNo != index).Any()), // ReSharper restore AssignNullToNotNullAttribute Answer = string.Empty, CorrectAnswer = string.Empty, Points = CurrentIssue.CorrectAnswerPoints }); break; case IssueTypes.Placement: isCorrect = PlacementCorrectAnswer1.Count == CurrentIssue.PlacementCorrectAnswer1.Count && !PlacementCorrectAnswer1.Where( (imageFileName, index) => imageFileName != Path.Combine(_currentDirectory, CurrentIssue.PlacementCorrectAnswer1[index])).Any(); isCorrect &= PlacementCorrectAnswer2.Count == CurrentIssue.PlacementCorrectAnswer2.Count && !PlacementCorrectAnswer2.Where( (imageFileName, index) => imageFileName != Path.Combine(_currentDirectory, CurrentIssue.PlacementCorrectAnswer2[index])).Any(); isCorrect &= NumberOfShelves < 3 || (PlacementCorrectAnswer3.Count == CurrentIssue.PlacementCorrectAnswer3.Count && !PlacementCorrectAnswer3.Where( (imageFileName, index) => imageFileName != Path.Combine(_currentDirectory, CurrentIssue.PlacementCorrectAnswer3[index])).Any()); isCorrect &= NumberOfShelves < 4 || (PlacementCorrectAnswer4.Count == CurrentIssue.PlacementCorrectAnswer4.Count && !PlacementCorrectAnswer4.Where( (imageFileName, index) => imageFileName != Path.Combine(_currentDirectory, CurrentIssue.PlacementCorrectAnswer4[index])).Any()); isCorrect &= NumberOfShelves < 5 || (PlacementCorrectAnswer5.Count == CurrentIssue.PlacementCorrectAnswer5.Count && !PlacementCorrectAnswer4.Where( (imageFileName, index) => imageFileName != Path.Combine(_currentDirectory, CurrentIssue.PlacementCorrectAnswer5[index])).Any()); AppController.UserInfo.Answers[_currentSet].Add(new UserAnswer { IsCorrect = isCorrect, Answer = string.Empty, CorrectAnswer = string.Empty, Points = CurrentIssue.CorrectAnswerPoints }); break; } if (isCorrect) { AppController.UserInfo.CorrectAnswers[_currentSet]++; AppController.UserInfo.CorrectAnswerPoints[_currentSet] += CurrentIssue.CorrectAnswerPoints; } else { AppController.UserInfo.IncorrectAnswers[_currentSet]++; } // Go to the either next issue or result page var issue = GetNextIssue(); if (issue == null) { var page = o as Page; if (page != null && page.NavigationService != null) { page.NavigationService.Navigate(AppController.GetPage(ApplicationPages.ResultPage)); } } else { SetNewIssue(issue); } }