pub struct TicTacToe;Expand description
Pgx’s tic-tac-toe (tic_tac_toe): two players place marks on a 3x3
board; three in a row wins (+1, and −1 for the other player). Action
i places a mark on cell i (row-major). The observation is
bool[3, 3, 2]: the current player’s marks and the opponent’s. The
first player is random.
It reproduces Pgx 2.6 with the same operations. Pgx’s environments have
no automatic reset and give rewards to every player; this one is wrapped
as Pgx’s pgx.experimental.auto_reset does: step splits the key into
(key_step, key_reset), takes Pgx’s step(state, action, key_step),
and starts a new game with init(key_reset) where one ended. The
observation is Pgx’s observation (the view of the current player), the
reward is the reward of the player who acted, and
legal_action_mask is Pgx’s
legal_action_mask. An illegal action ends the game with Pgx’s penalty:
−1 for the player who acted and +1 for the other.
Trait Implementations§
impl Copy for TicTacToe
Source§impl Environment for TicTacToe
impl Environment for TicTacToe
Source§type State<B: Backend> = TicTacToeState<B>
type State<B: Backend> = TicTacToeState<B>
Source§type Action<B: Backend> = Scalar<B, i32>
type Action<B: Backend> = Scalar<B, i32>
I32<B> for discrete actions, Array<B, f32> for
continuous ones.Source§fn action_space(&self) -> ActionSpace
fn action_space(&self) -> ActionSpace
action_space).Source§fn default_params<B: Backend>(&self)
fn default_params<B: Backend>(&self)
Source§fn step_env_uses_key(&self) -> bool
fn step_env_uses_key(&self) -> bool
step_env uses its key (the default). An environment whose
steps are deterministic returns false, so that step natively
splits the key only when the episode ends and the reset needs it;
the results are the same (testing::check_backends compares the
native results with the traced ones, which always split).Source§fn reset<B: Backend>(
&self,
key: Key<B>,
_params: &(),
) -> (Array<B, bool>, TicTacToeState<B>)
fn reset<B: Backend>( &self, key: Key<B>, _params: &(), ) -> (Array<B, bool>, TicTacToeState<B>)
reset_env).Source§fn step_env<B: Backend>(
&self,
_key: Key<B>,
s: &TicTacToeState<B>,
action: I32<B>,
_params: &(),
) -> Transition<B, TicTacToeState<B>, Array<B, bool>>
fn step_env<B: Backend>( &self, _key: Key<B>, s: &TicTacToeState<B>, action: I32<B>, _params: &(), ) -> Transition<B, TicTacToeState<B>, Array<B, bool>>
Source§fn is_truncated<B: Backend>(&self, _s: &TicTacToeState<B>, _p: &()) -> Bool<B>
fn is_truncated<B: Backend>(&self, _s: &TicTacToeState<B>, _p: &()) -> Bool<B>
Source§fn legal_action_mask<B: Backend>(
&self,
s: &TicTacToeState<B>,
) -> Option<Array<B, bool>>
fn legal_action_mask<B: Backend>( &self, s: &TicTacToeState<B>, ) -> Option<Array<B, bool>>
state, for environments that have them (board
games, Jumanji): a mask over the joint actions (shape [n], or
nvec for multi-discrete actions); None (the default) if every
action is legal. Tests and benchmarks take legal actions with
choose_legal. Environments with more joint actions than
MAX_MASK_ACTIONS have no mask (ActionSpace::mask_len is 0).Source§fn num_actions(&self) -> usize
fn num_actions(&self) -> usize
Source§fn step<B: Backend>(
&self,
key: Key<B>,
state: &Self::State<B>,
action: Self::Action<B>,
params: &Self::Params<B>,
) -> Step<B, Self::State<B>, Self::Obs<B>>
fn step<B: Backend>( &self, key: Key<B>, state: &Self::State<B>, action: Self::Action<B>, params: &Self::Params<B>, ) -> Step<B, Self::State<B>, Self::Obs<B>>
Environment.step does: the key is split in two, both
step_env and reset are computed, and the reset state and
observation are selected where the episode ended. Natively, the reset
is computed only when the episode ends (lax::select_with), with
the same results.