Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
6Dragons 4.3 bugfixes
Feb 5, 2017, 8:28 am
By Vladaar
Bug in violence_update( )
Jan 28, 2017, 3:54 pm
By Sadiq
Bug in mobile_update( )
Jan 25, 2017, 4:19 pm
By GatewaySysop
Bug (another one) in disarm( )
Jan 20, 2017, 5:16 pm
By GatewaySysop
Bug in format_obj_to_char( )
Jan 13, 2017, 10:01 am
By Remcon
LOP Heroes Edition
Author: Vladaar
Submitted by: Vladaar
Heroes sound extras
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.3
Author: Vladaar
Submitted by: Vladaar
Memwatch
Author: Johan Lindh
Submitted by: Vladaar
Beastmaster 6D sound files
Author: Vladaar
Submitted by: Vladaar
Users Online
CommonCrawl, Yahoo!, Bing

Members: 0
Guests: 9
Stats
Files
Topics
Posts
Members
Newest Member
476
3,695
19,209
602
ServerFailure
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » Codebases » SmaugFUSS » Bug in mprog_driver( )
Forum Rules | Mark all | Recent Posts

Bug in mprog_driver( )
< Newer Topic :: Older Topic > Issue with prior posted fix?

Pages:<< prev 1 next >>
Post is unread #1 Jan 7, 2017, 3:24 am
Go to the top of the page
Go to the bottom of the page

GatewaySysop
Conjurer
GroupMembers
Posts360
JoinedMar 7, 2005

Happened upon this while messing with something unrelated, but believe there's an issue here.

In mud_prog.c, function mprog_driver( )

    * BUGFIX - Reported by Aurin on the SmaugMuds.org forum.
    *  Adapted for simplicity by Samson. The random pick wasn't as random as one might like.
    *  It had a heavy bias toward the first chosen target, but his fix relied
    *  on what looked like dodgy dynamic array allocation. This is safer as it doesn't
    *  need to do anything like that.
    */
   count = 0;
   for( vch = mob->in_room->first_person; vch; vch = vch->next_in_room )
   {
      if( !IS_NPC( vch ) && can_see( mob, vch ) )
         ++count;
   }
   rand_pick = number_range( 1, count );

   // Now that we have the count and have picked a random number in that range, run the list again if there's a point in doing so.
   if( count > 0 )
   {
      for( vch = mob->in_room->first_person; vch; vch = vch->next_in_room )
      {
         if( !IS_NPC( vch ) && can_see( mob, vch ) )
         {
            if( count == rand_pick )
            {
               rndm = vch;
               break;
            }
            ++count;
         }
      }
   }


Shouldn't that look like this instead?


    * BUGFIX - Reported by Aurin on the SmaugMuds.org forum.
    *  Adapted for simplicity by Samson. The random pick wasn't as random as one might like.
    *  It had a heavy bias toward the first chosen target, but his fix relied
    *  on what looked like dodgy dynamic array allocation. This is safer as it doesn't
    *  need to do anything like that.
    */
   count = 0;
   for( vch = mob->in_room->first_person; vch; vch = vch->next_in_room )
   {
      if( !IS_NPC( vch ) && can_see( mob, vch ) )
         ++count;
   }

   // Now that we have the count and have picked a random number in that range, run the list again if there's a point in doing so.
   if( count > 0 )
   {
      rand_pick = number_range( 1, count );
      count = 0;
      for( vch = mob->in_room->first_person; vch; vch = vch->next_in_room )
      {
         if( !IS_NPC( vch ) && can_see( mob, vch ) )
         {
            ++count;
            if( count == rand_pick )
            {
               rndm = vch;
               break;
            }
         }
      }
   }


If the count doesn't get reset, how does the inner loop function properly? And if the ++count is beneath and not above the if( count == rand_pick) check, isn't that also incorrect because it throws the comparison off by 1 vs. the random selection?


       
Post is unread #2 Jan 7, 2017, 8:21 am
Go to the top of the page
Go to the bottom of the page

Sadiq
Fledgling
GroupMembers
Posts24
JoinedJan 7, 2010

The correction looks right, to me. Nice catch! :smile:
       
Pages:<< prev 1 next >>