supertuxkart / stk-code

The code base of supertuxkart
Other
4.36k stars 1.03k forks source link

Fixes for handleAllVotes #5041

Closed kimden closed 1 month ago

kimden commented 1 month ago

This fixes the following issues related to voting for a map in the server lobby:

  1. When several maps have the same number of votes, the code currently iterates over them and picks the next one with probability $\frac{1}{2}$, so if there are $n$ different votes, $i$-th of them is chosen with probability $2^{\max(i, 2)} / 2^{n + 1}$. This PR changes all probabilities to $\frac{1}{n}$.
  2. When the majority exists for maps, for lap counts, and for directions, but there's no vote with exactly the same map, lap count, and direction, the first vote (that is, the vote of players with smallest host id?) was picked instead. This PR postpones the decision until the voting is over.

I also tried to get rid of repeated code, thus moved it to another function.

Agreement

By creating a pull request in stk-code, you hereby agree to dual-license your contribution as
GNU General Public License version 3 or any later version and
Mozilla Public License version 2 or any later version.

This includes your previous contribution(s) under the same name of contributor.

Keep the above statement in the pull request comment for agreement.