Author Topic: Math question (upgrade material costs)  (Read 426 times)

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Math question (upgrade material costs)
« on: January 14, 2012, 10:33:27 AM »
Players can upgrade their mansion. Each level of mansion should cost 500 gold more than previous one (level 1 500, level 2 1000, level 3 1500, etc). I want half of this cost to be paid via gold directly and half via materials. The materials cost does not need to be perfectly 250 (500/2) per level, actually it would be impossible to fit if perfectly due to various material costs, just something near it.

I also want higher levels of the mansion to require more advanced materials (just more advanced, not more expensive total). First wood, then stone, then bricks, then marble.

Example:
Level 1: 10 stamina, 250 gold coins, 250 materials (wood 90%, stone 10%)
Level 2: 10 stamina, 500 gold coins, 500 materials (wood 80%, stone 20%)
Level 3: 10 stamina, 750 gold coins, 750 materials (wood 70%, stone 20%, bricks 10%)
Level 4: 10 stamina, 1000 gold coins, 1000 materials (wood 60%, stone 20%, bricks 20%)
Level 5: 10 stamina, 1250 gold coins, 1250 materials (wood 50%, stone 30%, bricks 20%)
Level 6: 10 stamina, 1500 gold coins, 1500 materials (wood 40%, stone 30%, bricks 30%)
Level 7: 10 stamina, 1750 gold coins, 1750 materials (wood 30%, stone 30%, bricks 30%, marble 10%)
(ignore stamina, the % is just an example, it does not have to be like that)

There would be no problem if all materials costed the same, but these are not...
* wood 0.40 gold
* stone 0.90 gold
* bricks 1.00 gold
* marble 3.00 gold

How to make a formula/algorithm which will detemine which materials and how many each estate level require?
(again, I don't need a solution identical to what I described, just something similar in the spirit)

Offline Nox

  • Level 35
  • **
  • Posts: 768
  • Reputation: +12/-2
    • View Profile
Re: Math question (upgrade material costs)
« Reply #1 on: January 14, 2012, 02:02:43 PM »
That's similar to the loot formula you asked for some time ago, right?

So as long as materials have the same cost you can create the mechanism?

Well in that case a modification for varying costs, I believe it should be like:

1) calculate as if the cost is the same
2) divide the calculated material costs by the multiplier
3) divide the target total materials by the sum of costs from (2)
4) divide each of the costs from (2) by the coeficient from (3)

Please try it out and tell if it yields proper results
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: Math question (upgrade material costs)
« Reply #2 on: January 14, 2012, 04:14:14 PM »
That's similar to the loot formula you asked for some time ago, right?
Really? I don't see any, but who knows, maybe there are similarities... :)

Actually, the question is about 2 completely different things.
1) what should be the percentage composition of materials on each level of the mansion (it is partially eastetic/gameplay question)
2) how many of each material is required for a given mansion level
So I need 2 formulas, first one to prepare the list of required resources and the second that will give me the exact resources needed.

I also realized that instead calling the materials for each level "percentage", it should be "weight".

Probably something like this:
woodweight=100-level;
stoneweight=10+level; if(level>10) stoneweight-=level;
brickweight=0+max(0,level-10);

So level 1 mansion would require resources in this proportion 99/11/0, level 10 = 90/20/0, level 15 = 85/10/5.

Then a second formula would get the recommended_total_cost, prices of each resource, the proportion and return how many of each resource is used.


Quote
1) calculate as if the cost is the same
2) divide the calculated material costs by the multiplier
3) divide the target total materials by the sum of costs from (2)
4) divide each of the costs from (2) by the coeficient from (3)
I don't understand :)

Offline Nox

  • Level 35
  • **
  • Posts: 768
  • Reputation: +12/-2
    • View Profile
Re: Math question (upgrade material costs)
« Reply #3 on: January 14, 2012, 04:26:47 PM »
1) I believe you're the only one that can answer that right now ... difficult for us to say with no info and no balance testing availible
2)
a) Well the first part is easy:
Stamina = 10
Gold = Materials = level * 250 ... if you want non-linear, I believe you're capable to do this by yourself, just pass some pow($level * const, around 1.x I guess). You can use a spreadsheet calculator or a graph soft to test various equations

b)
Quote
I also realized that instead calling the materials for each level "percentage", it should be "weight".
Imho doesn't matter, you can convert percentage <= => weight

Code: [Select]
$totalMaterials = getTotalMaterialsCost(); // e.g. 1750
$materials = getMaterialsCosts(); // array[wood, stone, bricks...] ints, 1750 * respective %

foreach($materials as $key => $material)
     $materials[$key] *= $materialCostRatio[$key];

$totalRatio = $totalMaterials / array_sum($materials);

foreach($materials as $key => $material)
     $materials[$key] *= $totalRatio;

var_dump($materials); // final materials costs
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: Math question (upgrade material costs)
« Reply #4 on: January 14, 2012, 04:56:31 PM »
OK, I got the answer to the second question, it's rather trivial after thinking :)

wood_needed=totalprice*wood_percentage/100/wood_price; // repeat for stone, bricks and marble

So level 7 would be 1750*30/100/0.40=1312 wood (worth 524 gold which is about 30%)


Imho doesn't matter, you can convert percentage <= => weight
Indeed...


1) I believe you're the only one that can answer that right now ... difficult for us to say with no info and no balance testing availible
No, no. Just the general concept here. You build a mansion. At the beginning it is just a meager hut made of wood, then you start using stone, next bricks, and finally marble. I'm here for the "mood", just an impression. Because mathematically it does not matter, since you can always buy the materials and the materials total cost will be the same no matter which composition of materials you used.

I guess, its turning into a design/aestetic question :)
« Last Edit: January 15, 2012, 08:26:11 AM by Chris »

Offline AltarofScience

  • Level 12
  • *
  • Posts: 90
  • Reputation: +1/-0
    • View Profile
Re: Math question (upgrade material costs)
« Reply #5 on: January 14, 2012, 09:39:33 PM »
OK, I got the answer to the second question, it's rather trivial after thinking :)

wood_needed=totalprice*wood_percentage/100/wood_price; // repeat for stone, bricks and marble

So level 7 would be 1750*30/100/0.40=1312 wood (worth 524 gold which is about 30%)


Imho doesn't matter, you can convert percentage <= => weight
Indeed...


1) I believe you're the only one that can answer that right now ... difficult for us to say with no info and no balance testing availible
No, no. Just the general concept here. You build a mansion. At the beginning it is just a meager hut made of wood, then you start using stone, next bricks, and finally marble. I'm here for the "mood", just an impression. Because mathematically it does not matter, since you can always buy the materials and the materials total cost will be the same no matter which composition of materials you used.

I guess, its turning into a design/eastetic question :)

aesthetic? reading your spelling is driving me insane.

Offline arai

  • Level 6
  • *
  • Posts: 22
  • Reputation: +1/-0
    • View Profile
Re: Math question (upgrade material costs)
« Reply #6 on: January 14, 2012, 10:52:39 PM »
Then stop reading his spelling  :P

Offline Nox

  • Level 35
  • **
  • Posts: 768
  • Reputation: +12/-2
    • View Profile
Re: Math question (upgrade material costs)
« Reply #7 on: January 15, 2012, 01:46:22 AM »
I think quoting a large post just to rant about spelling typo is way worse

Besides given Chris isn't from an English-speaking country his posts are well-written except a few mistakes

So unless it's written in a really incomprehensible way (which this is not in a slightest), I would not bash on that ... if it bugs you so much,
you can kindly notify the author via PersonalMessage or in a "P.S." part of your otherwise on-topic post.
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: Math question (upgrade material costs)
« Reply #8 on: January 15, 2012, 09:23:04 AM »
aesthetic? reading your spelling is driving me insane.
Fixed.

So, back to the core question, how would you do something like that: "You build a mansion. At the beginning it is just a meager hut made of wood, then you start using stone, next bricks, and finally marble. I'm here for the "mood", just an impression. Because mathematically it does not matter, since you can always buy the materials and the materials total cost will be the same no matter which composition of materials you used"?

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal