Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Encountering two-way red signals could prune unrelated branches. #9271

Merged
merged 1 commit into from May 23, 2021

Conversation

vituscze
Copy link
Contributor

Motivation / Problem

The pathfinder sometimes makes weird decisions when encountering a two-way red signal (with yapf.rail_firstred_twoway_eol on). Most recently spotted in this game: prune_bug.zip

This problem has also been reported in #6637

Description

The core of the issue is that when the pathfinder encounters a two-way red signal, it starts pruning the branch leading to the best intermediate node. However, this does not work in two cases:

  1. the branches corresponding to the best intermediate node and the two-way red node are completely unrelated, in which case the pathfinder simply prunes the wrong branch
  2. the intermediate node branch is a subset of the two-way red node branch and there is a node whose segment ends due to ESRB_CHOICE_FOLLOWS between those two nodes, in which case no pruning should be done

The 1. case is self-explanatory. For the 2. case, you can take a look at the attached savegame. The pathfinder:

  • discovers the two-way red signal node, prunes (there was no intermediate node, so nothing happens)
  • discovers the depot, sets it as the intermediate node
  • discovers the choice leading from the depot, its distance to the target is worse than the intermediate, so nothing happens
  • discovers the two-way red signal once again, prunes the depot node (intermediate node is now nullptr)

The PR solves these issues by first checking whether the intermediate node lays on the path between the two-way signal node and the preceding "choice follows" node and only prunes if that is the case.

Limitations

No known limitations.

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

The intermediate node branch is now only pruned if the node is on the
path leading to the two-way red signal.
@rubidium42 rubidium42 merged commit 33d99d2 into OpenTTD:master May 23, 2021
@vituscze vituscze deleted the branch-pruning-fix branch May 23, 2021 20:07
@rubidium42 rubidium42 added the backport requested This PR should be backport to current release (RC / stable) label May 29, 2021
@TrueBrain TrueBrain removed the backport requested This PR should be backport to current release (RC / stable) label Oct 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants