MouseyPounds / stardew-predictor

Predictions of not very random events in Stardew Valley
MIT License
100 stars 30 forks source link

Resort visitors #15

Open 1JackBlack1 opened 2 years ago

1JackBlack1 commented 2 years ago

I notice that you have resort visitors in the file but aren't displaying it. I was looking into it and noticed that the code you have doesn't match that produced by ILSpy. You have: 1.21*save.gameID + 2.5*(day + save.dayAdjust) As the seed for the random number generator, but the code produced by ILSpy converts these both to integers before combining them, which produces a different result.

Could that be the cause of why it appears so random?

1JackBlack1 commented 2 years ago

Some other things I noticed in comparison: ILSpy excludes the night market as well (Winter 15 to 17) ILSpy also excludes Pam and Emily on the 15th of Fall. So the generated list would be wrong on that date.

For Marnie, ILSpy has : if (npc.Name == "Marnie" && day != "Tue" && day != "Mon") which just excludes monday and tuesday, but you have if (who === "Marnie" && (weekDay !== 1 || weekDay !== 2)) { This would prevent Marnie from ever going to the island and get the list of visitors wrong on Monday and Tuesday, getting their predictions wrong as well.

And Robin should have the hospital visit on day 46, but you had 44.

But even after these fixes it still isn't entirely correct. So I'm investigating more.

1JackBlack1 commented 2 years ago

And I think I may have found the issue, and quickly skimming the code I think this is the only place it will appear, and it directly relates to the first point I found. This is the only significant location in your predictor that deals with floating point numbers in the seed (the closest you get otherwise is dividing by 2). And one of the numbers involved (the game id) is quite large.

Javascript using 64 bits for these numbers, but c# only uses 32 bits.

This causes rounding errors for the generation of the seed. So the seed actually needs to be (or equivalent to): parseInt(Math.fround(1.21*Math.fround(save.gameID))) + parseInt(Math.fround(2.5*(day + save.dayAdjust)))

I'll check to see if this works over the next few days in game

1JackBlack1 commented 2 years ago

And checking, it works for the current day (i.e. the day the save is when it is loaded into the predictor), and it works for groups. But due to the NPCs getting ordered differently each night, it doesn't work otherwise (although normally it could be narrowed down to a group until it gets to a group with a child).