/* Check every InputField.
     * @return true if no error is found.
     */
    public bool Validate()
    {
        HashSet <EdgeInput> goodInputs = new HashSet <EdgeInput> ();

        foreach (var a in GoodAnswer)
        {
            EdgeInput ei = m_Inputs.Find(e => e.TextEquals(a.Substring(0, 1), a.Substring(1, 1), IsChinaMap));
            if (ei != null)
            {
                goodInputs.Add(ei);
            }
        }
        HashSet <EdgeInput> badInputs = new HashSet <EdgeInput> (m_Inputs);

        badInputs.ExceptWith(goodInputs);
        foreach (var i in badInputs)
        {
            i.ShowColoredInput(false);
        }
        foreach (var i in goodInputs)
        {
            i.ShowColoredInput(true);
        }
        return(badInputs.Count == 0);
    }
    public virtual void Start()
    {
        bc = GetComponent <BoxCollider2D>();

        foreach (EdgeInput i in GetComponentsInChildren <EdgeInput>())
        {
            switch (i.colliderPosition)
            {
            case EdgeInput.Direction.Above:
                aboveInput    = i;
                aboveCollider = i.gameObject.GetComponent <EdgeCollider2D>();
                break;

            case EdgeInput.Direction.Below:
                belowInput    = i;
                belowCollider = i.gameObject.GetComponent <EdgeCollider2D>();
                break;

            case EdgeInput.Direction.Front:
                frontInput    = i;
                frontCollider = i.gameObject.GetComponent <EdgeCollider2D>();
                break;

            case EdgeInput.Direction.Back:
                backInput    = i;
                backCollider = i.gameObject.GetComponent <EdgeCollider2D>();
                break;
            }
        }

        UpdateEdgeColliders();
    }
    void Start()
    {
        states = GetComponent <States>();
        rb     = GetComponent <Rigidbody2D>();

        foreach (EdgeInput i in GetComponentsInChildren <EdgeInput>())
        {
            if (i.colliderPosition == EdgeInput.Direction.Below)
            {
                belowColliderInput = i;
            }
        }
    }
Beispiel #4
0
    void Start()
    {
        states   = GetComponent <PlayerStates>();
        movement = GetComponent <Movement>();
        rb       = GetComponent <Rigidbody2D>();

        foreach (EdgeInput i in GetComponentsInChildren <EdgeInput>())
        {
            if (i.colliderPosition == EdgeInput.Direction.Front)
            {
                frontColliderInput = i;
            }
        }
    }
    public void ShowGoodAnswer()
    {
        List <string> goodAnswers = new List <string> (GoodAnswer);

        if (goodAnswers.Count != m_Inputs.Count)
        {
            return;
        }
        for (int i = 0; i < goodAnswers.Count; i++)
        {
            string    answer = goodAnswers [i];
            EdgeInput ei     = m_Inputs [i];
            ei.input1.text = answer.Substring(0, 1);
            ei.input2.text = answer.Substring(1, 1);
            ei.ShowColoredInput(true);
        }
    }
    public virtual void Start()
    {
        rb = GetComponent <Rigidbody2D>();
        bc = GetComponent <BoxCollider2D>();

        aboveInput = aboveColliderObject.GetComponent <EdgeInput>();
        belowInput = belowColliderObject.GetComponent <EdgeInput>();
        frontInput = frontColliderObject.GetComponent <EdgeInput>();
        backInput  = backColliderObject.GetComponent <EdgeInput>();

        aboveCollider = aboveColliderObject.GetComponent <EdgeCollider2D>();
        belowCollider = belowColliderObject.GetComponent <EdgeCollider2D>();
        frontCollider = frontColliderObject.GetComponent <EdgeCollider2D>();
        backCollider  = backColliderObject.GetComponent <EdgeCollider2D>();

        UpdateEdgeCollidersUpright();

        lastPosition = rb.position;
    }
Beispiel #7
0
        private ResponseBase getResponse(ParsedUtterance utterance)
        {
            var responses         = new List <ModifiableResponse>();
            var originalUtterance = utterance.OriginalSentence;

            _context.StartTurn(originalUtterance);
            var edgeInput = new EdgeInput(originalUtterance);

            do
            {
                _context.EdgeReset();

                var scores = edgeInput.GetScore(_currentState);

                Trigger trigger;
                if (scores.Any())
                {
                    var bestHypothesis     = scores.First();
                    var score              = bestHypothesis.Score;
                    var nonPatternQuestion = getBestNonPattern(scores);

                    if (score < 0.5)
                    {
                        trigger = _currentState.DefaultTrigger;
                    }
                    else if (nonPatternQuestion != null && nonPatternQuestion.Score < 0.9 && _currentState == QuestionRouting)
                    {
                        _context.SetValue(EquivalenceQuestion.QueriedQuestion, originalUtterance);
                        var substitution = substitute(nonPatternQuestion.ParsedSentence, utterance);
                        _context.SetValue(EquivalenceQuestion.PatternQuestion, substitution);
                        edgeInput = new EdgeInput(EquivalenceQuestion.EquivalenceEdge);
                        continue;
                    }
                    else if (score < 0.9)
                    {
                        trigger = _currentState.DefaultTrigger;
                    }
                    else
                    {
                        var substitution = bestHypothesis.Substitution;
                        trigger = bestHypothesis.Value;
                        _context.AddSubstitution(substitution);
                    }
                }
                else
                {
                    trigger = _currentState.DefaultTrigger;
                }

                if (trigger == null)
                {
                    throw new NullReferenceException("Cannot handle null trigger");
                }

                var response = fireTrigger(trigger);
                if (response != null)
                {
                    responses.Add(response);
                }

                edgeInput = _context.CurrentOutput;
            } while (edgeInput != null);

            var concatenation = from response in responses select response.CreateResponse().ToString();

            return(new SimpleResponse(string.Join(".", concatenation)));
        }