I am trying to set up the OpenAI gym environment for the Taxi - V3 application in Google Colab and using the following code :
from IPython.display import clear_output
import gym
env = gym.make("Taxi-v3", render_mode = 'ansi').env
#env = gym.make("Taxi-v3", render_mode = 'ansi')
Then I have a function that shows the Taxi position in the Colab cell
def showStateVec(txR=3, txC=1,pxI=2,des=0):
env.reset()
state = env.encode(txR,txC,pxI,des)
env.s = state
print("State ", env.s, list(env.decode(env.s)))
env.s = state
p = env.render()
print(p[0])
for k,v in env.P[state].items():
print(v)
When I call
# taxi at 3,1, passenger at 2, destination = 0
# note, moving to the WEST is not possible, the position does not change
showStateVec(3,1,2,0)
I get the following output ( i have replaced the yellow box with 'x'). Evidently, this is not correct. The taxi is being somewhere else
State 328 [3, 1, 2, 0]
+---------+
|R: |x: :G|
| : | : : |
| : : : : |
| | : | : |
|Y| : |B: |
+---------+
[(1.0, 428, -1, False)]
[(1.0, 228, -1, False)]
[(1.0, 348, -1, False)]
[(1.0, 328, -1, False)]
[(1.0, 328, -10, False)]
[(1.0, 328, -10, False)]
However if I run the command again a second time, the yellow box moves elsewhere, even though the rest of the output is identical
State 328 [3, 1, 2, 0]
+---------+
|R: | : :G|
| : | : : |
| : : : : |
| | : | : |
|Y| :x|B: |
+---------+
[(1.0, 428, -1, False)]
[(1.0, 228, -1, False)]
[(1.0, 348, -1, False)]
[(1.0, 328, -1, False)]
[(1.0, 328, -10, False)]
[(1.0, 328, -10, False)]
Here is the link to the Colab notebook where you can replicate the problem. I have also seen this and other solutions in stackoverflow but none seem to work.
What should I do to ensure that the taxi ( or the yellow box representing the taxi) is displayed exactly where the state of the taxi says it should be. Please help.