(C++)  1.1.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
UnitStepFunction.hh
1 #ifndef GRAIL_SINGLE_STEP_FUNCTION_H
2 #define GRAIL_SINGLE_STEP_FUNCTION_H
3 
4 #include "Curve.hh"
5 
6 
7 namespace grail
8 {
9  namespace curves
10  {
11  template <typename ContextType>
16  class UnitStepFunction final : public Curve<ContextType>
17  {
18  public:
26  UnitStepFunction(std::shared_ptr<utility::Evaluator<ContextType>> childEvaluator,
27  float threshold, float beforeThresholdValue, float afterThresholdValue)
28  : Curve<ContextType>{childEvaluator},
29  threshold{ threshold }, beforeThresholdValue{ beforeThresholdValue }, afterThresholdValue{ afterThresholdValue }
30  {
31  }
32 
33  virtual float Sample(float argument) const override final
34  {
35  return argument > threshold ? afterThresholdValue : beforeThresholdValue;
36  }
37 
42  float GetThreshold() const { return threshold; }
47  float GetBeforeThresholdValue() const { return beforeThresholdValue; }
52  float GetAfterThresholdValue() const { return afterThresholdValue; }
53 
54  EvaluatorType GetEvaluatorType() const override final { return EvaluatorType::CURVE_UNIT_STEP; }
55 
56  private:
57  float threshold = 0.0f;
58  float beforeThresholdValue = 0.0f;
59  float afterThresholdValue = 0.0f;
60  };
61  }
62 }
63 
64 
65 #endif // GRAIL_SINGLE_STEP_FUNCTION_H
The Curve class - Defines objects transforming one value into the other.
Definition: Curve.hh:21
The UnitStepFunction class - Unit Step Function.
Definition: UnitStepFunction.hh:17
float GetBeforeThresholdValue() const
GetBeforeThresholdValue.
Definition: UnitStepFunction.hh:47
float GetAfterThresholdValue() const
GetAfterThresholdValue.
Definition: UnitStepFunction.hh:52
float GetThreshold() const
GetThreshold.
Definition: UnitStepFunction.hh:42
virtual float Sample(float argument) const override final
Sample - Transforms argument into output value depending on the type of Curve.
Definition: UnitStepFunction.hh:33
UnitStepFunction(std::shared_ptr< utility::Evaluator< ContextType >> childEvaluator, float threshold, float beforeThresholdValue, float afterThresholdValue)
UnitStepFunction - Constructor.
Definition: UnitStepFunction.hh:26
The Evaluator class - base class being able to evaluate given context and output the result.
Definition: Evaluator.hh:21