{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE InstanceSigs #-}
module Environments.Gym.ClassicControl.MountainCarV0
( Action(..)
, I.Runner
, State(..)
, Environment
, EnvironmentT
, Environments.Gym.ClassicControl.MountainCarV0.runEnvironment
, Environments.Gym.ClassicControl.MountainCarV0.runEnvironmentT
, Environments.Gym.ClassicControl.MountainCarV0.runDefaultEnvironment
, Environments.Gym.ClassicControl.MountainCarV0.runDefaultEnvironmentT
) where
import Reinforce.Prelude hiding (State)
import Control.MonadEnv
import Environments.Gym.Internal hiding (runEnvironment)
import qualified Environments.Gym.Internal as I
import Data.Aeson.Types
import OpenAI.Gym (GymEnv(MountainCarV0))
data State = State
{ position :: Float
, velocity :: Float
} deriving (Show, Eq, Generic, Ord, Hashable)
instance FromJSON State where
parseJSON :: Value -> Parser State
parseJSON arr@(Array _)= do
(a, b) <- parseJSON arr :: Parser (Float, Float)
return $ State a b
parseJSON invalid = typeMismatch "Environment State" invalid
data Action = MoveLeft | DoNothing | MoveRight
deriving (Enum, Bounded, Ord, Show, Eq, Generic, Hashable)
instance ToJSON Action where
toJSON :: Action -> Value
toJSON = toJSON . subtract 1 . fromEnum
type EnvironmentT t = GymEnvironmentT State Action t
type Environment = EnvironmentT IO
runEnvironmentT :: MonadIO t => Manager -> BaseUrl -> I.RunnerT State Action t x
runEnvironmentT = I.runEnvironmentT MountainCarV0
runEnvironment :: Manager -> BaseUrl -> I.RunnerT State Action IO x
runEnvironment = I.runEnvironmentT MountainCarV0
runDefaultEnvironmentT :: MonadIO t => I.RunnerT State Action t x
runDefaultEnvironmentT = I.runDefaultEnvironmentT MountainCarV0
runDefaultEnvironment :: I.RunnerT State Action IO x
runDefaultEnvironment = I.runDefaultEnvironmentT MountainCarV0
instance (MonadThrow t, MonadIO t) => MonadEnv (EnvironmentT t) State Action Reward where
reset = I._reset
step = I._step