Skip to main content

OpenAI Gym Environment for 2048

Project description

This package implements the classic grid game 2048 for OpenAI gym environment.


pip install gym-2048


The package currently contains two environments

  • Tiny2048-v0: A 2 x 2 grid game.
  • 2048-v0: The standard 4 x 4 grid game.


  • Observation: All observations are n x n numpy arrays representing the grid. The array is 0 for empty locations and numbered 2, 4, 8, ... wherever the tiles are placed.
  • Actions: There are four actions defined by integers.
    • LEFT = 0
    • UP = 1
    • RIGHT = 2
    • DOWN = 3
  • Reward: Reward is the total score obtained by merging any potential tiles for a given action. Score obtained by merging two tiles is simply the sum of values of those two tiles.


Currently only basic print rendering (mode='human') is supported. Graphic rendering support is coming soon.


Here is a sample rollout of the game which follows the same API as OpenAI gym.Env.

import gym_2048
import gym

if __name__ == '__main__':
  env = gym.make('2048-v0')


  done = False
  moves = 0
  while not done:
    action = env.np_random.choice(range(4), 1).item()
    next_state, reward, done, info = env.step(action)
    moves += 1

    print('Next Action: "{}"\n\nReward: {}'.format(
      gym_2048.Base2048Env.ACTION_STRING[action], reward))

  print('\nTotal Moves: {}'.format(moves))

NOTE: Top level import gym_2048 is needed to ensure registration with Gym.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for gym-2048, version 0.2.6
Filename, size File type Python version Upload date Hashes
Filename, size gym-2048-0.2.6.tar.gz (4.6 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page