Skip to content

2048 is a simple mathematics puzzle game. It is a really addictive game and the main operation performed in this game is addition which makes it easy for all of us.

Notifications You must be signed in to change notification settings

githubcrce/2048

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

2048 Game + DQN Reinforcement Learning Agent

This project contains:

  • A clean 2048 game environment (like OpenAI Gym style)
  • A Deep Q-Network (DQN) agent built using PyTorch
  • A training loop to learn how to play 2048
  • Modular, easy-to-extend code

πŸš€ How to Run

1. Install Requirements

pip install -r requirements.txt

2. Train the DQN Agent

python dqn_2048_game.py

Training will print average score every 100 episodes.


πŸ“¦ Project Structure

.
β”œβ”€β”€ dqn_2048_game.py     # Full Game + DQN training
β”œβ”€β”€ requirements.txt      # Dependencies
β”œβ”€β”€ README.md             # You're reading it!

🧠 How It Works

  • Environment: 2048 board (4x4), states are normalized grids
  • Actions: 0 = Up, 1 = Down, 2 = Left, 3 = Right
  • Rewards: Based on increase in board tile sum; small penalty for invalid move
  • Algorithm: Standard DQN with:
    • Experience Replay
    • Target = Bellman Equation (reward + discounted future reward)

πŸ“ˆ Future Upgrades

  • Add Target Networks (DQN stabilization)
  • Use DDQN (Double DQN)
  • Prioritized Experience Replay
  • Add TensorBoard logging
  • Play with a trained agent (inference mode)

πŸ“œ Requirements

See requirements.txt below.


requirements.txt

torch
numpy

(You only need torch and numpy for this basic version!)


πŸ† Credits

Built for fun and learning reinforcement learning principles with a classic game: 2048.


✨ Enjoy training your AI to beat 2048!

About

2048 is a simple mathematics puzzle game. It is a really addictive game and the main operation performed in this game is addition which makes it easy for all of us.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages