Tsangares / stoned_ape_tools

Plugin code for a Neptune's Pride Plugin oriented around making communication between alliances easier.
GNU General Public License v3.0
5 stars 5 forks source link

Multiple carriers attacking a star predicts fractional ships #29

Open Skilly146 opened 1 year ago

Skilly146 commented 1 year ago

What

When multiple carriers are attacking the same star it correctly distributes the survivors among the carriers but it also shows a decimal remaining instead of rounding the numbers, or more accurately rounding the highest fraction up and the remaining ones down. This definitely happens with multiple carriers owned by the same player (As Paralax showed on the discord) and looking at the code I would think it happens with multiple players as well

How

The problem is in the for (const k in contribution) loop at line 712. The best solution would probably be adding a variable that stores whichever carrier had the last fraction of remaining ships in an additional biggest_fraction variable defined before the loop. Simply compare the fraction of the current carrier from contribution to the biggest_fraction variable (using number - number.trunc()) and if it's bigger redefine biggest_fraction. The trouble I had with it was that its best done by moving lines 728-730

output.push("[[{0}]] has {1} on [[{2}]]".format(fleet.puid, contribution[k], fleet.n));
let outcomeString = "Wins! {0} land.".format(contribution[k]);
fleetOutcomes[fleet.uid] = { eta: tickToEtaString(fleet.etaFirst), outcome: outcomeString };

to outside of the loop and instead have them read a list created by the loop. That list would then be for looped through one more time to truncate all of the contribution[k] variables except for carrier stored in biggest_fraction which would be rounded up.

Tsangares commented 1 year ago

@Skilly146 Is the consensus to give to the first carrier or round them all down?

anicolao commented 1 year ago

According to the thread I started on the forums all the fractions should be truncated and the left over ships should be given round robin from the largest starting fleet to the smallest.