Bug in Hero offers code?

If you find a bug please report it here

Bug in Hero offers code?

Postby Chazar » Wed May 09, 2012 10:43 pm

There is a bug in the code for hero offers as shown in the warpedia about hero offers:
Code: Select all
if((currentgold > 400) && (newherochance < 400)) {newherochance = 500;}
   // Always a 10% chance - assuming enough gold
if((newherochance > 1150) && (numberofheroes > 0)) {newherochance = 1150;}
   // Maximum 75% chance if 1+ heroes
if(rand(400,1000) < newherochance)
{
   hero = rand(400, currentgold);
   ...

In order to have a 10% chance at 500 and 75% at 1150, the generated random value should range between 400 and 1400.

No I have no clue about JavaScript (or whatever that is), but the code "rand(400,1000)" seems suspicious to me:
  • If "rand(400,1000)" generates a number between 400 and 1000, then it should be rand(400,1400) instead to get the percentage chances as given in the comments
  • If "rand(400,1000)" generates a number between 400 and 400+1000 instead, then surely the next line "hero = rand(400, currentgold)" is buggy, since a hero should never cost more than the player has available.
  • Of course, the last possibility is that the comments are just outdated, but then 1150 is a suspiciously specific number, since 1001 would do just as well to yield a 100% chance.
Chazar
 
Posts: 670
Joined: Tue Feb 28, 2012 7:51 pm

Re: Bug in Hero offers code?

Postby KGB » Thu May 10, 2012 2:02 am

Chazar,

It's this one.

If "rand(400,1000)" generates a number between 400 and 400+1000

This is not buggy. You always get a 10% chance for a hero even if you have 0 gold. What that next check does is roll for the hero cost. If it exceeds your gold you won't get any offer (you are too poor for this hero).

KGB
KGB
 
Posts: 3030
Joined: Tue Feb 16, 2010 12:06 am


Return to Bug reports

Who is online

Users browsing this forum: No registered users and 6 guests

Not able to open ./cache/data_global.php