{"id":24098476,"url":"https://github.com/matlab-deep-learning/playing-pong-with-deep-reinforcement-learning","last_synced_at":"2025-07-28T21:09:04.744Z","repository":{"id":118345285,"uuid":"342685812","full_name":"matlab-deep-learning/playing-Pong-with-deep-reinforcement-learning","owner":"matlab-deep-learning","description":"Train a reinforcement learning agent to play a variation of Pong®","archived":false,"fork":false,"pushed_at":"2021-03-01T19:28:52.000Z","size":1458,"stargazers_count":44,"open_issues_count":0,"forks_count":9,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-07T19:47:41.134Z","etag":null,"topics":["ddpg-algorithm","deep-learning","matlab","matlab-deep-learning","pong-game","reinforcement-learning"],"latest_commit_sha":null,"homepage":"https://www.mathworks.com/products/reinforcement-learning.html","language":"MATLAB","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/matlab-deep-learning.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"Security.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-02-26T19:55:11.000Z","updated_at":"2025-03-28T18:25:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"d4aaf09f-87ee-4383-a9ac-ac8f53548200","html_url":"https://github.com/matlab-deep-learning/playing-Pong-with-deep-reinforcement-learning","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/matlab-deep-learning/playing-Pong-with-deep-reinforcement-learning","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matlab-deep-learning%2Fplaying-Pong-with-deep-reinforcement-learning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matlab-deep-learning%2Fplaying-Pong-with-deep-reinforcement-learning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matlab-deep-learning%2Fplaying-Pong-with-deep-reinforcement-learning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matlab-deep-learning%2Fplaying-Pong-with-deep-reinforcement-learning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matlab-deep-learning","download_url":"https://codeload.github.com/matlab-deep-learning/playing-Pong-with-deep-reinforcement-learning/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matlab-deep-learning%2Fplaying-Pong-with-deep-reinforcement-learning/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267585826,"owners_count":24111577,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-28T02:00:09.689Z","response_time":68,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ddpg-algorithm","deep-learning","matlab","matlab-deep-learning","pong-game","reinforcement-learning"],"created_at":"2025-01-10T14:46:12.502Z","updated_at":"2025-07-28T21:09:04.735Z","avatar_url":"https://github.com/matlab-deep-learning.png","language":"MATLAB","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Train Deep Reinforcement Learning Agent to Play a Variation of Pong\u0026reg;\nThis example demonstrates a reinforcement learning agent playing a variation of the game of Pong\u0026reg; using [Reinforcement Learning Toolbox\u0026trade;](https://www.mathworks.com/products/reinforcement-learning.html). You will follow a command line workflow to create a DDPG agent in [MATLAB\u0026reg;](https://www.mathworks.com/products/matlab.html), set up hyperparameters and then train and simulate the agent.\n\n![Anim](./anim.gif)\n\n# Prerequisites\nThis example requires installation of the following software:\n1. [MATLAB](https://www.mathworks.com/products/matlab.html) R2020b or later\n2. [Deep Learning Toolbox\u0026trade;](https://www.mathworks.com/products/deep-learning.html)\n3. [Reinforcement Learning Toolbox](https://www.mathworks.com/products/reinforcement-learning.html)\n\nYou can download the latest version of MATLAB from this [link](https://www.mathworks.com/downloads/). For installation instructions, follow the link [here](https://www.mathworks.com/help/install/install-products.html).\n\n# Introduction\nAfter downloading and installing MATLAB, _clone this repository_ to get the required scripts. The following two scripts can be used to train or simulate the agent.\n\n1. train_agent.m - script for creating and training a reinforcement learning agent\n2. play_agent.m - script for playing the game\n\nThe following scripts are used to create the environment:\n1. Environment.m - class for modeling the game\n2. Visualizer.m - class for animation functions\n\n##### Environment\nThe Environment for the game is a two dimensional space with a ball and a paddle. The ball starts with an initial velocity and moves around in the environment. The walls restrict the ball from moving outside the environment and also transfers some momentum to the ball on collision. For this reason there is a slight velocity change whenever the ball collides an object. The paddle is located at the bottom half and can move left to right to prevent the ball falling below.\n\n##### Agent\nA Deep Deterministic Policy Gradient (DDPG) reinforcement learning agent is used in this example. The agent learns to hit the ball by observing the following states in the environment:\n1. x, y positions of the ball\n2. x, y velocities of the ball\n3. x position of the paddle\n4. x velocity of the paddle\n5. Action values from the last time step\n\nThe action of the agent is the _force_ applied on the paddle in the x direction.\n\n# Train\nTo create an agent and run the training, open and run the **train_agent.m** script.\n\n# Play\nTo view a pre-trained agent playing the game, use the script **play_agent.m**.\n\n# Additional Resources\nFor additional resources on reinforcement learning, take a look at the following:\n- [What is reinforcement learning?](https://www.mathworks.com/discovery/reinforcement-learning.html)\n- [RL Tech talk series with Brian Douglas](https://www.mathworks.com/videos/series/reinforcement-learning.html)\n- [Free Reinforcement Learning Onramp](https://www.mathworks.com/learn/tutorials/reinforcement-learning-onramp.html)\n- [Reinforcement Learning for an Inverted Pendulum with Image Data Video](https://www.mathworks.com/videos/reinforcement-learning-for-an-inverted-pendulum-with-image-data-1549467410890.html?s_tid=srchtitle)\n- [Deep Reinforcement Learning for Walking Robots Video](https://www.mathworks.com/videos/deep-reinforcement-learning-for-walking-robots--1551449152203.html?s_tid=srchtitle)\n\n\n\n[![View Playing Pong® with deep reinforcement learning on File Exchange](https://www.mathworks.com/matlabcentral/images/matlab-file-exchange.svg)](https://www.mathworks.com/matlabcentral/fileexchange/87939-playing-pong-with-deep-reinforcement-learning)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatlab-deep-learning%2Fplaying-pong-with-deep-reinforcement-learning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatlab-deep-learning%2Fplaying-pong-with-deep-reinforcement-learning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatlab-deep-learning%2Fplaying-pong-with-deep-reinforcement-learning/lists"}