Game Development Reference
In-Depth Information
Adding and removing knowledge sources
To add a knowledge source to the blackboard, we can store an array of knowledge sources
indexed by the blackboard attribute they represent. Removal is the exact opposite of insert-
ing, and simply iterates through each of the attributes' knowledge sources and removes the
corresponding source, if found:
Blackboard.lua :
function Blackboard.AddSource(self, attribute, source)
if (not self.sources_[attribute]) then
self.sources_[attribute] = {};
end
table.insert(self.sources_[attribute], source);
end
function Blackboard.RemoveSource(self, attribute, source)
-- Since there can be multiple sources for the same
attribute,
-- iterate over all sources to find the correct one to
remove.
if (self.sources_[attribute]) then
for index = 1, #self.sources_[attribute] do
if (self.sources_[attribute][index] == source)
then
table.remove(self.sources_[attribute],
index);
break;
end
end
end
end
Search WWH ::




Custom Search