Jido. BehaviorTree. Blackboard
(Jido Behavior Tree v1.0.0)
View Source
A shared data structure for communication between behavior tree nodes.
The blackboard pattern allows nodes in a behavior tree to share data without tight coupling. Nodes can read from and write to the blackboard to coordinate their behavior and share results.
The blackboard is essentially a map with convenience functions for common operations like getting, setting, and updating values.
Summary
Functions
Deletes a key from the blackboard.
Checks if the blackboard is empty.
Gets a value from the blackboard by key.
Checks if the blackboard contains a key.
Gets all keys from the blackboard.
Merges another map or blackboard into this blackboard.
Creates a new blackboard with optional initial data.
Sets a value in the blackboard.
Returns the Zoi schema for this module
Returns the size (number of keys) in the blackboard.
Converts the blackboard to a plain map.
Updates a value in the blackboard using a function.
Gets all values from the blackboard.
Types
@type t() :: %Jido.BehaviorTree.Blackboard{data: map()}
Functions
Deletes a key from the blackboard.
Examples
iex> bb = Jido.BehaviorTree.Blackboard.new(%{user_id: 123, temp: "delete_me"})
iex> bb = Jido.BehaviorTree.Blackboard.delete(bb, :temp)
iex> Jido.BehaviorTree.Blackboard.get(bb, :temp)
nil
Checks if the blackboard is empty.
Examples
iex> bb = Jido.BehaviorTree.Blackboard.new()
iex> Jido.BehaviorTree.Blackboard.empty?(bb)
true
iex> bb = Jido.BehaviorTree.Blackboard.new(%{a: 1})
iex> Jido.BehaviorTree.Blackboard.empty?(bb)
false
Gets a value from the blackboard by key.
Examples
iex> bb = Jido.BehaviorTree.Blackboard.new(%{user_id: 123})
iex> Jido.BehaviorTree.Blackboard.get(bb, :user_id)
123
iex> Jido.BehaviorTree.Blackboard.get(bb, :missing_key, "default")
"default"
Checks if the blackboard contains a key.
Examples
iex> bb = Jido.BehaviorTree.Blackboard.new(%{user_id: 123})
iex> Jido.BehaviorTree.Blackboard.has_key?(bb, :user_id)
true
iex> Jido.BehaviorTree.Blackboard.has_key?(bb, :missing)
false
Gets all keys from the blackboard.
Examples
iex> bb = Jido.BehaviorTree.Blackboard.new(%{a: 1, b: 2})
iex> Jido.BehaviorTree.Blackboard.keys(bb)
[:a, :b]
Merges another map or blackboard into this blackboard.
Examples
iex> bb1 = Jido.BehaviorTree.Blackboard.new(%{a: 1, b: 2})
iex> bb2 = Jido.BehaviorTree.Blackboard.new(%{b: 3, c: 4})
iex> bb = Jido.BehaviorTree.Blackboard.merge(bb1, bb2)
iex> Jido.BehaviorTree.Blackboard.get(bb, :b)
3
Creates a new blackboard with optional initial data.
Examples
iex> bb = Jido.BehaviorTree.Blackboard.new()
%Jido.BehaviorTree.Blackboard{data: %{}}
iex> bb = Jido.BehaviorTree.Blackboard.new(%{user_id: 123, status: "active"})
%Jido.BehaviorTree.Blackboard{data: %{user_id: 123, status: "active"}}
Sets a value in the blackboard.
Examples
iex> bb = Jido.BehaviorTree.Blackboard.new()
iex> bb = Jido.BehaviorTree.Blackboard.put(bb, :user_id, 123)
iex> Jido.BehaviorTree.Blackboard.get(bb, :user_id)
123
Returns the Zoi schema for this module
@spec size(t()) :: non_neg_integer()
Returns the size (number of keys) in the blackboard.
Examples
iex> bb = Jido.BehaviorTree.Blackboard.new(%{a: 1, b: 2})
iex> Jido.BehaviorTree.Blackboard.size(bb)
2
Converts the blackboard to a plain map.
Examples
iex> bb = Jido.BehaviorTree.Blackboard.new(%{user_id: 123})
iex> Jido.BehaviorTree.Blackboard.to_map(bb)
%{user_id: 123}
Updates a value in the blackboard using a function.
If the key doesn't exist, the initial value is used as input to the function.
Examples
iex> bb = Jido.BehaviorTree.Blackboard.new(%{counter: 5})
iex> bb = Jido.BehaviorTree.Blackboard.update(bb, :counter, 0, &(&1 + 1))
iex> Jido.BehaviorTree.Blackboard.get(bb, :counter)
6
iex> bb = Jido.BehaviorTree.Blackboard.new()
iex> bb = Jido.BehaviorTree.Blackboard.update(bb, :counter, 0, &(&1 + 1))
iex> Jido.BehaviorTree.Blackboard.get(bb, :counter)
1
Gets all values from the blackboard.
Examples
iex> bb = Jido.BehaviorTree.Blackboard.new(%{a: 1, b: 2})
iex> Jido.BehaviorTree.Blackboard.values(bb)
[1, 2]