Table of Contents

Class BlackjackObservation

Namespace
Gym.Environments.Envs.ToyText
Assembly
Gym.Environments.dll

A Blackjack observation read by name (DR-13): Gymnasium's (player_sum, dealer_card, usable_ace), each item a 0-d int64 array (DR-08). BlackjackEnv returns Gym.NET's generic tuple, object?[] (what its Tuple observation space samples and every space tool reads); assigning one to this record converts it: BlackjackObservation obs = env.Reset().Observation;.

public record BlackjackObservation : IDisposable, ITuple, IEquatable<BlackjackObservation>
Inheritance
BlackjackObservation
Implements
Inherited Members
Extension Methods

Remarks

The conversion shares the arrays rather than copying them, so disposing the record's arrays disposes the observation's. Equality and repr are Python's tuple's (generated by GymTupleAttribute), and the record is itself a tuple to the spaces: env.ObservationSpace.Contains(obs) holds for a record converted from an observation.

Constructors

BlackjackObservation(NDArray, NDArray, NDArray)

A Blackjack observation read by name (DR-13): Gymnasium's (player_sum, dealer_card, usable_ace), each item a 0-d int64 array (DR-08). BlackjackEnv returns Gym.NET's generic tuple, object?[] (what its Tuple observation space samples and every space tool reads); assigning one to this record converts it: BlackjackObservation obs = env.Reset().Observation;.

public BlackjackObservation(NDArray PlayerSum, NDArray DealerCard, NDArray UsableAce)

Parameters

PlayerSum NDArray

The player's total, an ace counted as 11 when that keeps the total at 21 or under (up to 31 after a busting hit).

DealerCard NDArray

The dealer's face-up card: 1 for an ace, 2 to 10 for the others (a jack, queen or king is 10).

UsableAce NDArray

1 when the player's total counts an ace as 11, else 0.

Remarks

The conversion shares the arrays rather than copying them, so disposing the record's arrays disposes the observation's. Equality and repr are Python's tuple's (generated by GymTupleAttribute), and the record is itself a tuple to the spaces: env.ObservationSpace.Contains(obs) holds for a record converted from an observation.

Properties

DealerCard

The dealer's face-up card: 1 for an ace, 2 to 10 for the others (a jack, queen or king is 10).

public NDArray DealerCard { get; init; }

Property Value

NDArray

PlayerSum

The player's total, an ace counted as 11 when that keeps the total at 21 or under (up to 31 after a busting hit).

public NDArray PlayerSum { get; init; }

Property Value

NDArray

UsableAce

1 when the player's total counts an ace as 11, else 0.

public NDArray UsableAce { get; init; }

Property Value

NDArray

Methods

Dispose()

Disposes the three arrays. A record converted from an observation shares that observation's arrays, so this releases the observation too: dispose one or the other, once.

public void Dispose()

Equals(BlackjackObservation?)

Python's ==: the generic forms are equal (PyEquality), member by member; arrays compare by value.

public virtual bool Equals(BlackjackObservation? other)

Parameters

other BlackjackObservation

The other record.

Returns

bool

true when the records are equal.

GetHashCode()

A hash consistent with Equals(object): the member count, as array members have no value hash.

public override int GetHashCode()

Returns

int

The hash.

ToString()

Python's repr of the generic form: (1, 2).

public override string ToString()

Returns

string

The text.

Operators

implicit operator object?[](BlackjackObservation)

The generic form (DR-13): the members as an object?[], Gym.NET's Python tuple, as a Tuple space samples it.

public static implicit operator object?[](BlackjackObservation value)

Parameters

value BlackjackObservation

The record.

Returns

object[]

The generic form; its values are the record's, not copies.

Exceptions

ArgumentNullException

Thrown when value is null.

implicit operator BlackjackObservation(object?[])

The record of a generic form: the items in order (a tuple) or the entries by Python name (a dict), each cast to its member's type.

public static implicit operator BlackjackObservation(object?[] value)

Parameters

value object[]

The generic form.

Returns

BlackjackObservation

The record, holding the generic form's values.

Exceptions

ArgumentNullException

Thrown when value is null.

ValueError

Thrown when the item count is not the record's: expected 3 items, got 2.

InvalidCastException

Thrown when a value is not of its member's type.