private SignalRService(HubConnection client) { _client = client; CurrentAnswer = _client .Observe <Answer, DateTime>(nameof(CurrentAnswer)) .Log(this, nameof(CurrentAnswer)) .Publish(); CurrentAnswer .Connect() .DisposeWith(_disposable); CurrentLeaderboard = _client .Observe <IList <Player> >(nameof(CurrentLeaderboard)) .Log(this, nameof(CurrentLeaderboard)) .Publish(); CurrentLeaderboard .Connect() .DisposeWith(_disposable); PlayerCountUpdated = _client .Observe <int>(nameof(PlayerCountUpdated)) .Log(this, nameof(PlayerCountUpdated)) .Publish(); PlayerCountUpdated .Connect().DisposeWith(_disposable); }
/// <summary> /// Gets a boolean indicating if the current answer is correct. /// </summary> private bool IsAnswerCorrect() { CurrentAnswer = CurrentAnswer.Trim(); if (CurrentQuestion.Question == SrsQuestionEnum.Meaning) { // Look for an exact meaning answer. bool isExactAnswer = CurrentQuestionGroup.Reference.Meanings .Split(MultiValueFieldHelper.ValueSeparator) .Any(s => s.ToLower() == CurrentAnswer.ToLower()); // If there wasn't an exact meaning, use the string distance // algorithm to approximate the answer. if (!isExactAnswer) { // Compute all evaluation strings. List <string> evaluations = new List <string>(); foreach (string meaning in CurrentQuestionGroup.Reference.Meanings.Split(MultiValueFieldHelper.ValueSeparator)) { evaluations.Add(meaning); string formattedMeaning = StringHelper.RemoveParenthesisExpressions(meaning); if (formattedMeaning != meaning) { evaluations.Add(formattedMeaning); } } // See if the answer at least approximately matches one of the evaluation strings. string answer = evaluations.Where(s => StringDistanceHelper.DoDistributedLevenshteinDistance( CurrentAnswer.ToLower(), s.ToLower(), MeaningDistanceLenience)) .FirstOrDefault(); if (answer != null) { // An approximate answer was found. CurrentAnswer = answer; return(true); } // No approximate answer found either. return(false); } // Exact answer match. return(true); } else if (CurrentQuestion.Question == SrsQuestionEnum.Reading) { // Look for an exact match for any reading. return(CurrentQuestionGroup.Reference.Readings .Split(MultiValueFieldHelper.ValueSeparator) .Any(s => s.ToLower() == CurrentAnswer.ToLower())); } // Should never happen. return(false); }
public FrameUpdate Layer3_modify() { BinaryOperator binaryOperator = Setting.Operators.GetBinary(Content); if (NumberField != null) { throw new Exception("ModifyBinary時Number不能有值"); } ExpressionTreeManager.Modify(binaryOperator); return(new FrameUpdate(CurrentAnswer.ToString(), new ExpUpdate(removeLength: 1, updateString: Content.ToString()))); }
public FrameUpdate Layer3_add() { BinaryOperator binaryOperator = Setting.Operators.GetBinary(Content); //若沒有輸入過值,則視為輸入了0 ExpressionTreeManager.Add((NumberField == null) ? 0 : NumberField.Number.Value); //數字歸零 NumberField = null; //算出一個暫時的結果並存下 CurrentAnswer = ExpressionTreeManager.TryGetTmpResult(); ExpressionTreeManager.Add(binaryOperator); return(new FrameUpdate(CurrentAnswer.ToString(), new ExpUpdate(removeLength: 0, updateString: Content.ToString()))); }
public FrameUpdate Layer3_equalCombo() { string updateString = CurrentAnswer.ToString(); //更新計算答案 CurrentAnswer = ExpressionTreeManager.GetLastTreeReplaceLeftResult(CurrentAnswer); var op = ExpressionTreeManager.GetLastTreeTopOperator(); updateString += op; var rightNumber = ExpressionTreeManager.GetLastTreeRightResult(); updateString += rightNumber.ToString(); updateString += "="; return(new FrameUpdate(CurrentAnswer.ToString(), new ExpUpdate(removeLength: ExpUpdate.REMOVE_ALL, updateString: updateString))); }
public FrameUpdate Layer3_binaryAndEqualCombo() { //CurrentAnswer已經被Binary算好了 ExpressionTreeManager.Add(CurrentAnswer); //result處理 var result = ExpressionTreeManager.TryGetResult(); var ans = result.Answer; //做更新字串 var updateString = CurrentAnswer.ToString(); for (int i = 0; i < result.ExtraRightBracketCount; i++) { updateString += ")"; } //送出結果 updateString += "="; return(new FrameUpdate(ans.ToString(), new ExpUpdate(removeLength: 0, updateString: updateString))); }