Class Belief<TReference, TObservation>
Represents the agent's belief of a single object. Some object reference is used to generate/update an observation (i.e., some information about the game state as perceived by an agent).
public class Belief<TReference, TObservation> : IBelief where TReference : class
Type Parameters
TReference
The type of the object reference used to generate/update the observation. This must be a reference type, be aware that this is not enforced by the type checker if
TReference
is an interface.TObservation
The type of the observation that the belief represents.
- Inheritance
-
Belief<TReference, TObservation>
- Implements
- Derived
- Inherited Members
Remarks
This class supports implicit conversion to TObservation
.
Constructors
Belief(Metadata, TReference, Func<TReference, TObservation>)
Initializes a new instance of the Belief<TReference, TObservation> class with an object reference, a function to generate/update the observation using the object reference, and optionally a condition on when the observation should be updated.
public Belief(Metadata metadata, TReference reference, Func<TReference, TObservation> getObservationFromReference)
Parameters
metadata
MetadataOptional metadata about this belief, used to quickly display the goal in several contexts. If omitted, default metadata will be used.
reference
TReferenceThe object reference used to generate/update the observation. This must be a reference type, be aware that this is not enforced by the type checker if
TReference
is an interface.getObservationFromReference
Func<TReference, TObservation>A function that takes an object reference and generates/updates an observation.
Exceptions
- ArgumentException
Thrown when
reference
is not a reference type.
Belief(Metadata, TReference, Func<TReference, TObservation>, Predicate<TReference>)
Initializes a new instance of the Belief<TReference, TObservation> class with an object reference, a function to generate/update the observation using the object reference, and optionally a condition on when the observation should be updated.
public Belief(Metadata metadata, TReference reference, Func<TReference, TObservation> getObservationFromReference, Predicate<TReference> shouldUpdate)
Parameters
metadata
MetadataOptional metadata about this belief, used to quickly display the goal in several contexts. If omitted, default metadata will be used.
reference
TReferenceThe object reference used to generate/update the observation. This must be a reference type, be aware that this is not enforced by the type checker if
TReference
is an interface.getObservationFromReference
Func<TReference, TObservation>A function that takes an object reference and generates/updates an observation.
shouldUpdate
Predicate<TReference>An optional condition on when the observation should be updated. Takes the object reference of the belief as a parameter for the predicate. If omitted, the belief will always update.
Exceptions
- ArgumentException
Thrown when
reference
is not a reference type.
Belief(TReference, Func<TReference, TObservation>)
Initializes a new instance of the Belief<TReference, TObservation> class with an object reference, a function to generate/update the observation using the object reference, and optionally a condition on when the observation should be updated.
public Belief(TReference reference, Func<TReference, TObservation> getObservationFromReference)
Parameters
reference
TReferenceThe object reference used to generate/update the observation. This must be a reference type, be aware that this is not enforced by the type checker if
TReference
is an interface.getObservationFromReference
Func<TReference, TObservation>A function that takes an object reference and generates/updates an observation.
Exceptions
- ArgumentException
Thrown when
reference
is not a reference type.
Belief(TReference, Func<TReference, TObservation>, Predicate<TReference>)
Initializes a new instance of the Belief<TReference, TObservation> class with an object reference, a function to generate/update the observation using the object reference, and optionally a condition on when the observation should be updated.
public Belief(TReference reference, Func<TReference, TObservation> getObservationFromReference, Predicate<TReference> shouldUpdate)
Parameters
reference
TReferenceThe object reference used to generate/update the observation. This must be a reference type, be aware that this is not enforced by the type checker if
TReference
is an interface.getObservationFromReference
Func<TReference, TObservation>A function that takes an object reference and generates/updates an observation.
shouldUpdate
Predicate<TReference>An optional condition on when the observation should be updated. Takes the object reference of the belief as a parameter for the predicate. If omitted, the belief will always update.
Exceptions
- ArgumentException
Thrown when
reference
is not a reference type.
Fields
_getObservationFromReference
A function that takes an object reference and generates/updates an observation.
protected readonly Func<TReference, TObservation> _getObservationFromReference
Field Value
- Func<TReference, TObservation>
_reference
The object reference used to generate/update the observation.
protected readonly TReference _reference
Field Value
- TReference
_shouldUpdate
A condition on when the observation should be updated. Takes the object reference of the belief as a parameter for the predicate.
protected readonly Predicate<TReference> _shouldUpdate
Field Value
- Predicate<TReference>
Properties
Metadata
Gets the metadata of the Belief.
public Metadata Metadata { get; }
Property Value
Observation
The observation represented by the belief (i.e., some information about the game state as perceived by an agent).
public TObservation Observation { get; protected set; }
Property Value
- TObservation
Methods
UpdateBelief()
Generates/updates the observation if the shouldUpdate
condition is satisfied.
The observation is then updated by calling the getObservationFromReference
function.
public virtual void UpdateBelief()
UpdateObservation()
Generates/updates the observation.
protected void UpdateObservation()
Operators
implicit operator TObservation(Belief<TReference, TObservation>)
Implicit conversion operator to allow a Belief<TReference, TObservation> object
to be used where a TObservation
is expected.
public static implicit operator TObservation(Belief<TReference, TObservation> belief)
Parameters
belief
Belief<TReference, TObservation>The Belief<TReference, TObservation> object to convert.
Returns
- TObservation