Skip to main content

OpenAI Gym Environment for 2048

Project description

https://travis-ci.com/salmanazarr/gym-2048.svg?branch=master https://badge.fury.io/py/gym-2048.svg

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

Install

pip install gym-2048

Environment(s)

The package currently contains two environments

  • Tiny2048-v0: A 2 x 2 grid game.

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

Attributes

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

Rendering

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

Usage

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')
  env.seed(42)

  env.reset()
  env.render()

  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))
    env.render()

  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.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

gym_2048_extended-1.0-py3.10.egg (14.9 kB view details)

Uploaded Source

gym_2048_extended-1.0-py3.9.egg (16.8 kB view details)

Uploaded Source

File details

Details for the file gym_2048_extended-1.0-py3.10.egg.

File metadata

  • Download URL: gym_2048_extended-1.0-py3.10.egg
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for gym_2048_extended-1.0-py3.10.egg
Algorithm Hash digest
SHA256 bfeacd43b201bb47ba455f8c904218ccaabd04174b515d0f3d4c19e33690a435
MD5 6d3284ae61e2db445a43f63447be6d15
BLAKE2b-256 abed0adea6fdc08bd3c44ea07d31464ff293c55d485bc6b7f46085d7649ef683

See more details on using hashes here.

File details

Details for the file gym_2048_extended-1.0-py3.9.egg.

File metadata

  • Download URL: gym_2048_extended-1.0-py3.9.egg
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.1

File hashes

Hashes for gym_2048_extended-1.0-py3.9.egg
Algorithm Hash digest
SHA256 4d4b21e793e387043fb294b7f75616e074884cea71e2de3bb29d521f42891956
MD5 e933dbff68b6202e4311e08f18450abc
BLAKE2b-256 f947139de6c46220de751f76059a8b7077551051b7c59630a700236701664b42

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page