pub struct Pong { /* private fields */ }Expand description
Single-player Pong: agent controls left paddle, rule-based opponent on right.
§Snapshot semantics
clone_state / restore_state capture ball state, paddles, scores and
step counter, but not the thread-local RNG used by serve (the
random ball direction/height sampled after every score). Trajectories
that do not score (no ball exiting through either edge) are fully
reproducible after restore_state; scoring steps will redraw a new
random serve and so are not reproduced bit-for-bit.
Implementations§
Source§impl Pong
impl Pong
Sourcepub fn get_state(&self) -> [f32; 6]
pub fn get_state(&self) -> [f32; 6]
Raw rendering state: [ball_x, ball_y, left_y, right_y, left_score, right_score]
Sourcepub fn step_two(&mut self, left_action: i64, right_action: i64) -> StepResult
pub fn step_two(&mut self, left_action: i64, right_action: i64) -> StepResult
Step the environment with explicit actions for both paddles.
Unlike Environment::step, which drives the right paddle with a
rule-based tracker (see OPPONENT_SPEED), this method takes a direct
action for the right paddle. Both action arguments use the same
encoding as Environment::step: 0 = up, 1 = stay, 2 = down.
Used by self-play training where the right paddle is controlled by a
frozen policy snapshot rather than the heuristic. Ball physics,
collisions, scoring, and termination are otherwise identical to
Environment::step.
Trait Implementations§
Source§impl Environment for Pong
impl Environment for Pong
Source§type State = PongState
type State = PongState
restore_state
reproduces every subsequent step exactly. For envs that consume an
internal RNG (e.g. ball serve direction, food placement), the snapshot
captures the simulation step but not the RNG; see the env-level
documentation for which fields are preserved. Read moreSource§fn get_observation(&self) -> Vec<f32>
fn get_observation(&self) -> Vec<f32>
Source§fn step(&mut self, action: i64) -> StepResult
fn step(&mut self, action: i64) -> StepResult
Source§fn observation_space(&self) -> SpaceInfo
fn observation_space(&self) -> SpaceInfo
Source§fn action_space(&self) -> SpaceInfo
fn action_space(&self) -> SpaceInfo
Source§fn clone_state(&self) -> PongState
fn clone_state(&self) -> PongState
Source§fn restore_state(&mut self, state: &PongState)
fn restore_state(&mut self, state: &PongState)
Auto Trait Implementations§
impl Freeze for Pong
impl RefUnwindSafe for Pong
impl Send for Pong
impl Sync for Pong
impl Unpin for Pong
impl UnsafeUnpin for Pong
impl UnwindSafe for Pong
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more