d-openai-gym ~master

OpenAI gym binding


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

D openai gym

Build Status Dub version

D-language binding / DUB package of https://github.com/openai/gym-http-api

usage

random agent in example.d

import gym : Environment, Discrete;
import std.range : iota;
import std.random : choice;
import std.stdio : writefln, writeln;

void main() {
    auto env = Environment("127.0.0.1:5000", "CartPole-v0");
    env.record("/tmp/gym-d");
    scope(exit) env.stop();

    foreach (episode; 0 .. 10) {
        auto totalReward = 0.0;
        auto n = cast(size_t) Discrete.from(env.actionInfo);
        for (auto state = env.reset(); !state.done;) {
            auto action = choice(iota(n)); // left/right
            state = env.step(action, true); // render
            totalReward += state.reward;
            writeln(state);
        }
        writefln!"total reward %f"(totalReward);
    }
}

how to run

$ pip install -r requirements.txt
$ python gym_http_server.py &
$ rdmd example.d
$ kill %1
Authors:
  • skarita
Dependencies:
none
Versions:
0.0.1 2018-Jul-10
~master 2018-Jul-10
Show all 2 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 5 downloads total

Score:
0.7
Short URL:
d-openai-gym.dub.pm