I am currently trying to create a script that computes the average cost (in stamina) of a produced item given the probabilities of its raw materials.
The activity involves gathering raw materials by chance at a cost then producing items from these raw materials at a cost.
Gathering Raw Materials
Gathering costs 15 stamina per attempt and yields raw materials based on the following probabilities.
- Upgrading Ore Tier 1 - 10%
- Upgrading Ore Tier 2 - 10%
- Upgrading Ore Tier 3 - 5%
- Enchanting Ore Tier 1 - 10%
- Enchanting Ore Tier 2 - 10%
- Enchanting Ore Tier 3 - 5%
- Else nothing
Combining and Dismantling Raw Materials
3 materials of a specific tier can be combined to produce 1 material of a higher tier. Dismantling materials does not cost any stamina.
- 3 Upgrading Ore Tier 1 = 1 Upgrading Ore Tier 2
- ...
- 3 Enchanting Ore Tier 1 = 1 Enchanting Ore Tier 2
- ...
A material of a specific tier can also be dismantled to produce 2 materials of a lower tier.
- 1 Upgrading Ore Tier 2 = 2 Upgrading Ore Tier 1
- ...
- 1 Enchanting Ore Tier 2 = 2 Enchanting Ore Tier 1
- ...
Production
Raw materials can be combined together to produce an item at the crafting cost of 50 stamina. The following crafting table is available.
- Upgrader Tier 1 - 10 Upgrading Ore Tier 1
- Enchanter Tier 1 - 15 Enchanting Ore Tier 1
- Upgrader Tier 2 - 9 Upgrading Ore Tier 2
- Enchanter Tier 2 - 16 Enchanting Ore Tier 2
- ...
Computing the Cost
Ignoring combining and dismantling of raw materials first, I assume that the stamina cost of getting 1 item is pretty straightforward. For example in the case of gathering an Upgrading Ore Tier 2 at 10% chance, the cost is computed as follows
cost = stamina / probability
cost = 15 / 0.1
cost = 150
So the average cost of an Upgrading Ore Tier 2 would be 150 stamina.
When taking combining and dismantling into consideration, in the case of an Upgrading Ore Tier 2, I did the following:
cost = ((10 / 0.3333) * 0.1 / (0.1 + 0.1 + 0.05) + (10 / 1) * 0.1 / (0.1 + 0.1 + 0.05) + (10 / 2) * 0.05 / (0.1 + 0.1 + 0.05)) / (0.1 + 0.1 + 0.05)
Trying to explain the equation I used above:
- I added the expected value of the costs based on the conversion and probability:
- 10 / 0.3333 - Cost of tier 2 when using only tier 1 materials
- 0.1 / (0.1 + 0.1 + 0.05) - I multiplied the above with this, which is the probability scaled to a 100%
- Since the total is still below 100%, I scaled it up to a 100%, thus the
- sum / (0.1 + 0.1 + 0.05)
Is this correct? If not, what is the better approach? Is there a better way to generalize this? To be honest, I'm pretty lost at this point.
Also, apologies for the lack of language in explaining the problem above.