Skip to content

0.5.14

Compare
Choose a tag to compare
@scottpdo scottpdo released this 05 Jan 16:55
· 60 commits to main since this release
dae8b14

Updates to how Agent tick rules are assigned

(Deprecated: Agent.addRule and Agent.enqueue)

To date, it's been a cumbersome extra step to 1. instantiate an Agent with data, 2. add a tick rule, and then 3. add it to the environment. However, with this release, these three steps can now be performed simultaneously!

Before:

const agent = new Agent({
  x: 12
});
agent.addRule(a => a.increment('x')); // with each tick, increment `x` value
environment.addAgent(agent);

Now:

environment.addAgent(new Agent({
  x: 12,
  tick(a) { a.increment('x'); }
}));

By setting a function (or Rule) value for tick, this will be called with every Environment.tick that the Agent belongs to. This is identical behavior to calling agent.addRule(...), except that only one function can be set at any time.

Agents can also enqueue a rule to be called once at the end of the current tick, by calling agent.enqueue(...). Similarly, this is deprecated in favor of setting a queue value:

Before:

agent.addRule(a => {
  a.increment('x');
  a.enqueue(a => a.decrement('y'));
});

Now:

a.set('tick', a => {
  a.increment('x');
  a.set('queue', a => a.decrement('y'));
});

In this case, the lines of code remains the same, but instead of calling the addRule and enqueue methods, you should set tick and queue values.

The Agent.addRule and Agent.enqueue methods are now deprecated, and will be removed in version 0.7.0. Please migrate your existing code to the new API!