Angband Forums

Angband Forums (http://angband.oook.cz/forum/index.php)
-   Idle chatter (http://angband.oook.cz/forum/forumdisplay.php?f=6)
-   -   strange C code in Angband (am I reading this right?) (http://angband.oook.cz/forum/showthread.php?t=526)

will_asher February 4, 2008 05:37

strange C code in Angband (am I reading this right?)
 
This code is in the function to do polymorphing:

Code:

        /* Allowable range of "levels" for resulting monster */
        lev1 = r_ptr->level - ((randint(20)/randint(9))+1);
        lev2 = r_ptr->level + ((randint(20)/randint(9))+1);

If I'm reading this right, then this takes a random number from 1 to 20 and divides it by a random number from 1 to 9 and then adds 1 and thats the variation how far the new polymorphed monster's level can be from the level of the original monster before it was polymorphed.

Why would the max range of the levels of the polymorphed monsters be a random thing instead of fixed?

This strikes me as a very strange formula and I wonder how whoever programmed this came up with it. Am I reading this right? Does this strike anyone else as odd?

..just something I wondered about when I was looking at the code..

Nick February 4, 2008 06:03

Quote:

Originally Posted by will_asher (Post 5255)
This strikes me as a very strange formula and I wonder how whoever programmed this came up with it. Am I reading this right? Does this strike anyone else as odd?

Yes, you are reading it right. I think the reason is that mostly there will only be a small allowable range of levels, but occasionally you'll get a big variation in one direction (when randint(20) is big and randint(9) is small). So it allows a polymorph to give a very different monster level, but not often.

Where the exact 9 and 20 values came from I don't know - I guess someone originally calculated a good distribution to use.

will_asher February 4, 2008 07:54

ah. now it makes a lot more sense.
reading the code is interesting..

Daven_26d1 February 4, 2008 09:07

Quote:

Originally Posted by Nick (Post 5256)
Where the exact 9 and 20 values came from I don't know - I guess someone originally calculated a good distribution to use.

I figure someone started with 20 and 10 and then it got tweaked by a single point later on.

EDIT - nice to see you haven't gotten bored with those sources yet, will_asher =)


All times are GMT +1. The time now is 21:16.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.