Fixed some bugs in agent.py
Episodes now terminate and reset the agent to the correct position.