Skip to content

Abhishek741119/2048-in-python

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

148 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

2048 in Python

Deep Q-Learning Project to play 2048.

How does the game 2048 work?

2048 is played on a gray 4×4 grid, with numbered tiles that slide smoothly when a player moves them using the four arrow keys. Every turn, a new tile will randomly appear in an empty spot on the board with a value of either 2 or 4. Tiles slide as far as possible in the chosen direction until they are stopped by either another tile or the edge of the grid. If two tiles of the same number collide while moving, they will merge into a tile with the total value of the two tiles that collided. The resulting tile cannot merge with another tile again in the same move.

A scoreboard on the upper-right keeps track of the user's score. The user's score starts at zero, and is incremented whenever two tiles combine, by the value of the new tile. As with many arcade games, the user's best score is shown alongside the current score.

The game is won when a tile with a value of 2048 appears on the board, hence the name of the game. After reaching the 2048 tile, players can continue to play (beyond the 2048 tile) to reach higher scores. When the player has no legal moves (there are no empty spaces and no adjacent tiles with the same value), the game ends.

How to run the code?

Install TensorFlow, python & pip. Then, run:

pip install -r requirements.txt

To run the code, you'll need to update your PYTHONPATH:

source set_pythonpath.sh

Now, you should be able to run start learning, 'train_dir' is a training directory (which should either not exist, or contain a previous training run to continue training):

learning.py train_dir

Within the model.py file the INIT_LEARNING_RATE, and HIDDEN_SIZES can be changed. Within experience_batcher.py the BATCH_SIZE and MIN_EPSILON can be changed. Within target_batch_computer.py the GAMMA, and rewards can be specified.

Source Code Structure

All python source code is in rl_2048.

About

Python implementation for the 2048 Game. The game learns itself by using Reinforcement Learning

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 99.9%
  • Shell 0.1%