xxfillex

Cookie Clicker godzamok calculator

Jun 25th, 2023 (edited)
1,332
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 10.34 KB | Gaming | 1 0
  1. var fingersAdd=0
  2. var mouseMult=0
  3. var totMilkMult=1
  4. var totBuildMult=1
  5. var totClickMult=1
  6. var numberOfObjects=Object.keys(Game.Objects).length
  7. var baseClickingStrength=1
  8. var objAmountList=[]
  9. var objOwnedList=[]
  10. var bestOwnedList=[]
  11. var highestClickPow=0
  12. var skipBuilding=[]
  13. var sellTimeLoss=0.2
  14. var staticTimeLoss=2
  15. var clickSpeed=15
  16. var templeList=[0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0]
  17. var skipExtraList=[0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,1]
  18. var toWTRebuyList=[0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1]
  19.  
  20. FindOptimal=function(skip, spendable) {
  21.   //kinda does the whole process kinda stuff thing
  22.   return ReformatBuildingList(GetBuildings(FindGodzamokable(skip),spendable))
  23.   };
  24.  
  25. CalculateClickGain=function() {
  26.   //returns how much total you would gain from clicking with godzamok
  27.   //uses the global lists objAmountList and objOwnedList to see how many buildings are sold to godzamok
  28.   var numSold=0
  29.   var amountSold=0
  30.   for (var obj in objOwnedList) {if (!objOwnedList[obj]) {numSold++; amountSold+=objAmountList[obj]}}
  31.   var clickPow=(1+0.01*amountSold)*CalculateClickStrength()*clickSpeed*(10-staticTimeLoss-(sellTimeLoss*numSold));
  32.   return clickPow
  33.   };
  34.  
  35. BinaryLoop=function(i) {
  36.   //takes how many more recursions it should do as input
  37.   //calculates whether the combination is the best combination on the deepest recursion (normally 0)
  38.   //each time the function is called, it checks all combinations of deeper recursions for itself being 0 or 1, making it count in binary
  39.   for (var flip=0; flip<2; flip++) {
  40.     for (var nextIter=i-1; nextIter>=0; nextIter--) {if (!skipBuilding[nextIter]) {break}}
  41.     if (nextIter>=0) {BinaryLoop(nextIter)} else {
  42.       var clickPow=CalculateClickGain()
  43.       if (clickPow>highestClickPow) {
  44.         highestClickPow=clickPow;
  45.         bestOwnedList=[...objOwnedList];
  46.         };
  47.       };
  48.     if (objOwnedList[i]!=flip) {objOwnedList[i]=flip; Game.ObjectsById[i].amount=flip?objAmountList[i]:0};
  49.     };
  50.   };
  51.  
  52. FindGodzamokable=function(skip) {
  53.   //takes an input of a list of 0s and 1s, where 1 indicates that the building should not be sold to godzamok ever
  54.   //returns the list of buildings that should be sold to godzamok
  55.   //finds and prints buildings that should be sold to godzamok, as well as making the bestOwnedList list reflect those buildings
  56.   //skipping more buildings makes the function significantly faster
  57.   //templeList can be used to skip only temples, making a thorough search
  58.   //calls the recursive function BinaryLoop to check every single combination of non-skipped buildings
  59.   InitMouseVars();
  60.   InitCpSVars();
  61.   objAmountList=[]
  62.   objOwnedList=[]
  63.   skipBuilding=[]
  64.   bestOwnedList=[]
  65.   highestClickPow=0
  66.   for (var i = 0; i < numberOfObjects; i++) {
  67.     objAmountList.push(Game.ObjectsById[i].amount)
  68.     objOwnedList.push(1)
  69.     if (skip) {if (skip[i]==1) {skipBuilding.push(1)} else {skipBuilding.push(0)}};
  70.     };
  71.   iterLength=-1;
  72.   for (var i=numberOfObjects-1; i>=0; i--) {if (!skipBuilding[i]) {iterLength=i; break}}
  73.   if (iterLength>=0) BinaryLoop(iterLength)
  74.   for (var i = 0; i < numberOfObjects; i++) {
  75.     if (bestOwnedList[i]==0) console.log(Game.ObjectsById[i].name)
  76.     };
  77.   console.log(bestOwnedList, highestClickPow);
  78.   return bestOwnedList
  79.   };
  80.  
  81. GetBuildings=function(objList, spendable, rebuy) {
  82.   //takes the list of buildings sold to godzamok, cookies, and a boolean for whether you're rebuying as input
  83.   //bestOwnedList from FindGodzamokable can be used for objList
  84.   //Makes the building count optimal and changes the objAmountList to reflect that, and returns objAmountList
  85.   InitMouseVars();
  86.   InitCpSVars();
  87.   if (!spendable) spendable=Game.cookies;
  88.   var clickPow=0
  89.   var vList=[]
  90.   objAmountList=[]
  91.   objOwnedList=[...objList]
  92.   for (var i = 0; i < numberOfObjects; i++) {
  93.     Game.ObjectsById[i].amount=0
  94.     Game.ObjectsById[i].price=Game.ObjectsById[i].getPrice()
  95.     objAmountList.push(Game.ObjectsById[i].amount)
  96.     };
  97.   for (var i=0; i<9999; i++) {
  98.     for (var obj = 0; obj < numberOfObjects; obj++) {
  99.       var me=Game.ObjectsById[obj];
  100.       clickPow=CalculateClickGain();
  101.       if (objOwnedList[obj]) me.amount++;
  102.       objAmountList[obj]++;
  103.       vList[obj]=(CalculateClickGain()-clickPow)/me.price;
  104.       if (objOwnedList[obj]) me.amount--;
  105.       objAmountList[obj]--;
  106.       };
  107.     var bestObj=vList.indexOf(Math.max(...vList))
  108.     var me=Game.ObjectsById[bestObj]
  109.     var cost=me.price
  110.     var bulkCost=me.bulkPrice
  111.     if (bulkCost<(spendable/1000)) {spendable-=bulkCost; objAmountList[bestObj]+=100}
  112.     else if (cost<spendable) {spendable-=cost; objAmountList[bestObj]++}
  113.     else {me.price=me.getPrice(); break}
  114.     me.amount=objAmountList[bestObj]
  115.     me.price=me.getPrice()
  116.     me.bulkPrice=me.getSumPrice(100)
  117.     if (!objOwnedList[bestObj] && !rebuy) {me.amount=0};
  118.     };
  119.   var buildCount=0
  120.   for (var obj = 0; obj < numberOfObjects; obj++) {
  121.     Game.ObjectsById[obj].amount=objAmountList[obj];
  122.     Game.ObjectsById[obj].amount--;
  123.     Game.ObjectsById[obj].buyFree(1);
  124.     buildCount+=Game.ObjectsById[obj].amount
  125.     };
  126.   Game.BuildingsOwned=buildCount
  127.   return objAmountList
  128.   };
  129.  
  130. ReformatBuildingList=function(aList) {
  131.   //takes a building amount list as inputs to reformat it to a relative list, which is used in CCCEM
  132.   //returns the reformated list
  133.   rList=[]
  134.   for (var obj = 1; obj < numberOfObjects; obj++) {
  135.     rList.push(aList[obj]-aList[obj-1])
  136.     };
  137.   return rList
  138.   };
  139.  
  140. InitMouseVars=function()
  141.         {
  142.             //code copied from https://orteil.dashnet.org/cookieclicker/main.js
  143.             //changed to make variables permanent rather than calculated every time
  144.             fingersAdd=0
  145.             mouseMult=0
  146.             if (Game.Has('Thousand fingers')) fingersAdd+=      0.1;
  147.             if (Game.Has('Million fingers')) fingersAdd*=       5;
  148.             if (Game.Has('Billion fingers')) fingersAdd*=       10;
  149.             if (Game.Has('Trillion fingers')) fingersAdd*=      20;
  150.             if (Game.Has('Quadrillion fingers')) fingersAdd*=   20;
  151.             if (Game.Has('Quintillion fingers')) fingersAdd*=   20;
  152.             if (Game.Has('Sextillion fingers')) fingersAdd*=    20;
  153.             if (Game.Has('Septillion fingers')) fingersAdd*=    20;
  154.             if (Game.Has('Octillion fingers')) fingersAdd*=     20;
  155.             if (Game.Has('Nonillion fingers')) fingersAdd*=     20;
  156.             if (Game.Has('Decillion fingers')) fingersAdd*=     20;
  157.             if (Game.Has('Undecillion fingers')) fingersAdd*=   20;
  158.             if (Game.Has('Unshackled cursors')) fingersAdd*=    25;
  159.            
  160.             var num=0;
  161.             for (var i in Game.Objects) {num+=Game.Objects[i].amount;}
  162.             num-=Game.Objects['Cursor'].amount;
  163.             fingersAdd=fingersAdd*num;
  164.             if (Game.Has('Plastic mouse')) mouseMult+=0.01;
  165.             if (Game.Has('Iron mouse')) mouseMult+=0.01;
  166.             if (Game.Has('Titanium mouse')) mouseMult+=0.01;
  167.             if (Game.Has('Adamantium mouse')) mouseMult+=0.01;
  168.             if (Game.Has('Unobtainium mouse')) mouseMult+=0.01;
  169.             if (Game.Has('Eludium mouse')) mouseMult+=0.01;
  170.             if (Game.Has('Wishalloy mouse')) mouseMult+=0.01;
  171.             if (Game.Has('Fantasteel mouse')) mouseMult+=0.01;
  172.             if (Game.Has('Nevercrack mouse')) mouseMult+=0.01;
  173.             if (Game.Has('Armythril mouse')) mouseMult+=0.01;
  174.             if (Game.Has('Technobsidian mouse')) mouseMult+=0.01;
  175.             if (Game.Has('Plasmarble mouse')) mouseMult+=0.01;
  176.             if (Game.Has('Miraculite mouse')) mouseMult+=0.01;
  177.             if (Game.Has('Aetherice mouse')) mouseMult+=0.01;
  178.             if (Game.Has('Omniplast mouse')) mouseMult+=0.01;
  179.            
  180.             if (Game.Has('Fortune #104')) mouseMult+=0.01;
  181.  
  182.             if (Game.Has('Santa\'s helpers')) totClickMult*=1.1;
  183.             if (Game.Has('Cookie egg')) totClickMult*=1.1;
  184.             if (Game.Has('Halo gloves')) totClickMult*=1.1;
  185.             if (Game.Has('Dragon claw')) totClickMult*=1.03;
  186.            
  187.             if (Game.Has('Aura gloves'))
  188.             {
  189.                 totClickMult*=1+0.05*Math.min(Game.Objects['Cursor'].level,Game.Has('Luminous gloves')?20:10);
  190.             }
  191.            
  192.             totClickMult*=Game.eff('click');
  193.            
  194.             if (Game.hasGod)
  195.             {
  196.                 var godLvl=Game.hasGod('labor');
  197.                 if (godLvl==1) totClickMult*=1.15;
  198.                 else if (godLvl==2) totClickMult*=1.1;
  199.                 else if (godLvl==3) totClickMult*=1.05;
  200.             }
  201.            
  202.             for (var i in Game.buffs)
  203.             {
  204.                 if (typeof Game.buffs[i].multClick != 'undefined') totClickMult*=Game.buffs[i].multClick;
  205.             }
  206.            
  207.             totClickMult*=1+Game.auraMult('Dragon Cursor')*0.05;
  208.            
  209.             baseClickingStrength*=Math.pow(2,Game.Has('Reinforced index finger')+Game.Has('Carpal tunnel prevention cream')+Game.Has('Ambidextrous'))
  210.            
  211.             return
  212.         }
  213.  
  214. InitCpSVars=function()
  215.         {
  216.             //code copied from https://orteil.dashnet.org/cookieclicker/main.js
  217.             //changed to make variables permanent rather than calculated every time
  218.             numberOfObjects=Object.keys(Game.Objects).length
  219.             totMilkMult=1
  220.             totBuildMult=1
  221.             if (Game.hasGod)
  222.             {
  223.                 var godLvl=Game.hasGod('decadence');
  224.                 if (godLvl==1) totBuildMult*=0.93;
  225.                 else if (godLvl==2) totBuildMult*=0.95;
  226.                 else if (godLvl==3) totBuildMult*=0.98;
  227.                
  228.                 var godLvl=Game.hasGod('industry');
  229.                 if (godLvl==1) totBuildMult*=1.1;
  230.                 else if (godLvl==2) totBuildMult*=1.06;
  231.                 else if (godLvl==3) totBuildMult*=1.03;
  232.                
  233.                 var godLvl=Game.hasGod('labor');
  234.                 if (godLvl==1) totBuildMult*=0.97;
  235.                 else if (godLvl==2) totBuildMult*=0.98;
  236.                 else if (godLvl==3) totBuildMult*=0.99;
  237.             }
  238.             Game.milkProgress=Game.AchievementsOwned/25;
  239.             if (Game.Has('Santa\'s milk and cookies')) totMilkMult*=1.05;
  240.             totMilkMult*=1+Game.auraMult('Breath of Milk')*0.05;
  241.             if (Game.hasGod)
  242.             {
  243.                 var godLvl=Game.hasGod('mother');
  244.                 if (godLvl==1) totMilkMult*=1.1;
  245.                 else if (godLvl==2) totMilkMult*=1.05;
  246.                 else if (godLvl==3) totMilkMult*=1.03;
  247.             }
  248.             totMilkMult*=Game.eff('milk');
  249.         }
  250.  
  251. CalculateClickStrength=function() {
  252.   //returns how much you gain from 1 click, mostly only recalculating the things that change. Seems optimized enough for now
  253.   Game.cookiesPs=0
  254.   for (var i in Game.Objects) {
  255.     var me=Game.Objects[i];
  256.     me.storedCps=me.cps(me);
  257.     if (Game.ascensionMode!=1) me.storedCps*=(1+me.level*0.01)*totBuildMult;
  258.     if (me.id==1 && Game.Has('Milkhelp&reg; lactose intolerance relief tablets')) me.storedCps*=1+0.05*Game.milkProgress*totMilkMult;
  259.     me.storedTotalCps=me.amount*me.storedCps;
  260.     Game.cookiesPs+=me.storedTotalCps;
  261.     }
  262.   if (Game.Has('"egg"')) {Game.cookiesPs+=9;Game.cookiesPsByType['"egg"']=9;}//"egg"
  263.   Game.cookiesPs*=Game.globalCpsMult;
  264.   var out=totClickMult*(Game.cookiesPs*mouseMult+baseClickingStrength+fingersAdd)
  265.   return out
  266.   };
  267.  
  268. InitMouseVars();
  269. InitCpSVars();
Advertisement
Add Comment
Please, Sign In to add comment