Changes to the weight list for powerups

Changes to the weight list for powerups

Postby Alayan » 03 Nov 2014, 04:29

I'm doing some code level changes to add a 6th category. (I did a fork of the github repo to do so and try to compile and test it when done)
The old five are : first ; top33; mid33 ; end33 ; last
The new split would be : first ; top25 ; midtop25 ; midend25 ; end 25 ; last

This doesn't matter with 5 or 8 karts ; but will allow for more accuracy with 15 or 20 karts.


Doing the changes ; I spotted what is IMO a bug :
{l Code}: {l Select All Code}
            // The 'global' powerups (i.e. powerups that affect
            // all karts, not only the ones close by) appear too
            // frequently with larger number of karts. To reduce
            // this effect their weight is reduced by the number
            // of karts.
            if(w!=0 && num_karts > 4 &&
                 (type==POWERUP_PARACHUTE || type==POWERUP_SWITCH) )
            {
                w = w / (num_karts-4);
                if(w==0) w=1;
            }

w=w/(num_karts-4) is a bad formula. A really really bad formula.
Let's say that the number of items taken is linear following the number of karts (it's false in that with more karts ; the likeliness to get a given item box is a little bit lower ; but it's not so unaccurate)
4 karts => P = 1
5 karts => P = (5/4)*1/(5-4) = (5/4)*1/1 = 1,25
6 karts => P = (6/4)*1/(6-4) = (6/4)*1/2 = 0,75
7 karts => P = 7/4 * 1/3 = 0,5833
8 karts => P = 8/4 * 1/4 => 0,5
[...]
20 karts => P = 20/4 *1/20 => 0,25

So at the end you have 4 times less often the global effect with 20 karts than with 4 !
Note that obviously, this calc doesn't take in account the effect of the different position class (first, top25 etc) : so adding a kart may improve the probabilities by having a more important increase in <karts which can have the global item>. But ultimately, this will go in the other direction with the next one, and the global picture stay the same.

I started a race with 5 opponents to test it, and I can confirm the bug is indeed here : I was in the 4th and 5th position ; and my first three items were : para ; switch ; para. I stopped the experiment at this point, since the point of "global items appear way more often with 5 opponents than with 20 (for the whole karts)" was already made.


To resolve the issue ; there are two ways IMO : 1)change so instead of num_karts-4 ; it is num_karts/4. Yeah ; that's that trivial. It will allow to keep nearly always the same global probability for global items to be picked.
2)Split so the powerup.xml will indicate several values adapted depending of the number of karts (not for the 20 possibilities ; but 3 or 4 which will also work for the nearby others). This change would allow to different weights for other items too depending on the number of karts. The dynamics of a 5 karts and 20 karts races are different enough to justify this. I intend at least to try this to see how it works. With it ; the need to adapt the global items probability depending of the number of karts would be greatly lowered (it may still be added on the top)


EDIT : Another spotted bug
{l Code}: {l Select All Code}
    // Now num_karts must be >2, since position <=num_players

    unsigned int third = (unsigned int)floor((float)(num_karts-1)/3.0f)

=> should be num_karts-2 ; since first AND last are taken out ; and they are different for that part of code to be of any use.
The comments flying arround confirm this is indeed a bug in that the position_class LAST seems to have been added after, without any change otherwise to the code.
EDIT2 : As I did a table to see which postion correspond to which class ; while not properly cuting in 3 the fact we work with integers ends that it do work as well for that, with the added bonus of cuting better when there are only 4 karts. So ; intended or not, it wasn't an issue. :)
Last edited by Alayan on 04 Nov 2014, 22:27, edited 1 time in total.
Image
Alayan
STK Moderator
 
Posts: 307
Joined: 25 Mar 2012, 22:11

Re: Changes to the weight list for powerups

Postby Alayan » 03 Nov 2014, 05:47

The changes for the split in 6 position_class for weights of powerup, instead of 5 ; are done on my github fork : https://github.com/Alayan-stk/stk-code
I still need to do a test powerup.xml ; before compiling and testing. (I hope the actual code between two main releases is stable enough. It will be my first compilation of STK :D )

To compare the previous divisions and these I did ; these two screenshoots should be helpful :
Previous :
SuperTuxKart_powerup33.png

Mine :
SuperTuxKart_powerup25.png
Image
Alayan
STK Moderator
 
Posts: 307
Joined: 25 Mar 2012, 22:11

Re: Changes to the weight list for powerups

Postby Arthur » 03 Nov 2014, 13:30

Yes, there are definitely issues with the balancing for 20 kart races. It hasn't been prioritized because the defaults are much lower, and there are always other matters. But since the code is being written/fixed by you, I see no reason to reject this as I'm convinced by own experience that balancing with many karts could be better. In other words, whoop-de-do, glad someone looks at this issue and does something to fix it. :)
Hey pal, I took an oath for justice! "In happy days or tightest tights..." or something like that.
User avatar
Arthur
 
Posts: 1073
Joined: 06 Dec 2009, 00:49

Re: Changes to the weight list for powerups

Postby Alayan » 09 Nov 2014, 17:06

My compilation issues and my graphic driver issues haven been sorted out, I finally was able to test my changes & correct some small errors.
It just works™

However new values for powerup.xml need to be created to use that possibility, and atm I can't.
Image
Alayan
STK Moderator
 
Posts: 307
Joined: 25 Mar 2012, 22:11

Who is online

Users browsing this forum: No registered users and 1 guest