I have recently started playing clickerheroes again. In the recent patch they introduced a new mechanic to mercenaries: their lifetime. Instead of having a random chance at dying now they have a certain lifespan given by a geometric distribution of p = 0.2. They can be sent on quests to accumulate a premium currency called rubys. When they die you can revive them paying rubys.

The challenge

The amount of rewards they bring home are scaling linear with their level, while the revivecost is scaling exponentially, so at a certain level it is better to not revive a mercenary and instead hire a new one.

I wrote some code simulating this challenge but found that it was pretty long and there certainly must be a way to make it shorter.

Your job is to do that and find the level where not reviving makes the ruby return per day reach a maximum.

More information on mercenaries

  • The lifespan of a mercenary is given by a geometric distribution with p = 0.2 in days. Within the day the distribution is linear. Meaning that the chance to die at any given minute is the same as any other minute that day.

  • Doing a quest reduces the lifespan by the duration of that quest.

  • You can always choose from 4 quests.

  • The quest available are random and split in 2 parts.

  • The main objective is choosen from a pool of 5 where only 1 is finding rubies so the chance that it is a ruby quest is 1/5.

  • The other value is the duration, the possibilities are 5 min, 15 min, 30 min, 1 hour, 2 hours, 4 hours, 8 hours, 1 day and 2 days.

  • The reward is given by the base value 0.01112 rubies times the level times the duration/5min (eg 30 min = 6) times a durations factor, since longer quest gives diminishing returns, given in the table below.

    5 min    1
    15 min   0.8594
    30 min   0.7785
    1 hour   0.624
    2 hours  0.5467
    4 hours  0.4687
    8 hours  0.3903
    1 day    0.3125
    2 days   0.25
  • This means we will always choose the shortest ruby quest and if there isn´t one the shortest other quest.

  • The cost to revive a mercenary is 10 + ceiling(1.5^level)

  • After reviving the quest is finished and then a new lifespan is generated

  • The level is going up by 1 for every day the mercenary spent questing and it starts at 1.

Input and Result

This program should require no input. In the case that your language is not able to generate values of a geometric distribution you may take random values from this list.

The result is a single number that represents at what point a mercenay should be discarded instead of revived.

The precision requirement is not a fixed value like 10%, but instead the accuracy should increase the more repetitions you run, so a perfect value should be theoretically possible given unlimited computation power.

The result of my simulation looks like this:

I used 50000 mercenarys per revive cap. Below 10000 gives spiky bits due to randomness

  • \$\begingroup\$ What do you mean by "within the day the distribution is linear'? What about precision issues? \$\endgroup\$ – lirtosiast Feb 11 '16 at 15:30
  • \$\begingroup\$ the chance to die in the first minute of the day is 1/1440 the chance to die in the second is 1/1440 and so on. It should be precise in the sense that running more "lifes" should result in an increase in accuray. \$\endgroup\$ – Eumel Feb 12 '16 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.