GithubHelp home page GithubHelp logo

00mjk / rl_2048 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dsgiitr/rl_2048

0.0 0.0 0.0 2.55 MB

Implementation of Deep Q-network to play the game 2048 using Keras.

Python 4.07% Jupyter Notebook 95.93%

rl_2048's Introduction

Q Learning Agent to Play 2048

Implementation of deep Q-network to play the game 2048 using Keras.

Deep Q-Learning

Q-Learning is a reinforcement learning algorithm that seeks to find the best action to take given the current state. The expected reward of a action at that step is known as the Q-Value. It is stored in a table for each state, future state tuple. For most environments keeping track of the number of possible states and all possible combinations of these state is extremely difficult. Hence instead of storing these Q-Values we approximate them using Neural networks, this is known as a Deep Q-Network. Read more at-

Project Description

For calculating the Q Values we used a Neural Network, rather than just showing the current state to the network, the next 4 possible states(left, right, up, down) were also shown. This intuition was inspired from Monte Carlo Tree Search estimation where game is played till the end to determine the Q-Values. Instead of using a normal Q Network, a Double Q Network was used one for predicting Q values and other for predicting actions. This is done to try and reduce the large overestimations of action values which result form a positive bias introduced in Q Learning. For data preprocessing log2 normalisation, training was done using the Bellman's Equation. The policy used was Epsilon greedy, to allow exploration the value of epsilon was annealed down by 5%.

Results

Fig: Max tile obtained on each game as NN training proceeds. Its visible that the model is able to learn the strategy within 600 Epochs as the number of tiles with 512 is much more towards the end.

Also from observation the model was able to learn the common heuristic amongst player to keep the maximum numbered tile at one corner and surround it with monotonically increasing tiles. This helps in combining the tiles in a series.

Repository Structure

  • DQN_Agent_2048.ipynb-Main notebook to train/test the DQN, also contains the definitions of the deep learning models
  • Game_Board.py-Module with the game logic of 2048 (uses OPENAI Gym interface)
  • DQN_Network is the Architecture of the Q Network.
  • trained_model.model-Model trained for 1000 epochs.

Installing and Running

This project requires:

  • Python (Python 3.6)
  • Numpy
  • TensorFlow
  • Keras
  • Gym (OpenAI Gym)
  • Matplotlib

Once everything is installed open the DQN_Agent_2048.ipynb file on a jupyter notebook and run the cells.

Future Work

This work is in the very elementry stage and we'd like to improve upon the following:

  • Other Networks like Actor Critic
  • Convolution Network in the Network architecture for Agent
  • Showing the subsequent 4 States of all the immideate next state so as to get better predictions(4 +4*4=16 states in total)
  • Run the game for more iterations (1,000,000)

References

rl_2048's People

Contributors

anirudhdagar avatar ishan-kumar2 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.