Skip to main content

Pong

Struct Pong 

Source
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

Source

pub fn new() -> Self

Construct a new Pong environment with the ball served toward the agent.

Source

pub fn get_state(&self) -> [f32; 6]

Raw rendering state: [ball_x, ball_y, left_y, right_y, left_score, right_score]

Source

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 Default for Pong

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Environment for Pong

Source§

type Action = i64

Action type accepted by Environment::step. Read more
Source§

type State = PongState

Snapshot type for this env. For fully deterministic envs without internal RNG, this is the complete env state and 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 more
Source§

fn reset(&mut self)

Reset the environment and return initial observation
Source§

fn get_observation(&self) -> Vec<f32>

Get the current observation
Source§

fn step(&mut self, action: i64) -> StepResult

Step the environment with an action
Source§

fn observation_space(&self) -> SpaceInfo

Get the observation space dimensions
Source§

fn action_space(&self) -> SpaceInfo

Get the action space dimensions
Source§

fn render(&self) -> Vec<u8>

Render the current environment state
Source§

fn close(&mut self)

Close the environment
Source§

fn clone_state(&self) -> PongState

Snapshot the current env state for later restoration. Read more
Source§

fn restore_state(&mut self, state: &PongState)

Restore the env to a previously-snapshotted state. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more