0% found this document useful (0 votes)
37 views

AI Toolkit - Utility AI

Utility AI is a planning algorithm that can be used to find the best action to perform in a given situation. It works by assigning a score to each possible action based on how well it achieves the goal. The algorithm is guaranteed to find a solution. To use it, the user creates classes for each possible action, an evaluator object containing the actions, and a "blackboard" object holding the current state. The evaluator then runs and applies the highest scoring action to the blackboard.

Uploaded by

Anna J Bischoff
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

AI Toolkit - Utility AI

Utility AI is a planning algorithm that can be used to find the best action to perform in a given situation. It works by assigning a score to each possible action based on how well it achieves the goal. The algorithm is guaranteed to find a solution. To use it, the user creates classes for each possible action, an evaluator object containing the actions, and a "blackboard" object holding the current state. The evaluator then runs and applies the highest scoring action to the blackboard.

Uploaded by

Anna J Bischoff
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Classes | Typedefs

Utility AI

Classes

class aitoolkit::utility::action< T >

Base abstract class for all actions. More...

class aitoolkit::utility::evaluator< T >

Evaluate a set of actions and apply the best one. More...

Typedefs

template<typename T >

using aitoolkit::utility::action_ptr = std::shared_ptr<action<T>>

Heap allocated pointer to an action.

Detailed Description

Introduction
Utility AI is a planning algorithm that can be used to find the best action to perform in a given situation. The algorithm works by assigning a score to
each action based on how well it will achieve the goal. The algorithm is guaranteed to find a solution.

Collect food Collect wood Collect stone Collect gold


score: +50 score: +150 score: -10 score: +75

Usage
First, include the header file:

#include <aitoolkit/utility.hpp>

Then, create a blackboard type:

struct blackboard_type {
int food{0};
int wood{0};
int stone{0};
int gold{0};
};

Next, create a class for each action that you want to be able to perform:

using namespace aitoolkit::utility;

class collect_food final : public action<blackboard_type> {


public:
virtual float score(const blackboard_type& blackboard) const override {
return 50.0f;
}

virtual void apply(blackboard_type& blackboard) const override {


blackboard.food += 1;
}
};
class collect_wood final : public action<blackboard_type> {
public:
virtual float score(const blackboard_type& blackboard) const override {
return 150.0f;
}

virtual void apply(blackboard_type& blackboard) const override {


blackboard.wood += 1;
}
};

class collect_stone final : public action<blackboard_type> {


public:
virtual float score(const blackboard_type& blackboard) const override {
return -10.0f;
}

virtual void apply(blackboard_type& blackboard) const override {


blackboard.stone += 1;
}
};

class collect_gold final : public action<blackboard_type> {


public:
virtual float score(const blackboard_type& blackboard) const override {
return 75.0f;
}

virtual void apply(blackboard_type& blackboard) const override {


blackboard.gold += 1;
}
};

Finally, create an evaluator and run it:

auto evaluator = evaluator<blackboard_type>{


std::make_shared<collect_food>(),
std::make_shared<collect_wood>(),
std::make_shared<collect_stone>(),
std::make_shared<collect_gold>()
};

auto blackboard = blackboard_type{};


evaluator.run(blackboard);

You might also like