Rails icon indicating copy to clipboard operation
Rails copied to clipboard

Fighting greed

Open erik-vos opened this issue 3 years ago • 2 comments

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 avatar Aug 22 '22 19:08 erik-vos

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 avatar Aug 22 '22 20:08 erik-vos

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 avatar Aug 24 '22 20:08 erik-vos