Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
Divide::goap::Planner Class Reference

#include <Planner.h>

Public Member Functions

 Planner () noexcept=default
 
void printOpenList (Divide::string &output) const
 
void printClosedList (Divide::string &output) const
 
vector< const Action * > plan (const WorldState &start, const WorldState &goal, const vector< const Action * > &actions)
 

Private Member Functions

bool memberOfClosed (const WorldState &ws) const
 
vector< goap::Node >::iterator memberOfOpen (const WorldState &ws)
 
NodepopAndClose ()
 
void addToOpenList (Node &&node)
 
int calculateHeuristic (const WorldState &now, const WorldState &goal) const
 

Private Attributes

hashMap< I32, Nodeknown_nodes_
 A master lookup table of ID-to-Node; useful during the action replay.
 
vector< Nodeopen_
 
vector< Nodeclosed_
 

Detailed Description

Definition at line 17 of file Planner.h.

Constructor & Destructor Documentation

◆ Planner()

Divide::goap::Planner::Planner ( )
defaultnoexcept

Member Function Documentation

◆ addToOpenList()

void Planner::addToOpenList ( Node &&  node)
private

Moves the given Node (an rvalue reference) into the 'open' list.

Parameters
nodean rvalue reference to a Node that will be moved to the open list

Definition at line 12 of file Planner.cpp.

◆ calculateHeuristic()

int Planner::calculateHeuristic ( const WorldState now,
const WorldState goal 
) const
private

Given two worldstates, calculates an estimated distance (the A* 'heuristic') between the two.

Parameters
nowthe present worldstate
goalthe desired worldstate
Returns
an estimated distance between them

Definition at line 8 of file Planner.cpp.

◆ memberOfClosed()

bool Planner::memberOfClosed ( const WorldState ws) const
private

Is the given worldstate a member of the closed list? (And by that we mean, does any node on the closed list contain an equal worldstate.)

Parameters
wsthe worldstate in question
Returns
true if it's been closed, false if not

Definition at line 28 of file Planner.cpp.

◆ memberOfOpen()

vector< Node >::iterator Planner::memberOfOpen ( const WorldState ws)
private

Is the given worldstate a member of the open list? (And by that we mean, does any node on the open list contain an equal worldstate.)

Parameters
wsthe worldstate in question
Returns
a pointer to the note if found, end(open_) if not

Definition at line 35 of file Planner.cpp.

◆ plan()

vector< const Action * > Planner::plan ( const WorldState start,
const WorldState goal,
const vector< const Action * > &  actions 
)

Actually attempt to formulate a plan to get from start to goal, given a pool of available actions.

Parameters
startthe starting worldstate
goalthe goal worldstate
actionsthe available action pool
Returns
a vector of Actions in REVERSE ORDER - use a reverse_iterator on this to get stepwise-order
Exceptions
std::runtime_errorif no plan could be made with the available actions and states

Definition at line 57 of file Planner.cpp.

◆ popAndClose()

Node & Planner::popAndClose ( )
private

Pops the first Node from the 'open' list, moves it to the 'closed' list, and returns a reference to this newly-closed Node. Its behavior is undefined if you call on an empty list.

Returns
a reference to the newly closed Node

Definition at line 20 of file Planner.cpp.

◆ printClosedList()

void Planner::printClosedList ( Divide::string output) const

Useful when you're debugging a GOAP plan: simply dumps the closed list to stdout.

Definition at line 48 of file Planner.cpp.

◆ printOpenList()

void Planner::printOpenList ( Divide::string output) const

Useful when you're debugging a GOAP plan: simply dumps the open list to stdout.

Definition at line 39 of file Planner.cpp.

Member Data Documentation

◆ closed_

vector<Node> Divide::goap::Planner::closed_
private

Definition at line 23 of file Planner.h.

◆ known_nodes_

hashMap<I32, Node> Divide::goap::Planner::known_nodes_
private

A master lookup table of ID-to-Node; useful during the action replay.

Definition at line 20 of file Planner.h.

◆ open_

vector<Node> Divide::goap::Planner::open_
private

Definition at line 22 of file Planner.h.


The documentation for this class was generated from the following files: