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; }
// @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; }