Book Image

Learning Game AI Programming with Lua

By : David Young
Book Image

Learning Game AI Programming with Lua

By: David Young

Overview of this book

Table of Contents (16 chapters)
Learning Game AI Programming with Lua
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
Getting Started with AI Sandbox
Index

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