use anyhow::Result; use border_core::{record::BufferedRecorder, util, Env as _, Policy}; use border_py_gym_env::{ PyGymEnv, PyGymEnvActFilter, PyGymEnvConfig, PyGymEnvContinuousAct, PyGymEnvContinuousActRawFilter, PyGymEnvObs, PyGymEnvObsFilter, PyGymEnvObsRawFilter, }; use ndarray::Array; use std::default::Default; type Obs = PyGymEnvObs; type Act = PyGymEnvContinuousAct; type ObsFilter = PyGymEnvObsRawFilter; type ActFilter = PyGymEnvContinuousActRawFilter; type Env = PyGymEnv; #[derive(Clone)] struct RandomPolicyConfig; struct RandomPolicy; impl Policy for RandomPolicy { type Config = RandomPolicyConfig; fn build(_config: Self::Config) -> Self { Self } fn sample(&mut self, _: &Obs) -> Act { Act::new( Array::from( (0..8) .map(|_| 2f32 * fastrand::f32() - 1f32) .collect::>(), ) .into_dyn(), ) } } fn main() -> Result<()> { env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init(); fastrand::seed(42); let env_config = PyGymEnvConfig::default() .name("AntPyBulletEnv-v0".to_string()) .obs_filter_config(>::Config::default()) .act_filter_config(>::Config::default()) .pybullet(true) .render_mode(Some("human".to_string())); let mut env = Env::build(&env_config, 0)?; let mut recorder = BufferedRecorder::new(); let mut policy = RandomPolicy; env.set_render(true); let _ = util::eval_with_recorder(&mut env, &mut policy, 5, &mut recorder)?; Ok(()) } #[test] fn test_random_ant() { fastrand::seed(42); let env_config = PyGymEnvConfig::default() .name("AntPyBulletEnv-v0".to_string()) .obs_filter_config(>::Config::default()) .act_filter_config(>::Config::default()) .pybullet(true); let mut env = Env::build(&env_config, 0).unwrap(); let mut recorder = BufferedRecorder::new(); let mut policy = RandomPolicy; let _ = util::eval_with_recorder(&mut env, &mut policy, 1, &mut recorder).unwrap(); }