No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
.travis.yml
README.md
dub.json
example.d
gym.d
gym_http_server.py
requirements.txt

README.md

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