Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
Bug in get_exp_worth( )
Oct 10, 2017, 1:26 am
By GatewaySysop
Bug in do_drag( )
Oct 8, 2017, 12:40 am
By GatewaySysop
Bug in one_hit( )
Oct 7, 2017, 2:50 pm
By GatewaySysop
Development
Sep 21, 2017, 11:57 am
By Caius
Seg. Fault / Hang During Color Selection
May 28, 2017, 8:45 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, Yandex

Members: 0
Guests: 12
Stats
Files
Topics
Posts
Members
Newest Member
476
3,701
19,226
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
Posts363
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 >>