Code Monkey home page Code Monkey logo

playing-pong-with-deep-reinforcement-learning's Introduction

Train Deep Reinforcement Learning Agent to Play a Variation of Pong®

This example demonstrates a reinforcement learning agent playing a variation of the game of Pong® using Reinforcement Learning Toolbox™. You will follow a command line workflow to create a DDPG agent in MATLAB®, set up hyperparameters and then train and simulate the agent.

Anim

Prerequisites

This example requires installation of the following software:

  1. MATLAB R2020b or later
  2. Deep Learning Toolbox™
  3. Reinforcement Learning Toolbox

You can download the latest version of MATLAB from this link. For installation instructions, follow the link here.

Introduction

After 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.

  1. train_agent.m - script for creating and training a reinforcement learning agent
  2. play_agent.m - script for playing the game

The following scripts are used to create the environment:

  1. Environment.m - class for modeling the game
  2. Visualizer.m - class for animation functions
Environment

The 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.

Agent

A 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:

  1. x, y positions of the ball
  2. x, y velocities of the ball
  3. x position of the paddle
  4. x velocity of the paddle
  5. Action values from the last time step

The action of the agent is the force applied on the paddle in the x direction.

Train

To create an agent and run the training, open and run the train_agent.m script.

Play

To view a pre-trained agent playing the game, use the script play_agent.m.

Additional Resources

For additional resources on reinforcement learning, take a look at the following:

View Playing Pong® with deep reinforcement learning on File Exchange

playing-pong-with-deep-reinforcement-learning's People

Contributors

man7therakis avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.