diff --git a/src/component/event/design/DesireCommitted.js b/src/component/event/design/DesireCommitted.js index 2dcfd0e..b36a048 100644 --- a/src/component/event/design/DesireCommitted.js +++ b/src/component/event/design/DesireCommitted.js @@ -8,8 +8,8 @@ function DesireCommitted(props) { const type = "Desire committed"; const intention = props.event.message.event - const desire = intention.intentionInfo.intendedMeansInfo[0].plan.trigger - const selectedPlan = props.log.slice(0, props.log.indexOf(props.event)).findLast(e => e.message.type === "SelectPlanEvent" && e.message.event.selectedPlan.trigger === desire) + const desire = intention.intentionInfo.trigger + const selectedPlan = props.log.slice(0, props.log.indexOf(props.event)).findLast(e => e.message.type === "SelectPlanEvent" && e.message.event.selectedPlan.trigger === desire).message.event.selectedPlan const planSelected = props.log.slice(0, props.log.indexOf(props.event)).findLast(e => e.message.type === "PlanSelected" && e.message.event.goalInfo.goalFunctor === desire) const explanation = props.log.slice(0, props.log.indexOf(props.event)).findLast(e => e.message.type === "GoalCreated" && e.message.event.goalInfo.goalFunctor === desire) @@ -17,12 +17,11 @@ function DesireCommitted(props) { if (selectedPlan && planSelected) { const context = selectedPlan.context ? " because I believe " + selectedPlan.context.replace("&", "and").replace("|", "or") : "" const body = selectedPlan.body ? "Plan body: " + selectedPlan.body : "" - const im = intention.intentionInfo.intendedMeansInfo const id = intention.intentionInfo.id - const description = "I committed to desire " + desire + context + ", and it became a new intention " + id + " " + im[0].trigger + const description = "I committed to desire " + desire + context + ", and it became a new intention " + id + " " + intention.intentionInfo.trigger let reason = getIntentionReason(desire, intention.intentionInfo) - let parentDesire = reason ? ["Intention " + id + " " + desire + " is an intention" + reason,
] : [] + let parentDesire = reason ? ["Intention " + id + " " + desire + " is an intention " + reason,
] : [] if (agentState.intention[id]) { agentState.intention[id].push(desire) diff --git a/src/component/event/design/DesireRemoved.js b/src/component/event/design/DesireRemoved.js index 21c8c2e..c8a4d7c 100644 --- a/src/component/event/design/DesireRemoved.js +++ b/src/component/event/design/DesireRemoved.js @@ -31,7 +31,7 @@ function DesireRemoved(props) { let intentionInfo = "intention " + id + " " + functor.split('(')[0] if (result === "achieved") { type = "Desire satisfied"; - description = "I have satisfied my desire " + functor + " because its " + intentionInfo + " has finished" + description = "I have satisfied my desire " + functor + " because its " + intentionInfo + " finished" } else if (result === "failed") { type = "Desire dropped"; description = "I gave up desire " + functor + " because its " + intentionInfo + " failed" diff --git a/src/component/event/design/NewDesire.js b/src/component/event/design/NewDesire.js index e4fe5f9..22f48c9 100644 --- a/src/component/event/design/NewDesire.js +++ b/src/component/event/design/NewDesire.js @@ -1,6 +1,5 @@ import React from "react"; import Event from "../Event"; -import {agentState} from "../../../model/agentState"; import {Level} from "../../../model/Level"; function NewDesire(props) { @@ -13,27 +12,33 @@ function NewDesire(props) { const info = "State: " + state let description = "I have a new desire " + functor - let reason = " because it is an initial desire" + let reason = "" let explanation - if (intention) { - let im = intention.intendedMeansInfo - if (im.length > 0) { - const parent = im[0].trigger - if (agentState.speechAct.signal.includes(parent)) { - reason = " because it is created from the signal " + parent - } else if (agentState.speechAct.tell.includes(parent)) { - reason = " because it is created from " + parent + " tell message" - } else if (agentState.belief.self.includes(parent)) { - reason = " because it is formed on the addition of a belief " + parent - } else if (agentState.belief.percept.includes(parent)) { - reason = " because it is created from the perception of " + parent - } else { // parent-goal - explanation = props.log.slice(0, props.log.indexOf(props.event)).findLast(e => e.message.type === "GoalCreated" && e.message.event.goalInfo.intention.value && e.message.event.goalInfo.intention.value.id === intention.id) - reason = " because it is created from " + parent + + if (source) { + if (source.includes("self")) { + if (intention) { + let im = intention.intendedMeansInfo + if (im.length > 0) { + const parent = im[0].trigger + const type = im[0].type + + if (type === "belief") { + reason = " because I believe " + parent + } else if (type === "achieve") { + explanation = props.log.slice(0, props.log.indexOf(props.event)).findLast(e => e.message.type === "GoalCreated" && e.message.event.goalInfo.intention.value && e.message.event.goalInfo.intention.value.id === intention.id) + reason = " because it is created from " + parent + } + } else { + reason = " because it is an initial desire " + } + } + } else { //speech act message + const speechAct = props.log.slice(0, props.log.indexOf(props.event)).findLast(e => e.message.type === "NewSpeechActMessage" && e.message.event.message.sender === source[0] && e.message.event.message.message === goalInfo.goalFunctor) + if (speechAct) { + reason = " because I received a " + speechAct.message.event.message.type + " message " + speechAct.message.event.message.message + " from the agent " + speechAct.message.event.message.sender } } - } else if (source && source !== "self" && agentState.speechAct.achieve.includes(functor)) { - reason = " created from agent " + source + " by an achieved message " } return ( diff --git a/src/component/event/implementation/goalEvent/GoalCreated.js b/src/component/event/implementation/goalEvent/GoalCreated.js index c0e38b1..89600dd 100644 --- a/src/component/event/implementation/goalEvent/GoalCreated.js +++ b/src/component/event/implementation/goalEvent/GoalCreated.js @@ -6,14 +6,13 @@ function GoalCreated(props) { const type = "Goal Created" const functor = props.event.message.event.goalInfo.goalFunctor const state = props.event.message.event.goalStates - // const intention = props.event.message.event.intention.value const info = "State: " + state let description = "Goal " + functor + " created" const intention = props.event.message.event.goalInfo.intention.value let explanation if (intention) { - explanation = props.log.slice(0, props.log.indexOf(props.event)).findLast(e => e.message.type === "GoalCreated" && e.message.event.goalInfo.goalFunctor.split("(")[0] === intention.intendedMeansInfo[0].trigger) + explanation = props.log.slice(0, props.log.indexOf(props.event)).findLast(e => e.message.type === "GoalCreated" && intention.intendedMeansInfo[0] && e.message.event.goalInfo.goalFunctor.split("(")[0] === intention.intendedMeansInfo[0].trigger) description += " from " + intention.trigger } diff --git a/src/model/agentState.js b/src/model/agentState.js index 33891c1..75c77b1 100644 --- a/src/model/agentState.js +++ b/src/model/agentState.js @@ -18,7 +18,7 @@ export function getIntentionReason(desire, intentionInfo) { let reason = "" if (im.length > 0) { - let parent = im[0].trigger !== desire ? im[0].trigger : (im[1] ? im[1].trigger : "") + let parent = intentionInfo.trigger if (parent) { if (agentState.speechAct.signal.includes(parent)) {