Game Development Reference
In-Depth Information
Creating a knowledge source
Knowledge sources have a few main characteristics: cached evaluation of the resulting cal-
culation, the confidence of the evaluation, and the update frequency.
The cached evaluation is merely the result of the evaluator function the Know-
ledgeSource instance stores internally. The confidence measure is a value between 0
and 1, which our knowledge data structure can use to determine the best piece of know-
ledge to be used at any given time.
The update frequency is used to determine whether the knowledge source needs to re-eval-
uate the evaluator function when evaluation is invoked. Typically, this value can be used to
throttle constant re-evaluations when the same knowledge source is used in multiple places
within a logic structure:
KnowledgeSource.lua :
KnowledgeSource = {};
function KnowledgeSource.new(evaluator, updateFrequency)
local source = {};
-- The KnowledgeSource's data members.
source.confidence_ = 0;
source.evaluation_ = nil;
source.evaluator_ = evaluator;
source.lastUpdateTime_ = 0;
source.updateFrequency_ = updateFrequency or 0;
-- The KnowledgeSource's accessor functions.
source.Evaluate = KnowledgeSource.Evaluate;
return source;
end
Search WWH ::




Custom Search