Skip to content

Pong-misc

Pong

Pong(width: int = 40, height: int = 30, paddle_half_height: int = 2)

Bases: Environment[EnvState, EnvParams]

Keep the ball in play by moving the left paddle up and down.

Pong-like game on a height x width grid, adapted from the vanilla Pong of batch_pong_poc. The agent controls the left paddle. The right paddle follows a built-in policy that moves towards the ball, or copies the agent's action if params.use_ai_policy is False. Every episode starts with both paddles and the ball centred and the ball moving horizontally to the right. A paddle hit reflects the ball and changes its vertical speed depending on where it hits the paddle.

  • Observation: Box of shape (height, width, 3) with three binary channels: both paddles, the ball, and the ball at the previous step.
  • Actions: Discrete(3). 0 does nothing, 1 moves the paddle up and 2 moves it down.
  • Reward: 1 for every step in which the ball stays in play, 0 for the terminating step.
  • Termination: the ball leaves the field across the left or the right border.
  • Truncation: after params.max_steps_in_episode steps (1000 by default).

Parameters:

  • width (int, default: 40 ) –

    Number of columns of the playing field.

  • height (int, default: 30 ) –

    Number of rows of the playing field.

  • paddle_half_height (int, default: 2 ) –

    Number of cells a paddle extends above and below its centre.

References

Parameters and state

EnvParams

Bases: EnvParams

Parameters of the Pong environment.

Attributes:

  • ball_max_y_speed (int) –

    Maximum absolute vertical speed of the ball after it is reflected by a paddle.

  • paddle_y_speed (int) –

    Number of rows a paddle moves per step.

  • ball_x_speed (int) –

    Horizontal speed of the ball after a reset.

  • use_ai_policy (bool) –

    Whether the right paddle follows a built-in policy that moves towards the ball. Otherwise it executes the same action as the left paddle.

  • max_steps_in_episode (int) –

    Number of steps after which the episode is truncated.

EnvState

Bases: EnvState

State of the Pong environment.

Attributes:

  • paddle_centers (Array) –

    Array of shape (2,) with the row of the centre of the left and the right paddle.

  • ball_position (Array) –

    Position of the ball as (row, column).

  • last_ball_position (Array) –

    Position of the ball in the previous step.

  • ball_velocity (Array) –

    Velocity of the ball as (row, column) change per step.

  • time (int) –

    Number of steps taken in the current episode.

  • terminal (bool) –

    Terminal flag checked by is_terminated. Set to False on reset and not updated by the step transition.