Skip to main content

OpenAI Gym Environment for 2048 extended functionality

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 Distribution

gym-2048-extended-1.3.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

gym_2048_extended-1.3-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file gym-2048-extended-1.3.tar.gz.

File metadata

  • Download URL: gym-2048-extended-1.3.tar.gz
  • Upload date:
  • Size: 7.6 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.3.tar.gz
Algorithm Hash digest
SHA256 0096483e1f2be21edbf529933a48d80ec3956dc2be268ab6aa134c579e461c0a
MD5 5bcb0e9a6b9f98f3bcaf2a125d7aa859
BLAKE2b-256 0502cd2dc8ec91327a1a92d4d894d08637235907c7bb32dd147461dcdc689bb0

See more details on using hashes here.

File details

Details for the file gym_2048_extended-1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for gym_2048_extended-1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 040c6c303ecf2376e97dee63b5ea341d7a82e714153abaefd77f5adb77b60c79
MD5 57d07304644e3a2b677e425574b3101e
BLAKE2b-256 0ac4c2728379b38ed81d84ec178069cd547e7e2be3325cb43ef419049df0f7b9

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