bugs

Forum > Bugs > Incorrect tourney placings
Reply To Thread (login)
Ender [1]
Administrator
2015-06-10 22:08:18
[8 years, 333 days ago]

Copy/pasting this bug report I received from Myriad (thanks!) via bmail to make it more public. This indeed looks like a bug.

Hi Ender,

I was checking the tourney placings for category 8 edition 4, and I noticed an anomaly.

http://bots4.net/tournament/edition-4/category-8

My bot, Passion, placed 2nd, despite having more average hp % remaining and being tied on wins with N 002. It was quite close, so I didn't notice this before.

This is the only cat in which I've noticed this bug, but I'll let you know if I find any more results like this. I'm not sure what has caused it, but it may have something to do with one bot being clanned and the other not being clanned.


 
Ender [1]
Administrator
2015-06-10 22:55:54
[8 years, 333 days ago]

This was an interesting one. It's fixed now and won't be an issue going forward. I'm deeming it infeasible to go back and re-rank/re-award past tournaments with the fix though. As usual, read on for the gory details if you're interested.

The tournament code uses PHP's usort function to do the custom sorting logic that ranks bots first by wins, then if necessary by average remaining HP, then if necessary (this should almost never happen) by bot id. This involves providing a standard comparison function that can compare two objects and say whether one should be ordered before, after, or the same as another object. Specifically, this comparison function should return an integer less than, equal to, or greater than zero depending on the ordering relationship between the two objects (many programming languages have libraries that use this convention).

Now here's where the gotcha/bug comes in. If you read the docs linked above closely, you'll notice it cautions against returning non-integer values from the comparison function. A common setup for these kinds of functions, when you have a tiered setup where you want to order by A, then by B if needed, then by C if needed, and so on, is to see if the "A" of each object is the same, and if not, to return the difference (swapping the order as needed to control whether higher means before or after). This works great for integer fields like "wins", but not so great for non-integer fields like "average HP remaining". It turns out the value in that case will get cast to an integer.

Here's where the bug really comes in (I guess I lied earlier). :) For pairs of bots that had an average remaining HP less than 1%, the absolute value of the difference came out to some value less than 1. Because of how most programming languages cast floating point numbers to integers, this always get changed to 0. Recall that the comparison function returning 0 means it's saying the objects are equal. So what this means is that for certain pairs of bots, the order is effectively undefined; it might come out correct, but it might not.

This affected the tournament result that Myriad pointed out. The effect is even more pronounced if you look at the middle of the pack in a large category like category 10. There are a number of bots with 27 wins that all had an average remaining HP percent of around 12-14%. Their ordering is effectively random.

Anyway, I hope at least one person found this unexpectedly long explanation informative and/or interesting. It's a bit surprising that a bug with such an obviously wrong result went unnoticed for this long, but it feels good to squash nonetheless. Thanks for reporting this, Myriad.


 
Esvrainzas [134]
2015-06-11 06:36:15
[8 years, 332 days ago]

Very well spotted Myriad. Yeah, I found it interesting and I guess I understood it ;)


 
Myriad [361]
2015-06-11 07:48:41
[8 years, 332 days ago]

Awesome that you fixed the bug Ender, but I'm not sure I understand why you can't award the appropriate trophies after fixing the bug. I mean, this isn't some bug that gave out too many trophies or something - some bots actually got screwed out of trophies/plats as a result of this bug. If other people want to claim trophies that they were entitled to, I think they should be able to as well.


 
Pothead [100]
2015-06-11 08:11:07
[8 years, 332 days ago]

Many people were screwed out of trophies etc by cheaters like ville but weren't awarded the trophies that they should of been. Besides, winning by a bug is pretty stylish.


 
Ender [1]
Administrator
2015-06-11 09:14:47
[8 years, 332 days ago]

I deemed it infeasible because it would be a lot of work to correct this. I'd probably have to write a custom script to delete everyone's trophies (and therefore trophy points) associated with all tournaments (which may or may not even be possible if they've already spent said trophy points), then tweak the tournament ranking/awarding scripts to be able to re-run on arbitrary tournaments, use the correct historical timestamps when awarding trophies, make sure the scripts are robust against being run for different category setups (they changed after edition 1 I believe), etc. This would all take at least several hours and would be an error-prone process because of how much new code it would be. I'm sorry that the results came out wrong in a few edge cases and that in some cases this meant missing out on a platinum trophy, but due to the nature of the bug the bot ranks that got swapped were bots that finished neck-and-neck - a tiny slip of the RNG would have resulted in the same swap.


 
Esvrainzas [134]
2015-06-11 09:27:20
[8 years, 332 days ago]

RNG?


 
Pothead [100]
2015-06-11 09:34:06
[8 years, 332 days ago]

Random number generator


 
DarkNinjaMaster [24]
2015-06-11 10:46:34
[8 years, 332 days ago]

You lost me at "It turns out the value in that case will get case to an integer."

I picked it back up at RNG though.


 
Ender [1]
Administrator
2015-06-11 22:50:48
[8 years, 332 days ago]

Oops, I meant "cast", not "case". I went back and edited my post using my ninja admin powers. :)


 
Myriad [361]
2015-06-12 07:18:13
[8 years, 331 days ago]

I understand that fixing ALL the tourney results would be a long undertaking, but would it not be possible to change results/reaward the trophies manually on a request basis? I doubt there would be many significant results to change, otherwise the bug would have been noticed earlier. I get that it is more satisfying to fix all results than just one here and there, but it's also satisfying to actually be rewarded for winning a category :p


 
Forum > Bugs > Incorrect tourney placings
Reply To Thread (login)