Reader small image

You're reading from  Learning Game AI Programming with Lua

Product typeBook
Published inNov 2014
Reading LevelBeginner
PublisherPackt
ISBN-139781783281336
Edition1st Edition
Languages
Right arrow
Author (1)
David Young
David Young
Right arrow

Evaluators


Evaluators are the principal method of handling conditional checks in our decision structures. While actions perform the eventual behaviors that our agents exhibit, it's the responsibly of evaluators to determine which action is allowed to run at what time.

Creating an evaluator object simply wraps a function call that returns true or false when the userData table is passed into the function:

Evaluator.lua:

function Evaluator.Evaluate(self)
    return self.function_(self.userData_);
end

function Evaluator.new(name, evalFunction, userData)
    local evaluator = {};
    
    -- data members
    evaluator.function_ = evalFunction;
    evaluator.name_ = name or "";
    evaluator.type_ = Evaluator.Type;
    evaluator.userData_ = userData;
    
    -- object functions
    evaluator.evaluate_ = Evaluate;
    
    return evaluator;
end
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Learning Game AI Programming with Lua
Published in: Nov 2014Publisher: PacktISBN-13: 9781783281336

Author (1)