Skip to content

[Bug Report] Rainy Taxi is inconsistent in left and right #1510

@dm-ackerman

Description

@dm-ackerman

Describe the bug

The rainy taxi has an 80% change to move as intended, a 10% chance to go left of course, 10% chance to go right. The left/right should be relative to the direction of motion. From the original paper, "probability 0.1 it instead moves to the right (of the intended direction) and with probability 0.1 it moves to the left".

They are not consistent in the code, which reverses them for some directions. More importantly, the test for valid movements seems to assume movements are to the left and right based on a north heading, regardless of actual motion. This blocks some moves that should be allowed.

Example, in the image below with the taxi at (1,3), all movements are valid. However the left and right are not consistent
Image

The transitions are:

If moving SOUTH, outcomes are
   With probability 0.8 move ahead to (2, 3) 
   With probability 0.1 move left  to (1, 2)  <--- actually right
   With probability 0.1 move right to (1, 4)   <--- actually left
If moving NORTH, outcomes are
   With probability 0.8 move ahead to (0, 3) 
   With probability 0.1 move left  to (1, 2) 
   With probability 0.1 move right to (1, 4) 
If moving EAST, outcomes are
   With probability 0.8 move ahead to (1, 4) 
   With probability 0.1 move left  to (2, 3)  <--- actually right 
   With probability 0.1 move right to (0, 3)   <--- actually left
If moving WEST, outcomes are
   With probability 0.8 move ahead to (1, 2) 
   With probability 0.1 move left  to (2, 3) 
   With probability 0.1 move right to (0, 3) 

If the taxi is one step to the east (location 1,4) , the invalid moves should be: EAST (and left/right of east), NORTH right, SOUTH left. All other moves should be valid
Image

The actual transitions are:

If moving SOUTH, outcomes are
   With probability 0.8 move ahead to (2, 4) 
   With probability 0.1 move left  to (1, 3) 
   With probability 0.1 move right to (1, 4) (no movement - move blocked)  <-- wrong: left/right swapped
If moving NORTH, outcomes are
   With probability 0.8 move ahead to (0, 4) 
   With probability 0.1 move left  to (1, 3) 
   With probability 0.1 move right to (1, 4) (no movement - move blocked)  <-- correct
If moving EAST, outcomes are
   With probability 0.8 move ahead to (1, 4) (no movement - move blocked)  <-- correct
   With probability 0.1 move left  to (1, 4) (no movement - move blocked)  <-- correct
   With probability 0.1 move right to (1, 4) (no movement - move blocked)  <-- correct
If moving WEST, outcomes are
   With probability 0.8 move ahead to (1, 3) 
   With probability 0.1 move left  to (1, 4) (no movement - move blocked) <-- wrong: completely wrong
   With probability 0.1 move right to (0, 4)

Code example

from gymnasium.envs.toy_text.taxi import TaxiEnv

env = TaxiEnv(is_rainy=True)

# taxi_loc = (1, 3)  # example 1
taxi_loc = (1, 4)  # example 2
pax_loc = 0
pax_dest = 1
state = env.encode(taxi_loc[0], taxi_loc[1], pax_loc, pax_dest)

actions = {'SOUTH': 0, 'NORTH': 1, 'EAST': 2, 'WEST': 3}
directions = ["ahead", "left ", "right"]

for action_name, action in actions.items():
    print(f"If moving {action_name}, outcomes are")
    for direction, (prob, new_state, _, _) in zip(directions, env.P[state][action]):
        new_taxi_x, new_taxi_y, _, _ = env.decode(new_state)
        new_taxi_loc = (new_taxi_x, new_taxi_y)
        note = "(no movement - move blocked)" if new_taxi_loc == taxi_loc else ""
        print(f"   With probability {prob} move {direction} to {new_taxi_loc} {note}")

System info

installed from latest source

gymnasium.__version__ = '1.2.3'

Additional context

I believe I know the cause of this and can fix it along with #1509

Does this require a version bump because the behavior changes?

Checklist

  • I have checked that there is no similar issue in the repo

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions