Change: Distribute left over cargo to stations according to the highest remainder #8398
My idea here was to change the logic on what to do about the missing cargo that can originate from "a / b" division.
The original code rewards an extra cargo unit to stations that have the highest rating for that cargo type, but this approach disregards what I'm calling of "remainder". The highest rated station could, for example, be receiving 361/2=180 units with a rating of 200, and the second highest could be receiving 482/3=160 with a rating of 190. The remainder is, however, not tracked.
My code adds the ability to track the remainder of the a / b division. But since this value can't be simply a % b due to the multitude of values that b could have in different instances, I had to come up with a solution to make different remainders equiparable. That's when (a % b) / b came up. This would result in a value in the range [0,1[, which resembles the fractional part of a decimal number. However, due to how interger division works, the result is always 0. Scaling (a % b) / b by 100 would result in getting a fractional part of two decimals, but this didn't look like it had the precision it needed, so I went up scaling it up further to a maximum of a 16-bit value, hence the 65535 * (a % b) / b.
With equiparable remainders, going back to the 2 stations mentioned above, we have:
Now, even though the 2nd station has less rating (190) than the 1st (200), and less cargo moved (160+0,66 = 160,66) than the first station (180+0,50 = 180,5), 0,66 is closer to 1 than 0,50. And that's the basis of the logic of how the extra unit of cargo is added.
…st remainder Instead of distributing the cargo among the best rated stations, distribute it according to the highest remainder.