Git Product home page Git Product logo

gym-2048's Introduction

Gym 2048

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

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.

gym-2048's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.