Rails-18xx / Rails

Rails 18xx Java Application Main Repository
GNU General Public License v2.0
36 stars 22 forks source link

Fighting greed #478

Open erik-vos opened 2 years ago

erik-vos commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

I have further tested in several ways:

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.