bugger.
RL environments/Pythoneasyrl-lineworld-v1
IMPLEMENTATION LAB

Implement reset and step in LineWorld

Build a three-cell episode and distinguish a goal from a time limit.

RL Environments

Your task

A policy moves through cells 0, 1, and 2. The starter returns an empty trace. Implement the environment transition and collect the results in solve(data).

Input has start and goal (distinct cells from 0 through 2), a positive step limit, and a list of actions. Each action is left or right. Clamp walks at both edges. After each action return observation (the new cell), reward (1 on reaching the goal, otherwise 0), terminated (goal reached), and truncated (the step count reached the limit). The flags are independent, so both can be true on the same step. Stop after either flag. Print one JSON object with trace, an array of these results.

Expected behavior

Record one transition per executed action, including the final observation. Ignore actions after the episode ends.

Examples

01 Right, right reaches the goal
{"start":0,"goal":2,"limit":3,"actions":["right","right","left"]}
{"trace":[{"observation":1,"reward":0,"terminated":false,"truncated":false},{"observation":2,"reward":1,"terminated":true,"truncated":false}]}
02 Repeated left hits the limit
{"start":0,"goal":2,"limit":3,"actions":["left","left","left","left"]}
{"trace":[{"observation":0,"reward":0,"terminated":false,"truncated":false},{"observation":0,"reward":0,"terminated":false,"truncated":false},{"observation":0,"reward":0,"terminated":false,"truncated":true}]}
03 An empty action sequence has no transitions
{"start":0,"goal":2,"limit":3,"actions":[]}
{"trace":[]}

Before you begin

  • Python functions, lists, and dictionaries

Need a nudge?

Reveal one investigation hint at a time. Try each clue before opening the next.

    Run the examples, then submit to check the full contract.
    Read-only preview
    Ready when you are
    Every fix starts with a failing test.

    Read the report, then sign in to start your investigation.