added terminal function and reward function to inverted pendulum