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

Fighting greed #478

Open
erik-vos opened this issue Aug 22, 2022 · 2 comments
Open

Fighting greed #478

erik-vos opened this issue Aug 22, 2022 · 2 comments

Comments

@erik-vos
Copy link
Contributor

Copying a comment of mine in #435: (see next comment for additional info)

I think I have found another case where a valid rotation is not allowed. It is in 1826 that I'm now working on.
1825-Rotation-problem
The green tile 23 that I'm trying to lay on the hex NW of Paris is only allowed in this rotation, not in the equally valid 180° rotated one.

Muddling through the rotation code jungle, the root cause seems to be that the SE side of that hex is marked as "GREEDY".*
Does that really mean that no token is present behind that side (i.e. in Paris NW)? Well, that token is there, and the train routing code finds it well enough, see the pink line.

Is there anyone around who can explain this?

Talking about greediness, there are four possible enum values for that field: SEEN, DONE, GREEDY and NOT_GREEDY.
No documentation, of course. Can anyone explain the meaning of these values to me?

This all looks needlessly complicated. I'm thinking of replacing the code to find valid tile rotations by just a simple check: is there a token in any given direction, or not.

I don't know if the Chesapeake problem has the same cause, perhaps it is worth a check.

* See NetworkGraph.getReachableSides().126

@erik-vos
Copy link
Contributor Author

This is the code fragment that I'm talking about:

if (vertex.isSide() && iterator.getSeenData().get(vertex) != NetworkIterator.greedyState.GREEDY ) {

When I disable the GREEDY check, so the code becomes

if (vertex.isSide()) {

then the problem disappears: I can happily lay tile 23 both ways, including (in a somewhat different situation):

afbeelding

However, this change does not fix the 1830 routing bug in #221 (1830) and the rotation failure in #435 (18Ches).

I'm currently testing with saved files from various games to check if this deletion affects route finding and revenue calculations in any way, but so far all seems OK. If it stays this way, and lacking any info on what GREEDY really means, I may decide to apply this fix to the code base.

@erik-vos
Copy link
Contributor Author

I have further tested in several ways:

  • Running long or even completed saved games of several games (1830, 1835, 1851, 1856, 1880, 1889, 18AL, 18EU) and compared the reports with and without the fix. No relevant differences showed up.
  • Checked possible tile laying actions in a few ORs of several of the above games. No invalids were found.

Of course this is not a complete proof of the harmlessness of removing the GREEDY check. But I am confident that any glitches will be absent or rare. I remain open to demonstrations to the contrary.

I will add this fix to the currently open PR #471.

erik-vos pushed a commit to erik-vos/Rails that referenced this issue Aug 24, 2022
The check in NetworkGraph.getReachableSides() on an edge having GREEDY status has been disabled. This resolves issue Rails-18xx#478.

Also a bug in ListAndFixSavedFiles that mixed up Stop and Station numbers has been fixed.
@erik-vos erik-vos changed the title Fighting greediness Fighting greed Aug 26, 2022
erik-vos pushed a commit to erik-vos/Rails that referenced this issue Oct 30, 2022
The check in NetworkGraph.getReachableSides() on an edge having GREEDY status has been disabled. This resolves issue Rails-18xx#478.

Other fixes:
 - A bug in ListAndFixSavedFiles that mixed up Stop and Station numbers.
 - Distances from tokenable stops to the nearest base token went wrong when hexes had multiple cities on one hex
 (e.g. Paris in 1826).
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

No branches or pull requests

1 participant