Skip to content

Commit

Permalink
#126: fix integrated goal and belief revision (#127)
Browse files Browse the repository at this point in the history
Add missing `this` so that goal revision function
gets updated beliefs
  • Loading branch information
TimKam authored Mar 31, 2021
1 parent f9115c6 commit 4f7c523
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions spec/src/agent/Agent.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,32 @@ describe('Agent / next(), configuration object-based', () => {
})
expect(newAgent.next({ ...Belief('dogNice', true) })[0].action).toEqual('Good dog, Hasso!')
})

it('should support integrated goal and belief revision', () => {
const beliefs = {
...Belief('dogNice', false)
}
const goals = {
praiseDog: Goal('praiseDog', false, { dogName: 'Hasso' })
}
const reviseBeliefs = () => {
return { dogNice: true }
}
const reviseGoals = (beliefs, goals) => {
if (beliefs.dogNice) {
goals.praiseDog.isActive = true
}
return goals
}
const plans = [ Plan(goals.praiseDog, (belief, goalValue) => ({ action: `Good dog, ${goalValue.dogName}!` })) ]
const newAgent = new Agent({
id: 'MyAgent',
beliefs,
goals,
plans,
reviseBeliefs,
reviseGoals
})
expect(newAgent.next({ ...Belief('dogNice', false) })[0].action).toEqual('Good dog, Hasso!')
})
})
2 changes: 1 addition & 1 deletion src/agent/Agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function Agent (
this.isActive = true
this.next = function (beliefs) {
this.beliefs = this.reviseBeliefs(this.beliefs, beliefs)
this.goals = this.reviseGoals(beliefs, this.goals)
this.goals = this.reviseGoals(this.beliefs, this.goals)
if (this.isActive) {
if (Object.keys(this.desires).length === 0) {
this.intentions = this.beliefs
Expand Down

0 comments on commit 4f7c523

Please sign in to comment.