Hero offers in v0.9 more scarce?

Discuss anything related to warbarons.

Re: Hero offers in v0.9 more scarce?

Postby KGB » Thu Jan 31, 2013 10:40 pm

Piranha,

Since the max chance caps at 1250 and your roll goes to 1300 it definitely equates to a max chance higher than 75%

But what does this 2nd line below do? It appears the gold cost check is still 400-1250 rather than 400-850 which will cut out some hero offers where you roll successfully but don't reach the 1200 gold even though you in theory meet the max 850 cost. Shouldn't that line be $hero = rand(400, 450) to get a 400-850 gold price?

//hero cost
$hero = rand(400, 850);
if(rand(350,950) < $newherochance && $currentgold > $hero)

KGB

P.S. Also I don't see anything here where you show how levels are being assigned/limited etc. There are definitely hero offers coming in at turn 13+ that are only L1 despite having lots of gold.
KGB
 
Posts: 3030
Joined: Tue Feb 16, 2010 12:06 am

Re: Hero offers in v0.9 more scarce?

Postby Chazar » Thu Jan 31, 2013 11:20 pm

That makes it a lot harder to get a hero if you are low on gold:
First you have to roll a hero cost that is below your current gold, and then you have to pass another roll which has to be below your current gold.
Code: Select all
    if(rand(350,950) < $newherochance && $currentgold > $hero)

Why the double roll?
Chazar
 
Posts: 670
Joined: Tue Feb 28, 2012 7:51 pm

Re: Hero offers in v0.9 more scarce?

Postby piranha » Fri Feb 01, 2013 6:08 am

The range goes from 400 to 850, not 400 to 400+850. Check this function: http://www.php.net/manual/en/function.mt-rand.php
I changed to mt_rand because it's faster but they are basically the same otherwise.

If you have improvement ideas you are welcome. We think offers should come often if you have the money so it wont be bad luck that didn't give you a hero offer in time when you had money. The next thing to reduce luck on in my opinion is where your new hero arrives. There is a lot of luck involved there too. I pasted the entire function for hero offer, its gone through many last minute updates so it's a bit messy. We have no plan to update it in our current version 0.91 so feel free to improve if you want to.
Not sure if you need more data in order to do anything with picking a city code.

Code: Select all
// -----------------------
//  CHECK FOR HERO OFFER
// -----------------------
function  checkforherooffer($playerID,$currentgold,$turn)
    {
    $herooffer = "null"; // Blir ett JS objekt senare så kan ej vara tomt
    $randmax = 3;

    $query="SELECT count(army.ID)
    FROM $this->armytable army
    WHERE status !='dead' AND army.unitclass = 'Hero' AND army.playerID=$playerID AND army.gameID=$this->gameid";
    $returnvalue = $this->datawork->DBGet($query);
    $numberofheroes =  $returnvalue[0];


    if ($turn == 1)
        {

        $herocost = 500;
        $standalonecost = $herocost;

        // Vissa scenariogames kan starta med lite gold --> dvs ingen Herooffer
        if ($currentgold > $herocost)
           {
         $newhero = "yes";
         $heroallies=0;
            $realherolevel=1;
           }


        }


    if($newhero != "yes" && $turn > 1)
        {
           
/*
För varje 6 turns som passerat över leveln som man kan slumpa fram en hjälte med. Max level 5.
Turn 1-6 max level 1, extra cost 0
Turn 7 - 12 max level 2, extra cost 150 - 250
Turn 13 - 18 max level 3, extra cost 250 - 600
Turn 19 - 24 max level 4, extra cost 600 - 950
Turn 25 - 30 max level 5, extra cost 950 - 1250
*/           
            //Om man inte har ett hjälte erbjudande kollar vi pengar och antal hjältar man har.
            $morethanfive = ($numberofheroes - 4);
            if($morethanfive < 1) {$morethanfive = 1;}
            $newherochance = ($currentgold - ($numberofheroes * $numberofheroes * 100 * $morethanfive)); // Number of heroes squared
            if(($currentgold > 400) && ($newherochance < 500)) {$newherochance = 500;} // Always a 10% chance - assuming enough gold
            if(($newherochance > 1250) && ($numberofheroes > 0)) {$newherochance = 1250;} // Maximum 75% chance if 1+ heroes

            //Räkna ut hjälte kostnad
            $hero = mt_rand(400, 850);
            if(mt_rand(350,950) < $newherochance && $currentgold > $hero)
                {
                    $newhero = "yes";
     
                    if ($turn > 6 && $turn < 13)
                        {
                        // 33% chans för lvl 2 hero
                        $herolevel = mt_rand(1,3);
                        if ($herolevel == 3)
                            {
                            $herolevel = 2;   
                            } 
                        }
                    if ($turn > 12 && $turn < 19)
                        {
                        $herolevel = mt_rand(1,3);
                        if($herolevel == 1)
                        {
                            $herolevel = 2;
                        } 
                        }
                    if ($turn > 18 && $turn < 25)
                        {
                        $herolevel = mt_rand(1,4);
                        if($herolevel == 1)
                        {
                            $herolevel = 2;
                        }
                        }     
                    if ($turn > 24)
                        {
                        $herolevel = rand(3,5);   
                        }     
                       
                    // Rotera upp per level o addera på kostnad (250 guld per level) så långt pengarna räcker...                                                                                       
                    $availablegold = $currentgold - $hero;
                    $realherolevel = 1;
                    for ($i=1;$i<$herolevel;$i++)
                        {
                        if (($currentgold - $hero - 250) > 0)
                            {
                                if($i > 1)
                                {
                                    $hero=$hero+250;
                                }
                           
                                $realherolevel = $i;   
                            } 
                        else
                            {
                            break;
                            }
                        }

               $standalonecost=$hero;
                    $availablegold = $currentgold - $hero;
                    if ($availablegold > 500)
                       {
                       $minrand=0;
                       $maxrand=1;
                       }
                    if ($availablegold > 1000)
                       {
                       $minrand=1;
                       $maxrand=2;
                       }
                    if ($availablegold > 1500)
                       {
                       $minrand=1;
                       $maxrand=3;
                       }
                    if ($availablegold > 2000)
                       {
                       $minrand=2;
                       $maxrand=3;
                       }
                    if ($availablegold > 2500)
                       {
                       $minrand=2;
                       $maxrand=3;
                       }
                    if ($availablegold > 3500)
                       {
                       $minrand=3;
                       $maxrand=3;
                       }

                    $maxnumberofallies = mt_rand($minrand,$maxrand);

                    $wizard[0] = mt_rand(250, 300);
                    $medusa[0] = mt_rand(300, 400);
                    $elemental[0] = mt_rand(300, 400);
                    $ghost[0] = mt_rand(250, 350);
                    $demon[0] = mt_rand(600, 700);
                    $devil[0] = mt_rand(600, 750);
                    $archon[0] = mt_rand(800, 1000);
                    $dragon[0] = mt_rand(850, 1100);

                    $wizard[1] = 22;
                    $medusa[1] = 20;
                    $elemental[1] = 24;
                    $ghost[1] = 21;
                    $demon[1] = 25;
                    $devil[1] = 26;
                    $archon[1] = 27;
                    $dragon[1] = 28;

                    $alliearray = array($wizard, $medusa, $elemental, $ghost, $demon, $devil, $archon, $dragon);


               shuffle($alliearray);  // Samma typ av ally i alla offers tills vidare
                    for ($i=0;$i<$maxnumberofallies ;$i++)
                       {
                       // shuffle($alliearray);
                  $newally = $alliearray[0];

                  if ($availablegold < $newally[0])
                     {
                     continue;
                     }
                  $allycontent[] = $newally[1];
                  $availablegold=$availablegold-$newally[0];
                       }

                    $herocost = $currentgold - $availablegold;
                }

            }
    elseif (($turn < 5) && ($turn > 2) && ($currentgold < 1000) && ($currentgold > 350) && ($newhero != "yes"))
        {
        // Om ens hjälte är död ska man ha extra stor chans att få en ny till billigt pris
        if ($numberofheroes == 0)
            {
            $newhero = "yes";
            $herocost = $currentgold*1;
            $heroallies=0;
            $realherolevel=1;
            }
        }

    if ($newhero == "yes")
        {

      // Slumpa en stad
        $returnvalue = $this->datawork->DBmultiget("SELECT mapcoord, name
        FROM $this->objectstable
        WHERE status='playerowned' AND playerID=$playerID AND type='City' AND gameID=$this->gameid");
        for ($i=0;$i<count($returnvalue);$i++)
            {
            $citycoordarray[$i] = $returnvalue[$i][0];
            $cityhash[$returnvalue[$i][0]] = $returnvalue[$i][1];
            }
        if (count($citycoordarray)>1)
           {
           shuffle($citycoordarray);
           }
        $herooffercity = $citycoordarray[0];
        $herooffercityname = $cityhash[$herooffercity];


      // Addera en history entry
      $timestamp = time();
      $event = "Event_herooffer";
      $arguments = $herooffercityname;
      $dataarray=array($this->gameid,$turn,$event,$arguments, $timestamp,$herooffercity,'event',"PLAYER",$playerID);
      $this->datawork->DBinsert($this->historytable,$dataarray);

      unset($herooffer );
        $herooffer['type']             = "herooffer";
        $herooffer['cost']             = $herocost;
        $herooffer['level']             = $realherolevel;
        $herooffer['standalonecost']    = $standalonecost;
        $herooffer['allies']          = $allycontent;
        $herooffer['citycoord']       = $herooffercity;
       $herooffer = json_encode($herooffer);
      $herooffer = preg_replace('/"(-?\d+\.?\d*)"/', '$1', $herooffer);
        }

    return $herooffer;

    }
User avatar
piranha
Site Admin
 
Posts: 1188
Joined: Fri Feb 12, 2010 9:44 pm

Re: Hero offers in v0.9 more scarce?

Postby KGB » Fri Feb 01, 2013 3:21 pm

Piranha,

Thanks for the mt_rand clarification. Based on that, then these 2 lines are no longer correct.
Code: Select all
                if(($currentgold > 400) && ($newherochance < 500)) {$newherochance = 500;} // Always a 10% chance - assuming enough gold
                if(($newherochance > 1250) && ($numberofheroes > 0)) {$newherochance = 1250;} // Maximum 75% chance if 1+ heroes


The first line is wrong because you are now starting at 350 instead of 400 for your roll. So at a base of 500 there is *more* than a 10% chance. A value of 410 is a 10% chance (10% of 950-350 = 60. So 350+60=410).
The second line does nothing at all because the max roll is now 950. So the cap of 1250 means the max is now 100% and hence the line does nothing.

Code: Select all
               if(mt_rand(350,950) < $newherochance && $currentgold > $hero)


As Chazar mentioned this line forces the player to pass 2 rolls to get a hero. This actually lowers the chances by quite a bit when you have lower gold amounts (<950 gold). To see this imagine having 650 gold and a newHeroChance of 650 (ie you have no heroes). The 2 rolls are 350-950 and 400-850. To pass the first roll is 50% (650 is midway between 350 and 950). To pass the second roll is 62.5% (650 is just past midway of 400 and 850). So the hero chance is really .5*.625= 31.25% and the player has been penalized by 19%. This is why in the sample code I showed I made just 1 roll. Then if that's successful you roll for the gold cost. Like this:

Code: Select all
               if(mt_rand(350,950) < $newherochance)
               {
                    $hero = mt_rand(400, 850);
                    if($hero > $currentgold) $hero=$currentGold // hero costs all the players gold


This explains why we aren't getting L2+ heroes correctly.

Code: Select all
    for ($i=1;$i<$herolevel;$i++)


It should be <=$herolevel. Whats happening is when you get a L2 hero, the check works for 1 pass through this code (i=1) but when i=2 it exits the loop. So players are getting there heroes at 1 level lower than they should (ie 1 instead of 2, 2 instead of 3 etc).

You can delete this code. It never runs because the 'if' part is just (turn>1) which will always be true other than turn 1 (which is handled by the first few lines in your function).

Code: Select all
        elseif (($turn < 5) && ($turn > 2) && ($currentgold < 1000) && ($currentgold > 350) && ($newhero != "yes"))
            {
            // Om ens hjälte är död ska man ha extra stor chans att få en ny till billigt pris
            if ($numberofheroes == 0)
                {
                $newhero = "yes";
                $herocost = $currentgold*1;
                $heroallies=0;
                $realherolevel=1;
                }
            }


KGB

P.S. I'll think a bit on picking the city. Right now the random city work is OK. One players suggestion to allow the hero to be vectored in the hero offer screen might solve a lot of issues related to getting a hero far away from the front lines on large maps.
KGB
 
Posts: 3030
Joined: Tue Feb 16, 2010 12:06 am

Re: Hero offers in v0.9 more scarce?

Postby piranha » Sat Feb 02, 2013 7:47 am

Thanks for spotting those errors. I've updated the file so should come more heroes from now on.

Perhaps a standard portal is the best way to solve it. I often find that I want my hero now and waiting 2 turns early on can be quite important. How about portals where the cost is gold instead of time?
User avatar
piranha
Site Admin
 
Posts: 1188
Joined: Fri Feb 12, 2010 9:44 pm

Re: Hero offers in v0.9 more scarce?

Postby Experix » Sat Feb 02, 2013 11:45 am

As Chazar mentioned this line forces the player to pass 2 rolls to get a hero. This actually lowers the chances by quite a bit when you have lower gold amounts (<950 gold). To see this imagine having 650 gold and a newHeroChance of 650 (ie you have no heroes). The 2 rolls are 350-950 and 400-850. To pass the first roll is 50% (650 is midway between 350 and 950). To pass the second roll is 62.5% (650 is just past midway of 400 and 850). So the hero chance is really .5*.625= 31.25% and the player has been penalized by 19%. This is why in the sample code I showed I made just 1 roll. Then if that's successful you roll for the gold cost.


I certainly prefer this double roll. Comparing to the 0.8 version, the difference in % for this concrete situation is lower than these 19%.
But if you already have 650 gold, it is usually not such a problem to raise it to 850 or 950, such that you achieve certainity or almost certainity.
The way that two sides have the same hero chance and the one who has less money has advantage that his offered hero would be cheaper on average, is illogical and confusing for me.
Experix
 
Posts: 129
Joined: Wed Jul 04, 2012 8:39 am

Re: Hero offers in v0.9 more scarce?

Postby KGB » Sat Feb 02, 2013 4:27 pm

Piranha,

Allowing players to instantly place their heroes anywhere for gold isn't a good idea. What will happen is that when you start offering L2+ heros + allies players will be placing those right on the front lines and using them to attack. Getting a L3 hero + allies is going to just be impossible to guard against and games would turn on that. The 2 turn portal time at least prevents that issue.

And the new changes must be working because I just got a hero offer for 476 gold that took 100% of my gold.

Experix,

Having lower gold means cheaper heroes but it means less chance to get them. I'd much rather have 950 gold and be sure of a hero than have only 650 and get one 50% of the time regardless of whether or not I paid 200 more gold for my hero. This is especially important when you consider you get 2x as many chances to get different allies / higher level heroes and 2x as many chances the hero arrives where you need him.

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

Re: Hero offers in v0.9 more scarce?

Postby Experix » Sun Feb 03, 2013 1:45 am

KGB,

Having lower gold means cheaper heroes but it means less chance to get them.


That's not true. When I didn't know the hero algorithm, I found myself for example in situation that I had four heroes (and would like to get one more). I tried to keep my gold over 1500. It seemed to me that since it is more than max hero price, I had a reasonable chance to get one in few turns. Later I found that the probability was exactly the same as if I had 400 gold - in which case I would have some good production instead and wouldn't get expensive offers the new hero wouldn't be worth. So not knowing the exact numbers and thinking more gold = better was definitely not good...
Having the max price lowered and possibility of adding level for sparse gold definitely helps a lot with this.

I'd much rather have 950 gold and be sure of a hero than have only 650 and get one 50% of the time regardless of whether or not I paid 200 more gold for my hero.


I don't say it's not worth to raise your money anyway in this case, I just don't see the reason for making some special rule which makes heroes cheaper for somebody who hasn't enough gold to pay for them...

Allowing players to instantly place their heroes anywhere for gold isn't a good idea. What will happen is that when you start offering L2+ heros + allies players will be placing those right on the front lines and using them to attack. Getting a L3 hero + allies is going to just be impossible to guard against and games would turn on that. The 2 turn portal time at least prevents that issue.


I see as much bigger problem than choosing the city the fact that the high level hero appears from nowhere. For example, if you are ready for attack in forest, and the opponent gets L3 offer, he buys a ranger and attacks you with 20 leadership (not mentioning possible allies), which completely turns the outcome of the battle for the other side...


One more thing for the posted code:

if ($turn > 6 && $turn < 13)
{
// 33% chans för lvl 2 hero
$herolevel = mt_rand(1,3);
if ($herolevel == 3)
{
$herolevel = 2;
}


This is 2/3 probability for L2 hero, not L1, isn't it?
Experix
 
Posts: 129
Joined: Wed Jul 04, 2012 8:39 am

Re: Hero offers in v0.9 more scarce?

Postby SnotlinG » Mon Feb 04, 2013 11:28 am

Experix wrote:
One more thing for the posted code:

if ($turn > 6 && $turn < 13)
{
// 33% chans för lvl 2 hero
$herolevel = mt_rand(1,3);
if ($herolevel == 3)
{
$herolevel = 2;
}


This is 2/3 probability for L2 hero, not L1, isn't it?


Yes you are correct, it has been updated now:
$herolevel = mt_rand(1,3);
if ($herolevel == 3)
{
$herolevel = 1;
}
Thanks for spotting this :-)
SnotlinG
 
Posts: 2148
Joined: Sat Feb 13, 2010 12:42 am

Re: Hero offers in v0.9 more scarce?

Postby Chazar » Mon Feb 04, 2013 9:28 pm

About the location: Select two random cities and let the player choose. It is still random, but has a less chance for a forgotten backwater city. (Could also be 3 cities, or #cities/10, or something.)

I agree with KGB: vectoring for heroes is not a good idea, since then heroes will always magically pop at the front line, and one cannot prepare - this would seem annoying.
Chazar
 
Posts: 670
Joined: Tue Feb 28, 2012 7:51 pm

PreviousNext

Return to Game discussion

Who is online

Users browsing this forum: No registered users and 16 guests

cron
Not able to open ./cache/data_global.php