Esempio n. 1
0
    public static IEnumerator LogBasesStream(MentalState m, Expression e, ProofType pt = Proof, float timeout = -1)
    {
        var result = new ProofBases();
        var done   = new Container <bool>(false);

        var startTime    = Time.time;
        var proofRoutine = m.StreamProofs(result, e, done, pt);

        m.StartCoroutine(proofRoutine);

        var waitingString    = "waiting for '" + e + "' to be proved...";
        var foundResult      = "found partial result. go to LogBasesStream() to see it.";
        var isProvedByString = "'" + e + "'" + " is proved by: ";

        while (!done.Item)
        {
            if (startTime + timeout >= Time.time)
            {
                m.StopCoroutine(proofRoutine);
                break;
            }
            // Log(waitingString);
            if (!result.IsEmpty())
            {
                // Log(foundResult);
                // Log(isProvedByString + result);
            }
            yield return(null);
        }
        Log(isProvedByString + result);
        yield break;
    }
Esempio n. 2
0
    // corresponds to the sum of two proofs:
    // either basis is sufficient to prove S
    public static ProofBases Join(ProofBases a, ProofBases b)
    {
        ProofBases ret = new ProofBases();

        ret.ProofBasisCollection.UnionWith(a.ProofBasisCollection);
        ret.ProofBasisCollection.UnionWith(b.ProofBasisCollection);
        return(ret);
    }
Esempio n. 3
0
    // corresponds to the product of two proofs:
    // both bases are necessary to prove S
    public static ProofBases Meet(ProofBases a, ProofBases b)
    {
        ProofBases ret = new ProofBases();

        foreach (var aBasis in a.ProofBasisCollection)
        {
            foreach (var bBasis in b.ProofBasisCollection)
            {
                ret.Add(new ProofBasis(aBasis, bBasis));
            }
        }
        return(ret);
    }
Esempio n. 4
0
    // @Note this should be removed when the planner is better.
    public IEnumerator RespondTo(Expression utterance, Expression speaker)
    {
        if (utterance.Type.Equals(ASSERTION))
        {
            if (utterance.Head.Equals(ASSERT.Head))
            {
                Agent.MentalState.ReceiveAssertion(
                    utterance.GetArgAsExpression(0),
                    speaker);
            }
            if (utterance.Head.Equals(DENY.Head))
            {
                Agent.MentalState.ReceiveAssertion(
                    new Expression(NOT, utterance.GetArgAsExpression(0)), speaker);
            }
            yield break;
        }

        if (utterance.Type.Equals(QUESTION))
        {
            if (utterance.Head.Equals(ASK.Head))
            {
                var positiveProofs = new ProofBases();
                var donePositive   = new Container <bool>(false);
                Agent.MentalState.StartCoroutine(Agent.MentalState.StreamProofs(
                                                     positiveProofs,
                                                     utterance.GetArgAsExpression(0),
                                                     donePositive));

                var negativeProofs = new ProofBases();
                var doneNegative   = new Container <bool>(false);

                Agent.MentalState.StartCoroutine(
                    Agent.MentalState.StreamProofs(
                        negativeProofs,
                        new Expression(NOT, utterance.GetArgAsExpression(0)),
                        doneNegative));

                while (!donePositive.Item || !doneNegative.Item)
                {
                    yield return(new WaitForSeconds(0.5f));
                }

                if (!positiveProofs.IsEmpty())
                {
                    StartCoroutine(Say(YES, 5));
                    yield break;
                }

                if (!negativeProofs.IsEmpty())
                {
                    StartCoroutine(Say(NO, 5));
                    yield break;
                }

                StartCoroutine(Say(MAYBE, 5));
            }

            yield break;
        }

        if (utterance.Type.Equals(CONFORMITY_VALUE))
        {
            if (utterance.Head.Equals(WOULD.Head))
            {
                var content = utterance.GetArgAsExpression(0);
                var proofs  = new ProofBases();
                var done    = new Container <bool>(false);

                Agent.MentalState.StartCoroutine(
                    Agent.MentalState.StreamProofs(proofs, content, done, ProofType.Plan));

                while (!done.Item)
                {
                    yield return(new WaitForSeconds(0.5f));
                }

                if (!proofs.IsEmpty())
                {
                    StartCoroutine(Say(ACCEPT, 5));
                    Agent.MentalState.ReceiveRequest(content, speaker);
                }
                else
                {
                    StartCoroutine(Say(REFUSE, 5));
                }
            }

            yield break;
        }

        yield break;
    }
Esempio n. 5
0
 public void Add(ProofBases bases)
 {
     ProofBasisCollection.UnionWith(bases.ProofBasisCollection);
 }