コード例 #1
0
    public ResponseAccuracyStats CheckResponse(string playerResponse)
    {
        ScriptLine activeLine = _scriptManager.GetActiveLine();
        Regex      pattern    = new Regex("[;,!.]");
        string     expected   = pattern.Replace(activeLine.line, "");

        Debug.Log("checking (" + playerResponse + ") vs. expected (" + expected + ")");
        // TODO: handle special characters
        string[] activeWords      = expected.Split();
        string[] playerWords      = playerResponse.Split();
        int      numWordsCorrect  = 0;
        int      numWordsExpected = activeWords.Length;

        for (int i = 0; i < numWordsExpected && i < playerWords.Length; i++)
        {
            // TODO: perform better and more forgiving checking versus exact match, in order
            Debug.Log("comparing: (" + activeWords[i] + ") and (" + playerWords[i] + ")");
            if (activeWords[i].Equals(playerWords[i], StringComparison.OrdinalIgnoreCase))
            {
                numWordsCorrect++;
            }
        }
        ResponseAccuracyStats stats = new ResponseAccuracyStats();

        stats.NumWordsCorrect  = numWordsCorrect;
        stats.NumWordsExpected = numWordsExpected;
        return(stats);
    }
コード例 #2
0
ファイル: ScoreManager.cs プロジェクト: lalaladida/Drama-Club
 public void UpdateStats(int lineNum, ResponseAccuracyStats lineStats)
 {
     _score.LastLineNum = lineNum;
     // TODO: update, only for testing
     if (lineStats.NumWordsCorrect > 0)
     {
         _score.NumLinesCorrect++;
     }
     _score.NumWordsCorrect = lineStats.NumWordsCorrect;
     _score.TotalLines++;
     _score.TotalWords = lineStats.NumWordsExpected;
     UpdateScore();
 }
コード例 #3
0
    public void AfterSpeechCallback(string text, double confidence)
    {
        ScriptLine activeLine = _scriptManager.GetActiveLine();

        if (_director.IsMyLine(activeLine))
        {
            // the user just uttered something again before the director spoke,
            // but not their turn, just ignore
            return;
        }
        ResponseAccuracyStats stats = _responseChecker.CheckResponse(text);
        int lineNum = _scriptManager.GetActiveLineNumber();

        _scoreManager.UpdateStats(lineNum, stats);
        Debug.Log("numCorrect: " + stats.NumWordsCorrect + " numExpected: " + stats.NumWordsExpected);
        Debug.Log("Overall Score: " + _scoreManager.GetOverallScore());
        _scriptManager.MoveToNextLine();
        if (_scriptManager.HasMoreLines())
        {
            processCurrentLine();
        }
    }