Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,4 @@ API specification
Contributors
============

See the [contributors page] (https://github.com/openai/gym-http-api/graphs/contributors)
See the [contributors page](https://github.com/openai/gym-http-api/graphs/contributors)
5 changes: 3 additions & 2 deletions binding-rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ authors = ["NivenT <[email protected]>"]

[dependencies]
rand = "0.3.14"
serde_json = "0.8.0"
hyper = "0.9.12"
serde = "1.0.10"
serde_json = "1.0.2"
reqwest = "0.7.1"
12 changes: 6 additions & 6 deletions binding-rust/examples/random_agent.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
extern crate gym;

use gym::*;
use gym::GymClient;

fn main() {
println!("**********************************");

let mut client = GymClient::new("http://localhost:5000".to_string());
//println!("already running environments:\n{:?}\n", client.get_envs().unwrap());
let client = GymClient::new("http://localhost:5000".to_string()).unwrap();
println!("already running environments:\n{:?}\n", client.get_envs().unwrap());

let mut env = match client.make("CartPole-v0") {
let env = match client.make("CartPole-v0") {
Ok(env) => env,
Err(msg) => panic!("Could not make environment because of error:\n{}", msg)
};

//println!("observation space:\n{:?}\n", env.observation_space());
//println!("action space:\n{:?}\n", env.action_space());
println!("observation space:\n{:?}\n", env.observation_space());
println!("action space:\n{:?}\n", env.action_space());

let _ = env.monitor_start("/tmp/random-agent-results".to_string(), true, false);
for ep in 0..10 {
Expand Down
44 changes: 44 additions & 0 deletions binding-rust/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use std::error::Error;
use std::fmt;

use serde_json;

use reqwest;

pub type GymResult<T> = Result<T, GymError>;

#[derive(Debug)]
pub enum GymError {
Connection(reqwest::Error),
Json(serde_json::Error)
}

impl fmt::Display for GymError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
GymError::Connection(ref err) => fmt::Display::fmt(err, f),
GymError::Json(ref err) => fmt::Display::fmt(err, f),
}
}
}

impl Error for GymError {
fn description(&self) -> &str {
match *self {
GymError::Connection(ref err) => err.description(),
GymError::Json(ref err) => err.description()
}
}
}

impl From<reqwest::Error> for GymError {
fn from(err: reqwest::Error) -> GymError {
GymError::Connection(err)
}
}

impl From<serde_json::Error> for GymError {
fn from(err: serde_json::Error) -> GymError {
GymError::Json(err)
}
}
Loading