Giter Club home page Giter Club logo

gym-coders-strike-back's Introduction

gym-coders-strike-back

This environment is an implementation of the Coders Strike Back contest, hosted by the Codin Game website.

Only single game mode is implemented, i.e. you can control only one pod through a random set of checkpoints, and the game finish when you reach the final checkpoint.

Installation

git clone https://github.com/alenic/gym-coders-strike-back
cd gym-coders-strike-back
python setup.py install

Usage

This piece of code simulates a single episode with this simple policy: go to the next checkpoint with a constant thrust

import gym
from gym_coders_strike_back import *
import time
import numpy as np

env = gym.make('CodersStrikeBack-v0')
fps =  env.metadata.get('video.frames_per_second')

totalReward = 0.0
# Set pseudorandom seed for the getting the same game
env.seed(1234)
state = env.reset()
for i in range(1,10000):
    # display the game
    render = env.render()
    if not render:
        break
    # Take action (simple policy)
    targetX, targetY = state[5:7]
    thrust = 60
    action = np.array([targetX, targetY, thrust], dtype=np.float32)
    # Do a game step
    state, reward, done, _ = env.step(action)

    # Print the state
    
    print('---------- Tick %d' % i)
    print('Pod angle ', state[0])
    print('Pod (x,y): (%d, %d)' % (state[1], state[3]))
    print('Pod velocity (v_x,v_y): (%d, %d)' % (state[2], state[4]))
    print('First Checkpoint (x,y): (%d, %d)' % (state[5],state[6]))
    print('Second Checkpoint (x,y): (%d, %d)' % (state[7],state[8]))
    print('Reward ', reward)
    print('done ', done)

    totalReward += reward
    # Slow down the cycle for a realistic simulation
    time.sleep(1.0/fps)

    # The game end if the flag done is True
    if done:
        break

print("Total reward: ", totalReward)
env.close()

gym-coders-strike-back's People

Contributors

alenic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gym-coders-strike-back's Issues

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.