JaffarPlus
High-performance best-first search optimizer for tool-assisted speedruns
Loading...
Searching...
No Matches
jaffarPlus::Rule Class Referencefinal

A labelled collection of conditions with associated reward, actions and outcome flags. More...

#include <rule.hpp>

Public Types

typedef size_t label_t
 Type used to identify a rule by label.
 

Public Member Functions

 Rule (const size_t index, const label_t label)
 Constructs a rule with its sequential index and identifying label.
 
bool evaluate () const
 Evaluates the rule by checking all of its conditions.
 
void setReward (const float reward)
 Sets the reward granted when this rule is satisfied.
 
void setWinRule (const bool isWinRule)
 Sets whether this rule is a win rule.
 
void setFailRule (const bool isFailRule)
 Sets whether this rule is a fail rule.
 
void setCheckpointRule (const bool isCheckpointRule)
 Sets whether this rule is a checkpoint rule.
 
void setCheckpointTolerance (const size_t checkPointTolerance)
 Sets the checkpoint tolerance for this rule.
 
void setSaveSolutionRule (const bool isSaveSolutionRule)
 Sets whether this rule triggers saving the solution.
 
void setSaveSolutionPath (const std::string &saveSolutionPath)
 Sets the path where the solution is saved.
 
void addAction (const std::function< void()> &function)
 Appends a game-specific action to run for this rule.
 
void addCondition (std::unique_ptr< Condition > condition)
 Adds a condition that must hold for this rule to be satisfied.
 
void addSatisfyRuleLabel (const label_t satisfyRuleLabel)
 Adds the label of another rule considered satisfied alongside this one.
 
void addSatisfyRule (Rule *const subRule)
 Adds a pointer to another rule considered satisfied alongside this one.
 
label_t getLabel () const
 Returns the rule's identifying label.
 
float getReward () const
 Returns the reward granted when this rule is satisfied.
 
bool isWinRule () const
 Returns whether this rule is a win rule.
 
bool isFailRule () const
 Returns whether this rule is a fail rule.
 
bool isCheckpointRule () const
 Returns whether this rule is a checkpoint rule.
 
size_t getCheckpointTolerance () const
 Returns the rule's checkpoint tolerance.
 
bool isSaveSolutionRule () const
 Returns whether this rule triggers saving the solution.
 
const std::string & getSaveSolutionPath () const
 Returns the path where the solution is saved.
 
const std::unordered_set< label_t > & getSatisfyRuleLabels () const
 Returns the labels of rules satisfied alongside this one.
 
const std::vector< Rule * > & getSatisfyRules () const
 Returns pointers to the rules satisfied alongside this one.
 
size_t getIndex () const
 Returns the rule's internal sequential index.
 
const std::vector< std::function< void()> > & getActions () const
 Returns the rule's game-specific actions.
 

Private Attributes

std::unordered_set< std::unique_ptr< Condition > > _conditions
 Conditions that must all hold for the rule to be satisfied.
 
const size_t _index
 Internal index for sequential access.
 
const label_t _label
 Identifying label for the rule.
 
float _reward = 0.0
 Reward associated with meeting this rule.
 
bool _isWinRule = false
 Whether this rule marks a win.
 
bool _isFailRule = false
 Whether this rule marks a fail.
 
bool _isCheckpointRule = false
 Whether this rule marks a checkpoint.
 
size_t _checkPointTolerance = 0
 Checkpoint tolerance value.
 
bool _isSaveSolutionRule = false
 Whether this rule triggers saving the solution.
 
std::string _saveSolutionPath
 Path where the solution is saved.
 
std::unordered_set< label_t_satisfyRuleLabels
 Labels of rules also satisfied when this one is.
 
std::vector< Rule * > _satisfyRules
 Pointers to rules also satisfied when this one is.
 
std::vector< std::function< void()> > _actions
 Storage for game-specific actions run for this rule.
 

Detailed Description

A labelled collection of conditions with associated reward, actions and outcome flags.

A rule is satisfied when all of its conditions evaluate to true (logical AND). On top of that it carries an identifying label and index, a numeric reward, a list of game-specific actions, and a set of other rules (by label or pointer) that are considered satisfied alongside it. Boolean flags mark the rule as a win, fail, checkpoint or save-solution rule.

Definition at line 26 of file rule.hpp.

Member Typedef Documentation

◆ label_t

typedef size_t jaffarPlus::Rule::label_t

Type used to identify a rule by label.

Definition at line 30 of file rule.hpp.

Constructor & Destructor Documentation

◆ Rule()

jaffarPlus::Rule::Rule ( const size_t  index,
const label_t  label 
)
inline

Constructs a rule with its sequential index and identifying label.

Parameters
indexInternal index used for sequential access.
labelIdentifying label for the rule.

Definition at line 37 of file rule.hpp.

Member Function Documentation

◆ addAction()

void jaffarPlus::Rule::addAction ( const std::function< void()> &  function)
inline

Appends a game-specific action to run for this rule.

Parameters
functionThe action to add.

Definition at line 67 of file rule.hpp.

◆ addCondition()

void jaffarPlus::Rule::addCondition ( std::unique_ptr< Condition condition)
inline

Adds a condition that must hold for this rule to be satisfied.

Parameters
conditionThe condition to add.

Definition at line 69 of file rule.hpp.

◆ addSatisfyRule()

void jaffarPlus::Rule::addSatisfyRule ( Rule *const  subRule)
inline

Adds a pointer to another rule considered satisfied alongside this one.

Parameters
subRuleThe rule to add.

Definition at line 73 of file rule.hpp.

◆ addSatisfyRuleLabel()

void jaffarPlus::Rule::addSatisfyRuleLabel ( const label_t  satisfyRuleLabel)
inline

Adds the label of another rule considered satisfied alongside this one.

Parameters
satisfyRuleLabelThe rule label.

Definition at line 71 of file rule.hpp.

◆ evaluate()

bool jaffarPlus::Rule::evaluate ( ) const
inline

Evaluates the rule by checking all of its conditions.

Returns
true if every condition evaluates to true, false if any fails.

Definition at line 45 of file rule.hpp.

◆ getActions()

const std::vector< std::function< void()> > & jaffarPlus::Rule::getActions ( ) const
inline

Returns the rule's game-specific actions.

Definition at line 98 of file rule.hpp.

◆ getCheckpointTolerance()

size_t jaffarPlus::Rule::getCheckpointTolerance ( ) const
inline

Returns the rule's checkpoint tolerance.

Definition at line 86 of file rule.hpp.

◆ getIndex()

size_t jaffarPlus::Rule::getIndex ( ) const
inline

Returns the rule's internal sequential index.

Definition at line 96 of file rule.hpp.

◆ getLabel()

label_t jaffarPlus::Rule::getLabel ( ) const
inline

Returns the rule's identifying label.

Definition at line 76 of file rule.hpp.

◆ getReward()

float jaffarPlus::Rule::getReward ( ) const
inline

Returns the reward granted when this rule is satisfied.

Definition at line 78 of file rule.hpp.

◆ getSatisfyRuleLabels()

const std::unordered_set< label_t > & jaffarPlus::Rule::getSatisfyRuleLabels ( ) const
inline

Returns the labels of rules satisfied alongside this one.

Definition at line 92 of file rule.hpp.

◆ getSatisfyRules()

const std::vector< Rule * > & jaffarPlus::Rule::getSatisfyRules ( ) const
inline

Returns pointers to the rules satisfied alongside this one.

Definition at line 94 of file rule.hpp.

◆ getSaveSolutionPath()

const std::string & jaffarPlus::Rule::getSaveSolutionPath ( ) const
inline

Returns the path where the solution is saved.

Definition at line 90 of file rule.hpp.

◆ isCheckpointRule()

bool jaffarPlus::Rule::isCheckpointRule ( ) const
inline

Returns whether this rule is a checkpoint rule.

Definition at line 84 of file rule.hpp.

◆ isFailRule()

bool jaffarPlus::Rule::isFailRule ( ) const
inline

Returns whether this rule is a fail rule.

Definition at line 82 of file rule.hpp.

◆ isSaveSolutionRule()

bool jaffarPlus::Rule::isSaveSolutionRule ( ) const
inline

Returns whether this rule triggers saving the solution.

Definition at line 88 of file rule.hpp.

◆ isWinRule()

bool jaffarPlus::Rule::isWinRule ( ) const
inline

Returns whether this rule is a win rule.

Definition at line 80 of file rule.hpp.

◆ setCheckpointRule()

void jaffarPlus::Rule::setCheckpointRule ( const bool  isCheckpointRule)
inline

Sets whether this rule is a checkpoint rule.

Parameters
isCheckpointRuleThe checkpoint-rule flag.

Definition at line 59 of file rule.hpp.

◆ setCheckpointTolerance()

void jaffarPlus::Rule::setCheckpointTolerance ( const size_t  checkPointTolerance)
inline

Sets the checkpoint tolerance for this rule.

Parameters
checkPointToleranceThe tolerance value.

Definition at line 61 of file rule.hpp.

◆ setFailRule()

void jaffarPlus::Rule::setFailRule ( const bool  isFailRule)
inline

Sets whether this rule is a fail rule.

Parameters
isFailRuleThe fail-rule flag.

Definition at line 57 of file rule.hpp.

◆ setReward()

void jaffarPlus::Rule::setReward ( const float  reward)
inline

Sets the reward granted when this rule is satisfied.

Parameters
rewardThe reward value.

Definition at line 53 of file rule.hpp.

◆ setSaveSolutionPath()

void jaffarPlus::Rule::setSaveSolutionPath ( const std::string &  saveSolutionPath)
inline

Sets the path where the solution is saved.

Parameters
saveSolutionPathThe file path.

Definition at line 65 of file rule.hpp.

◆ setSaveSolutionRule()

void jaffarPlus::Rule::setSaveSolutionRule ( const bool  isSaveSolutionRule)
inline

Sets whether this rule triggers saving the solution.

Parameters
isSaveSolutionRuleThe save-solution flag.

Definition at line 63 of file rule.hpp.

◆ setWinRule()

void jaffarPlus::Rule::setWinRule ( const bool  isWinRule)
inline

Sets whether this rule is a win rule.

Parameters
isWinRuleThe win-rule flag.

Definition at line 55 of file rule.hpp.

Member Data Documentation

◆ _actions

std::vector<std::function<void()> > jaffarPlus::Rule::_actions
private

Storage for game-specific actions run for this rule.

Definition at line 131 of file rule.hpp.

◆ _checkPointTolerance

size_t jaffarPlus::Rule::_checkPointTolerance = 0
private

Checkpoint tolerance value.

Definition at line 120 of file rule.hpp.

◆ _conditions

std::unordered_set<std::unique_ptr<Condition> > jaffarPlus::Rule::_conditions
private

Conditions that must all hold for the rule to be satisfied.

Definition at line 105 of file rule.hpp.

◆ _index

const size_t jaffarPlus::Rule::_index
private

Internal index for sequential access.

Definition at line 108 of file rule.hpp.

◆ _isCheckpointRule

bool jaffarPlus::Rule::_isCheckpointRule = false
private

Whether this rule marks a checkpoint.

Definition at line 119 of file rule.hpp.

◆ _isFailRule

bool jaffarPlus::Rule::_isFailRule = false
private

Whether this rule marks a fail.

Definition at line 118 of file rule.hpp.

◆ _isSaveSolutionRule

bool jaffarPlus::Rule::_isSaveSolutionRule = false
private

Whether this rule triggers saving the solution.

Definition at line 121 of file rule.hpp.

◆ _isWinRule

bool jaffarPlus::Rule::_isWinRule = false
private

Whether this rule marks a win.

Definition at line 117 of file rule.hpp.

◆ _label

const label_t jaffarPlus::Rule::_label
private

Identifying label for the rule.

Definition at line 111 of file rule.hpp.

◆ _reward

float jaffarPlus::Rule::_reward = 0.0
private

Reward associated with meeting this rule.

Definition at line 114 of file rule.hpp.

◆ _satisfyRuleLabels

std::unordered_set<label_t> jaffarPlus::Rule::_satisfyRuleLabels
private

Labels of rules also satisfied when this one is.

Definition at line 125 of file rule.hpp.

◆ _satisfyRules

std::vector<Rule*> jaffarPlus::Rule::_satisfyRules
private

Pointers to rules also satisfied when this one is.

Definition at line 128 of file rule.hpp.

◆ _saveSolutionPath

std::string jaffarPlus::Rule::_saveSolutionPath
private

Path where the solution is saved.

Definition at line 122 of file rule.hpp.


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