Skip to content

feat: add track completion detection and comprehensive environment guide#138

Open
EldarAlvik wants to merge 2 commits intotrackmania-rl:masterfrom
EldarAlvik:master
Open

feat: add track completion detection and comprehensive environment guide#138
EldarAlvik wants to merge 2 commits intotrackmania-rl:masterfrom
EldarAlvik:master

Conversation

@EldarAlvik
Copy link

@EldarAlvik EldarAlvik commented Nov 8, 2025

Thank you for the project and wanted to contribute a bit with some extra documentation that i have gotten from working on the gym environment using the get_environment method and added info extraction about if the agent has reached the finish line. also a tiny semantics thing for compute reward.

Changes

1. Add reached_finishline flag (tmrl/custom/tm/tm_gym_interfaces.py)

  • Explicitly indicates successful track completion in info dict
  • Solves ambiguity: episodes end for multiple reasons (success, timeout, off-course)
  • Enables getting a rough time for completteion
  • Backward compatible

2. Create gymnasium environment documentation (readme/tmrl_gym_enviroment.md)

  • Moved existing documentation from README to dedicated guide
  • More in-depth explanation of how to setup and use TMRL as purely a Gym environment

3. Link gymnasium environment guide in README (README.md)

**4. Updated terminated/truncated semantics slightly for tmrl/custom/tm/utils/compute_reward.py

  • Rename terminatedtruncated for timeout/off-track failures
  • Follows Gymnasium spec: terminated = goal state, truncated = constraint violation
  • Only crossing finish line is true termination

Testing

  • Tested with python -m tmrl --test
  • Tested with TMRL standard running workflow with server, trainer and worker.
  • Tested with custom agent using get_environment().

@EldarAlvik EldarAlvik force-pushed the master branch 2 times, most recently from 7bff043 to 42f93df Compare November 8, 2025 02:27
Add reached_finishline flag to info dict and create detailed documentation
for using the TrackMania Gymnasium environment.

Changes:
- Add 'reached_finishline' boolean flag to info dict in all TM2020 interfaces
  - Available in TM20FULL, TM20LIDAR, and TM20LIDARPROGRESS environments
  - Allows users to reliably detect successful track completion
  - Backward compatible with existing code

- Create comprehensive environment guide (readme/tmrl_gym_enviroment.md)
  - Setup instructions and verification steps
  - Detailed observation structures for all environment types
  - Action space documentation (continuous vs discrete)
  - Usage examples and best practices
  - Troubleshooting section for ViGEm controller issues
  - Complete config.json example
  - Include troubleshooting image (Nefarius2.png)

- Update README.md with link to new environment guide
- Fix reward computation to properly handle race completion
@yannbouteiller
Copy link
Member

yannbouteiller commented Nov 10, 2025

Nice, thanks for the contribution, I will try to look into it soon.

I am unsure about what you are describing regarding the distinction between termination and truncation, though. The way I understand it, termination means MDP terminal state (which includes going off-limits) whereas truncation means episode truncated in a non-terminal state (i.e., ending the episode due to some non-observable constraint, typically time limit - the point is that an episode should not be considered terminated in a truncated state, i.e., the value function should not be considered 0 at that time, as the constraint is not part of the MDP ; the off-limits constraint is clearly a terminal state: the entire point of this constraint is to set the value function to 0 when the car strays too far from the road)

@EldarAlvik
Copy link
Author

ok. i guess it could be argued either way as the agent could continue acting. But after looking at how car_racing handles it i agree with you. I updated the pull request and undid the change and updated the readme

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants