Angband Forums strange C code in Angband (am I reading this right?)
 Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 February 4, 2008, 06:37 #1 will_asher DaJAngband Maintainer     Join Date: Apr 2007 Location: San Antonio, TX Posts: 1,123 Donated: \$10 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.. __________________ Will_Asher aka LibraryAdventurer My old variant DaJAngband: http://sites.google.com/site/dajangbandwebsite/home (defunct and so old it's forked from Angband 3.1.0 -I think- but it's probably playable...)
February 4, 2008, 07:03   #2
Nick
Vanilla maintainer

Join Date: Apr 2007
Location: Canberra, Australia
Age: 56
Posts: 9,163
Donated: \$60
Quote:
 Originally Posted by will_asher 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.
__________________
One for the Dark Lord on his dark throne
In the Land of Mordor where the Shadows lie.

 February 4, 2008, 08:54 #3 will_asher DaJAngband Maintainer     Join Date: Apr 2007 Location: San Antonio, TX Posts: 1,123 Donated: \$10 ah. now it makes a lot more sense. reading the code is interesting.. __________________ Will_Asher aka LibraryAdventurer My old variant DaJAngband: http://sites.google.com/site/dajangbandwebsite/home (defunct and so old it's forked from Angband 3.1.0 -I think- but it's probably playable...)
February 4, 2008, 10:07   #4
Daven_26d1

Join Date: Jun 2007
Location: North of England.
Posts: 211
Quote:
 Originally Posted by Nick 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 =)
__________________
You sold a Broken Sword (1d2) (-2,-4) {average} (j) for 1 gold.
The shopkeeper howls in agony!
You say "Dude, the clue is in the name...".

 Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Angband     AAR     Vanilla     Development     ToME     Sil     Variants     Competition The real world     Idle chatter     Oook! Obsolete     v4

 Similar Threads Thread Thread Starter Forum Replies Last Post z118 AAR 1 February 5, 2008 00:38 APWhite Vanilla 0 October 16, 2007 22:19 K.I.L.E.R Vanilla 5 July 11, 2007 09:01 CJNyfalt Vanilla 11 June 26, 2007 04:25

All times are GMT +1. The time now is 10:46.