Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Gem calculation formulas.

  1. #1
    He who has not yet claimed his title dahimi's Avatar
    Join Date
    Sep 2012
    Location
    Hello Kitty Adventure Island
    Posts
    10,807

    Gem calculation formulas.

    I've gotten a few requests for how the wiki calculators work, so I figured I'd post it here.

    Gem expenditures are based on a series of plateaus. At each plateau the number of resources per gem increases. Between plateaus the number of resources per gem is constant.

    This means that the gem calculations are based on the slope between the plateaus.

    For example the plateaus for gold/elixir are:

    100 - 1 gem
    1000 - 5 gems
    10000 - 25 gems
    100000 - 125 gems
    1000000 - 600 gems
    10000000 - 3000 gems

    So let's say you wanted to buy 5000 gold or elixir. You look at the plateaus and see that 5000 falls between the 1000 and 10000 resource plateaus.

    We know the first 1000 resources costs 5 gems. The calculations for the rest are based on the slope of the line between the 1000 and 10000 gem resource plateaus.

    That yields the following formula:

    (5000 - 1000)/((10000 - 1000)/(25 - 5)) + 5
    = 4000/(9000/20) + 5
    = 4000/450 + 5
    ~14 gems

    There are two corner cases; the gem amounts for resources lower than the first plateau and gem amounts for resources greater than the max you can store. These are easily handled. For the first case, any resources less than 100 will also cost 1 gem. For the second case you simply make multiple purchases until you reach the desired amount.

    Dark Elixir works similarly, but costs 100 times as much.

    1 - 1 gem
    10 - 5 gems
    100 - 25 gems
    1000 - 125 gems
    10000 - 600 gems
    100000 - 3000 gems

    Other than the cost, the one difference is that the max plateau is lower than the max you can store. In this case the calculations just continue using the slope for the highest range.

    For example if you wanted to buy 150,000 DE, that would yield the following formula:

    (150000 - 10000)/((100000 - 10000)/(3000-600)) + 600
    = 140000/(90000/2400) + 600
    = 140000/37.5 + 600
    ~4333 gems

    Alternatively you could calculate it this way:
    (150000 - 100000)/((100000 - 10000)/(3000-600)) + 3000
    = 50000/37.5 + 3000
    ~4333 gems

    Here are the plateaus for time:

    60 seconds (1 min) - 1 gem
    3600 seconds (1 hour) - 20 gems
    86400 seconds (1 day) - 260 gems
    604800 seconds (1 week) - 1000 gems

    The one difference is that gem costs for time are always rounded down. So if you start an upgrade for a level 11 archer tower which takes 7 days and wait one second the gem cost will go from 1000 to 999 immediately.

    The following is the javascript I use on the wiki for the resource cost calculations:


    Code:
    function doCalcResourceToGems (resources) {
       var ranges = [100,1000,10000,100000,1000000,10000000];
       var gems = [1,5,25,125,600,3000];
       var storagemax = 8001000;
     
       if (isNaN(resources)) return("???");
     
       if (resources < 0) return("???");
       else if (resources == 0) return(0);
       else if (resources <= ranges[0]) return(gems[0]);
     
       for (var i = 1; i < ranges.length-1; i++)
          if (resources <= ranges[i]) 
             return(Math.round((resources - ranges[i-1])/((ranges[i] - ranges[i-1])/(gems[i] - gems[i-1])) + gems[i-1]));
     
       if (resources <= storagemax)
          return(Math.round((resources - ranges[ranges.length-2])/((ranges[ranges.length-1] - ranges[ranges.length-2])/(gems[gems.length-1] - gems[gems.length-2])) + gems[gems.length-2]));           
       else 
          return(doCalcResourceToGems(resources % storagemax) + Math.floor(resources/storagemax)*doCalcResourceToGems(storagemax));
     
       return("???");
    }

  2. #2
    Super Member mediapluck's Avatar
    Join Date
    Sep 2012
    Posts
    905
    Thanks for sharing this.
    Clan Leader of The Bullies clan. "We need your gold more than you do."

    Join the Clash of Clans community blog at COCBLOG.COM.

  3. #3
    Pro Member
    Join Date
    Nov 2012
    Location
    Chicago
    Posts
    517
    Very cool. Did you get the info from the game files? observation? Or did someone from SC share it at some point?

    ~Jeff

  4. #4
    He who has not yet claimed his title dahimi's Avatar
    Join Date
    Sep 2012
    Location
    Hello Kitty Adventure Island
    Posts
    10,807
    Quote Originally Posted by GameShaman View Post
    Very cool. Did you get the info from the game files? observation? Or did someone from SC share it at some point?

    ~Jeff
    The plateaus are from the in game files. The formulas were worked out via observation. SC seldom shares anything specific about internal numbers.

  5. #5
    Senior Member N1mrod's Avatar
    Join Date
    Feb 2013
    Location
    53.4831° N 2.2003° W
    Posts
    475
    thanks for this, been looking everywhere for the time formula
    Level 97, TH9
    Member of Unity Titans (but too lazy/stupid to put in the cool signature pics)
    gamecenter: (-)N1mrod(-) (I'll reject you and laugh though)
    URL for video the of best moment ever
    http://www.youtube.com/watch?v=7MQperfaJY8

  6. #6
    Fresh Spawn
    Join Date
    Nov 2014
    Posts
    4
    If you plot those plateaus you get these nice graphs (attached below for DE and Time) and a VERY good formula for calculating Gem cost.
    Gem = 1,0098*DE^0,6949 (Rē=1, perfect)
    Gem = 0,0443*Time^0,7558 (Rē=0,9995)
    Attached Images Attached Images

  7. #7
    Great work!!!! Awesome!!

    Thanks for sharing!


    Manage your village and rise beating your rivals! New feature: The Clan War Manager!

    You'll have all the data of your village and troops to make the best decisions.

    Discover if your clan is the strongest with our Ranking.


  8. #8
    Forum Champion
    Join Date
    Apr 2013
    Location
    IN MEH HOUSE
    Posts
    5,588
    This makes me feel so stupid.

    Nice job!
    IGN: Pranav | Clan: Legendary Kings [#8VYVC88R] | I am the man with no avatar.
    Quote Originally Posted by oyy
    Who took the Ayy username? i want it now
    Quote Originally Posted by BlindHaze
    I think Ayy took it.

    My Journey + More

  9. #9
    This is my java code, just var-->type conversions from your code.

    Code:
    public static double doCalcResourceToGems(double resources) {
        double[] ranges ={100, 1000, 10000, 100000, 1000000, 10000000};
        double[] gems ={1, 5, 25, 125, 600, 3000};
        double storagemax = 8001000;
    
    
        if (resources <= 0) return (0);
        else if (resources <= ranges[0]) return (gems[0]);
    
        for (int i = 1; i < ranges.length - 1; i++)
            if (resources <= ranges[i])
                return (Math.round((resources - ranges[i - 1]) / ((ranges[i] - ranges[i - 1]) / (gems[i] - gems[i - 1])) + gems[i - 1]));
    
        if (resources <= storagemax){
            System.out.println("2"+ranges.length);
            return (Math.round((resources - ranges[ranges.length - 2]) / ((ranges[ranges.length - 1] - ranges[ranges.length - 2]) / (gems[gems.length - 1] - gems[gems.length - 2])) + gems[gems.length - 2]));}
        else{
            System.out.println("3");
            return(doCalcResourceToGems(resources % storagemax) + Math.floor(resources/storagemax)*doCalcResourceToGems(storagemax));}
    
    }
    But now when condition resource greater than storagemax, my results an the COC.wikia results doesn't match
    any idea??

    i made some mistakes in conversion now they work fine
    Last edited by AshokVarma; December 30th, 2014 at 12:59 AM. Reason: working

  10. #10

    DarkElixir and Time max elements

    storagemax for darkelixir =??
    and is there any max for time, if not what we have to do ??

    and in game files where did you found the plateaus, so we can access them if any changes occured in future

    thanks for the answer
    storagemax for darkelixir = 200000;
    Last edited by AshokVarma; December 30th, 2014 at 12:58 AM. Reason: Got the answer fromdahimi

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •