Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
Couple bugs
Dec 12, 2017, 5:42 pm
By Remcon
Bug in disarm( )
Nov 12, 2017, 6:54 pm
By GatewaySysop
Bug in will_fall( )
Oct 23, 2017, 1:35 am
By GatewaySysop
Bug in do_zap( ), do_brandish( )
Oct 18, 2017, 1:52 pm
By GatewaySysop
Bug in get_exp_worth( )
Oct 10, 2017, 1:26 am
By GatewaySysop
LOP 1.45
Author: Remcon
Submitted 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
Users Online
CommonCrawl, Google, Sogou, Yandex

Members: 0
Guests: 11
Stats
Files
Topics
Posts
Members
Newest Member
477
3,705
19,232
608
LAntorcha
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
Posts367
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 >>