markuspeloquin

secret_cookie_wizard.user.js

Oct 20th, 2013
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        Secret cookie wizard
  3. // @namespace       http://cs.wisc.edu/~markus
  4. // @description     Tells you what option you are supposed to pick, taking into account time to achieve the option. This has been updated for the 2014-04-09 update.
  5. // @version     0.10.1
  6. // @include     http://orteil.dashnet.org/cookieclicker/
  7. // ==/UserScript==
  8.  
  9. function Secret_cookie_wizard()
  10. {
  11.  
  12. function real_game()
  13. {
  14.     try {
  15.         return Game;
  16.     } catch (e) {}
  17.     return null;
  18. }
  19. window.real_game = real_game;
  20.  
  21. (function () {
  22.  
  23. var BASE_COSTS = [15, 100, 500, 3000, 10000, 40000,
  24.     200000, 1666666, 123456789, 3999999999, 75000000000];
  25. var BASE_RATES = [.1, .5, 4, 10, 40, 100, 400,
  26.     6666, 98765, 999999, 10000000];
  27. var TIER1 = 10;
  28. var TIER2 = 100;
  29. var TIER3 = 1000;
  30. var TIER4 = 50000;
  31. var TIER5 = 1000000;
  32. var TIER6 = 8000000000;
  33. var UPGRADE_COST = {
  34.     // 1
  35.     //'elder pledge':               1,
  36.     // 2
  37.     'heavenly chip secret':         11,
  38.     'a festive hat':            25, // ignored
  39.     // 3
  40.     'reinforced index finger':      100,
  41.     'carpal tunnel prevention cream':   400,
  42.     // 4
  43.     'forwards from grandma':        BASE_COSTS[1] * TIER1, // 1000
  44.     'heavenly cookie stand':        1111,
  45.     'a lump of coal':           2525,
  46.     'an itchy sweater':         2525,
  47.     'ho ho ho-flavored frosting':       2525, // ignored
  48.     'improved jolliness':           2525,
  49.     'increased merriness':          2525,
  50.     'naughty list':             2525,
  51.     'reindeer baking grounds':      2525, // ignored
  52.     'santa\'s bottomless bag':      2525, // ignored
  53.     'santa\'s dominion':            2525,
  54.     'santa\'s helpers':         2525,
  55.     'santa\'s legacy':          2525,
  56.     'santa\'s milk and cookies':        2525,
  57.     'season savings':           2525,
  58.     'toy workshop':             2525,
  59.     'weighted sleighs':         2525, // ignored
  60.     'cheap hoes':               BASE_COSTS[2] * TIER1, // 5000
  61.     // 5
  62.     'ambidextrous':             10000,
  63.     'steel-plated rolling pins':        BASE_COSTS[1] * TIER2, // 10000
  64.     'sturdier conveyor belts':      BASE_COSTS[3] * TIER1, // 30000
  65.     'farmer grandmas':          BASE_COSTS[2] * TIER2, // 50000
  66.     'fertilizer':               BASE_COSTS[2] * TIER2, // 50000
  67.     'plastic mouse':            50000,
  68.     // 6
  69.     'lubricated dentures':          BASE_COSTS[1] * TIER3, // 100000
  70.     'sugar gas':                BASE_COSTS[4] * TIER1, // 100000
  71.     'heavenly bakery':          111111,
  72.     'worker grandmas':          BASE_COSTS[3] * TIER2, // 300000
  73.     'child labor':              BASE_COSTS[3] * TIER2, // 300000
  74.     'vanilla nebulae':          BASE_COSTS[5] * TIER1, // 400000
  75.     'cookie trees':             BASE_COSTS[2] * TIER3, // 500000
  76.     'thousand fingers':         500000,
  77.     // 7
  78.     'miner grandmas':           BASE_COSTS[4] * TIER2, // 1000000
  79.     'megadrill':                BASE_COSTS[4] * TIER2, // 1000000
  80.     'antimony':             BASE_COSTS[6] * TIER1, // 2000000
  81.     'sweatshop':                BASE_COSTS[3] * TIER3, // 3000000
  82.     'cosmic grandmas':          BASE_COSTS[5] * TIER2, // 4000000
  83.     'wormholes':                BASE_COSTS[5] * TIER2, // 4000000
  84.     'iron mouse':               5000000,
  85.     'prune juice':              BASE_COSTS[1] * TIER4, // 5000000
  86.     'kitten helpers':           9000000,
  87.     // 8
  88.     'ultradrill':               BASE_COSTS[4] * TIER3, // 10000000
  89.     'ancient tablet':           BASE_COSTS[7] * TIER1, // 16666660
  90.     'essence of dough':         BASE_COSTS[6] * TIER2, // 20000000
  91.     'transmuted grandmas':          BASE_COSTS[6] * TIER2, // 20000000
  92.     'genetically-modified cookies':     BASE_COSTS[2] * TIER4, // 25000000
  93.     'heavenly confectionery':       11111111,
  94.     'frequent flyer':           BASE_COSTS[5] * TIER3, // 40000000
  95.     'million fingers':          50000000,
  96.     'oatmeal raisin cookies':       99999999,
  97.     'peanut butter cookies':        99999999,
  98.     'plain cookies':            99999999,
  99.     'sugar cookies':            99999999,
  100.     // 9
  101.     'double-thick glasses':         BASE_COSTS[1] * TIER5, // 100000000
  102.     'radium reactors':          BASE_COSTS[3] * TIER4, // 150000000
  103.     'altered grandmas':         BASE_COSTS[7] * TIER2, // 166666600
  104.     'insane oatling workers':       BASE_COSTS[7] * TIER2, // 166666600
  105.     'true chocolate':           BASE_COSTS[6] * TIER3, // 400000000
  106.     'billion fingers':          500000000,
  107.     'gingerbread scarecrows':       BASE_COSTS[2] * TIER5, // 500000000
  108.     'titanium mouse':           500000000,
  109.     'ultimadrill':              BASE_COSTS[4] * TIER4, // 500000000
  110.     'lucky day':                777777777, // ignored
  111.     'coconut cookies':          999999999,
  112.     'macadamia nut cookies':        999999999,
  113.     'white chocolate cookies':      999999999,
  114.     // 10
  115.     'heavenly key':             1111111111,
  116.     'flux capacitors':          1234567890,
  117.     'soul bond':                BASE_COSTS[7] * TIER3, // 1666666000
  118.     'warp drive':               BASE_COSTS[5] * TIER4, // 2000000000
  119.     'recombobulators':          BASE_COSTS[3] * TIER5, // 3000000000
  120.     'trillion fingers':         5000000000,
  121.     //'revoke elder covenant':      6666666666,
  122.     'kitten workers':           9000000000,
  123.     'time paradox resolver':        9876543210,
  124.     // 11
  125.     'ambrosia':             BASE_COSTS[6] * TIER4, // 10000000000
  126.     'h-bomb mining':            BASE_COSTS[4] * TIER5, // 10000000000
  127.     'specialized chocolate chips':      10000000000,
  128.     'grandmas\' grandmas':          BASE_COSTS[8] * TIER2, // 12345678900
  129.     'designer cocoa beans':         20000000000,
  130.     'sugar bosons':             BASE_COSTS[9] * TIER1, // 39999999990
  131.     'chocolate monoliths':          BASE_COSTS[5] * TIER5, // 40000000000
  132.     'ritual rolling pins':          40000000000,
  133.     'adamantium mouse':         50000000000,
  134.     'quadrillion fingers':          50000000000,
  135.     'serendipity':              77777777777, // ignored
  136.     'underworld ovens':         80000000000,
  137.     'sanity dance':             BASE_COSTS[7] * TIER4, // 83333300000
  138.     'quantum conundrum':            98765456789,
  139.     'all-chocolate cookies':        99999999999,
  140.     'double-chip cookies':          99999999999,
  141.     'white chocolate macadamia nut cookies':
  142.                         99999999999,
  143.     // 12
  144.     'bingo center':             100000000000,
  145.     'persistent memory':            100000000000,
  146.     'one mind':             160000000000,
  147.     'aqua crustulae':           BASE_COSTS[6] * TIER5, // 200000000000
  148.     'christmas tree biscuits':      252525252525,
  149.     'holly biscuits':           252525252525,
  150.     'snowflake biscuits':           252525252525,
  151.     'snowman biscuits':         252525252525,
  152.     'mistletoe biscuits':           252525252525,
  153.     'candy cane biscuits':          252525252525,
  154.     'bell biscuits':            252525252525,
  155.     'present biscuits':         252525252525,
  156.     'exotic nuts':              320000000000,
  157.     'antigrandmas':             BASE_COSTS[9] * TIER2, // 399999999900
  158.     'string theory':            BASE_COSTS[9] * TIER2, // 399999999900
  159.     'bat cookies':              444444444444,
  160.     'eyeball cookies':          444444444444,
  161.     'ghost cookies':            444444444444,
  162.     'pumpkin cookies':          444444444444,
  163.     'skull cookies':            444444444444,
  164.     'slime cookies':            444444444444,
  165.     'spider cookies':           444444444444,
  166.     'gem polish':               BASE_COSTS[10] * TIER1, // 500000000000
  167.     'communal brainsweep':          640000000000,
  168.     'aging agents':             BASE_COSTS[1] * TIER6, // 800000000000
  169.     'dark chocolate-coated cookies':    999999999999,
  170.     'white chocolate-coated cookies':   999999999999,
  171.     // 13
  172.     'causality enforcer':           1234567890000,
  173.     'arcane sugar':             1280000000000,
  174.     'brane transplant':         BASE_COSTS[7] * TIER5, // 1666666000000
  175.     'elder pact':               2560000000000,
  176.     'sacrificial rolling pins':     2888888888888,
  177.     'season switcher':          3333333333333, // ignored
  178.     'large macaron collider':       BASE_COSTS[9] * TIER3, // 3999999999000
  179.     'pulsar sprinklers':            BASE_COSTS[2] * TIER6, // 4000000000000
  180.     '9th color':                BASE_COSTS[10] * TIER2, // 5000000000000
  181.     'rainbow grandmas':         BASE_COSTS[10] * TIER2, // 5000000000000
  182.     'unobtainium mouse':            5000000000000,
  183.     'kitten engineers':         9000000000000,
  184.     'eclipse cookies':          9999999999999,
  185.     'zebra cookies':            9999999999999,
  186.     // 14
  187.     'deep-bake process':            BASE_COSTS[3] * TIER6, // 24000000000000
  188.     'chocolate light':          BASE_COSTS[10] * TIER3, // 50000000000000
  189.     'quintillion fingers':          50000000000000,
  190.     'elder covenant':           66666666666666,
  191.     'get lucky':                77777777777777,
  192.     'coreforge':                BASE_COSTS[4] * TIER6, // 80000000000000
  193.     'british tea biscuits':         99999999999999,
  194.     'chocolate british tea biscuits':   99999999999999,
  195.     'empire biscuits':          99999999999999,
  196.     'macaroons':                99999999999999,
  197.     'round british tea biscuits':       99999999999999,
  198.     'round british tea biscuits with heart motif':
  199.                         99999999999999,
  200.     'round chocolate british tea biscuits': 99999999999999,
  201.     'round chocolate british tea biscuits with heart motif':
  202.                         99999999999999,
  203.     'snickerdoodles':           99999999999999,
  204.     'stroopwafels':             99999999999999,
  205.     // 15
  206.     'yestermorrow comparators':     BASE_COSTS[8] * TIER5, // 123456789000000
  207.     'big bang bake':            BASE_COSTS[9] * TIER4, // 199999999950000
  208.     'madeleines':               199999999999999,
  209.     'palets':               199999999999999,
  210.     'palmiers':             199999999999999,
  211.     'sables':               199999999999999,
  212.     'generation ship':          BASE_COSTS[5] * TIER6, // 320000000000000
  213.     'eludium mouse':            500000000000000,
  214.     'sextillion fingers':           500000000000000,
  215.     'kitten overseers':         900000000000000,
  216.     'caramoas':             999999999999999,
  217.     'fig gluttons':             999999999999999,
  218.     'grease\'s cups':           999999999999999,
  219.     'jaffa cakes':              999999999999999,
  220.     'loreols':              999999999999999,
  221.     'sagalongs':                999999999999999,
  222.     'shortfoils':               999999999999999,
  223.     'win mints':                999999999999999,
  224.     // 16
  225.     'origin crucible':          BASE_COSTS[6] * TIER6, // 1600000000000000
  226.     'grainbow':             BASE_COSTS[10] * TIER4, // 2500000000000000
  227.     'reverse cyclotrons':           BASE_COSTS[9] * TIER5, // 3999999999000000
  228.     'septillion fingers':           5000000000000000,
  229.     'ardent heart biscuits':        9999999999999999,
  230.     'eternal heart biscuits':       9999999999999999,
  231.     'gingerbread men':          9999999999999999,
  232.     'gingerbread trees':            9999999999999999,
  233.     'golden heart biscuits':        9999999999999999,
  234.     'pure heart biscuits':          9999999999999999,
  235.     'sour heart biscuits':          9999999999999999,
  236.     'weeping heart biscuits':       9999999999999999,
  237.     // 17
  238.     'deity-sized portals':          BASE_COSTS[7] * TIER6, // 13333328000000000
  239.     'octillion fingers':            50000000000000000,
  240.     'wishalloy mouse':          50000000000000000,
  241.     'pure cosmic light':            BASE_COSTS[10] * TIER5, // 50000000000000000
  242.     // 18
  243.     'far future enactment':         BASE_COSTS[8] * TIER6, // 987654312000000000
  244.     'chocolate macarons':           999999999999999999,
  245.     'hazelnut macarons':            999999999999999999,
  246.     'lemon macarons':           999999999999999999,
  247.     'pistachio macarons':           999999999999999999,
  248.     'rose macarons':            999999999999999999,
  249.     'violet macarons':          999999999999999999,
  250.     // 20
  251.     'nanocosmics':              BASE_COSTS[9] * TIER6, // 31999999992000000000
  252.     // 21
  253.     'glow-in-the-dark':         BASE_COSTS[10] * TIER6, // 400000000000000000000
  254.     'kitten managers':          900000000000000000000,
  255. };
  256.  
  257. function compute_rate(base, mult, bonus)
  258. {
  259.     if (!bonus) bonus = 0;
  260.     return base * Math.pow(2, mult) + bonus;
  261. }
  262.  
  263. function make_accessor(key)
  264. {
  265.     return function(val)
  266.     {
  267.         if (arguments.length)
  268.             return this[key] = val;
  269.         return this[key];
  270.     }
  271. }
  272.  
  273. function add_accessor(klass, name)
  274. {
  275.     klass.prototype[name] = make_accessor('_' + name);
  276. }
  277.  
  278. function add_accessors(klass /* , ...*/)
  279. {
  280.     for (var i = 1; i < arguments.length; i++)
  281.         add_accessor(klass, arguments[i]);
  282. }
  283.  
  284. function Game(options)
  285. {
  286.     this.constructor = Game;
  287.  
  288.     var clicks = 0;
  289.     var cookie_total = 0;
  290.     var cookies = 0;
  291.     var golden_cookies = 0;
  292.     var heavenly_chips = 0;
  293.     var milk = 0;
  294.     var santa_level = 0;
  295.  
  296.     if (options) {
  297.         if (options.clicks != null)
  298.             clicks = options.clicks;
  299.         if (options.cookie_total != null)
  300.             cookie_total = options.cookie_total;
  301.         if (options.cookies != null)
  302.             cookies = options.cookies;
  303.         if (options.golden_cookies != null)
  304.             golden_cookies = options.golden_cookies;
  305.         if (options.heavenly_chips != null)
  306.             heavenly_chips = options.heavenly_chips;
  307.         if (options.milk != null)
  308.             milk = options.milk;
  309.         if (options.available_upgrades != null)
  310.             this.available_upgrades(options.available_upgrades);
  311.         if (options.counts != null)
  312.             this.counts(options.counts);
  313.         if (options.upgrades != null)
  314.             this.upgrades(options.upgrades);
  315.         if (options.santa_level != null)
  316.             this.santa_level = options.santa_level;
  317.     }
  318.     if (this._available_upgrades === undefined)
  319.         this._available_upgrades = {};
  320.     if (this._counts === undefined) {
  321.         var counts = this._counts = new Array(BASE_COSTS.length);
  322.         for (var i = 0; i < counts.length; i++)
  323.             counts[i] = 0;
  324.     }
  325.     if (this._upgrades === undefined)
  326.         this._upgrades = {};
  327.  
  328.     this._clicks = clicks;
  329.     this._cookie_total = cookie_total;
  330.     this._cookies = cookies;
  331.     this._golden_cookies = golden_cookies;
  332.     this._heavenly_chips = heavenly_chips;
  333.     this._milk = milk;
  334.     this._santa_level = santa_level;
  335. }
  336. Game.prototype = {};
  337.  
  338. add_accessors(Game, 'clicks', 'cookie_total', 'cookies',
  339.     'golden_cookies', 'heavenly_chips', 'milk', 'santa_level');
  340.  
  341. Game.prototype.available_upgrades = function(available_upgrades)
  342. {
  343.     var dst, returned, src;
  344.     if (arguments.length) {
  345.         src = available_upgrades;
  346.         dst = this._available_upgrades = {};
  347.         returned = src;
  348.     } else {
  349.         src = this._available_upgrades;
  350.         dst = {};
  351.         returned = dst;
  352.     }
  353.     for (var key in src) dst[key] = null;
  354.     return returned;
  355. }
  356. Game.prototype.has_available_upgrade = function(name)
  357. {
  358.     return name in this._available_upgrades;
  359. }
  360. Game.prototype.add_available_upgrade = function(name)
  361. {
  362.     var available = this._available_upgrades;
  363.     //if (name in available)
  364.     //  throw 'upgrade `'+name+'\' already available';
  365.     available[name] = null;
  366.  
  367. }
  368.  
  369. Game.prototype.upgrades = function(upgrades)
  370. {
  371.     var src, dst, returned;
  372.     if (arguments.length) {
  373.         src = upgrades;
  374.         dst = this._upgrades = {};
  375.         returned = src;
  376.     } else {
  377.         src = this._upgrades;
  378.         dst = {};
  379.         returned = dst;
  380.     }
  381.     for (var key in src) dst[key] = null;
  382.     return returned;
  383. }
  384. Game.prototype.has_upgrade = function(name)
  385. {
  386.     return name in this._upgrades;
  387. }
  388.  
  389. Game.prototype.count = function(i, count)
  390. {
  391.     if (arguments.length > 1) {
  392.         this._counts[i] = count;
  393.         return count;
  394.     }
  395.     return this._counts[i];
  396. }
  397. Game.prototype.counts = function(counts)
  398. {
  399.     if (arguments.length) {
  400.         this._counts = counts.slice(0);
  401.         return counts;
  402.     }
  403.     return this._counts.slice(0);
  404. }
  405.  
  406. Game.prototype.costs = function()
  407. {
  408.     var counts = this._counts;
  409.     var upgrades = this._upgrades;
  410.     var result = [];
  411.     var mult = 1;
  412.     if ('season savings' in upgrades) mult *= .99;
  413.     if ('santa\'s dominion' in upgrades) mult *= .99;
  414.     for (var i = 0; i < BASE_COSTS.length; i++)
  415.         result.push(Math.ceil(
  416.             Math.pow(1.15, counts[i]) * BASE_COSTS[i] * mult));
  417.     return result;
  418. }
  419.  
  420. Game.prototype.rates = function()
  421. {
  422.     var self = this;
  423.     var types = ('cursor grandma farm factory mine shipment alchemy_lab ' +
  424.         'portal time_machine antimatter_condenser prism').split(' ');
  425.     return types.map(function (x) {
  426.         return self['rate_' + x]();
  427.     });
  428. }
  429.  
  430. Game.prototype.building_count = function()
  431. {
  432.     var counts = this._counts;
  433.     var sum = 0;
  434.     for (var i = 1; i < counts.length; i++)
  435.         sum += counts[i];
  436.     return sum;
  437. }
  438.  
  439. Game.prototype.building_cost = function(i)
  440. {
  441.     return Math.ceil(Math.pow(1.15, this._counts[i]) * BASE_COSTS[i]);
  442. }
  443.  
  444. Game.prototype.purchase = function(i)
  445. {
  446.     this._counts[i]++;
  447. }
  448. Game.prototype.purchase_undo = function(i)
  449. {
  450.     //if (!this._counts[i])
  451.     //  throw 'building '+i+' count is 0';
  452.     this._counts[i]--;
  453. }
  454.  
  455. Game.prototype.upgrade = function(name)
  456. {
  457.     //if (name in this._upgrades)
  458.     //  throw 'upgrade `'+name+'\' already present';
  459.     //if (!(name in this._available_upgrades))
  460.     //  throw 'upgrade `'+name+'\' not available';
  461.     this._upgrades[name] = null;
  462.     delete this._available_upgrades[name];
  463. }
  464. Game.prototype.upgrade_undo = function(name)
  465. {
  466.     //if (!(name in this._upgrades))
  467.     //  throw 'upgrade `'+name+'\' was not present';
  468.     //if (name in this._available_upgrades)
  469.     //  throw 'upgrade `'+name+'\' is available?';
  470.     delete this._upgrades[name];
  471.     this._available_upgrades[name] = null;
  472. }
  473.  
  474. Game.prototype.total_cps = function()
  475. {
  476.     var cps;
  477.     var heavenly_mult;
  478.     var mult;
  479.     var rates;
  480.     var i;
  481.  
  482.     var counts = this._counts;
  483.     var milk = this._milk;
  484.     var real = this._real;
  485.     var upgrades = this._upgrades;
  486.  
  487.     mult = 1;
  488.     mult += .05 * this._count_upgrades([
  489.         'coconut cookies',
  490.         'macadamia nut cookies',
  491.         'oatmeal raisin cookies',
  492.         'peanut butter cookies',
  493.         'plain cookies',
  494.         'sugar cookies',
  495.         'white chocolate cookies',
  496.     ]);
  497.     mult += .1 * this._count_upgrades([
  498.         'all-chocolate cookies',
  499.         'double-chip cookies',
  500.         'white chocolate macadamia nut cookies',
  501.     ]);
  502.     mult += .15 * this._count_upgrades([
  503.             'british tea biscuits',
  504.             'chocolate british tea biscuits',
  505.         'dark chocolate-coated cookies',
  506.         'eclipse cookies',
  507.             'empire biscuits',
  508.             'macaroons',
  509.         'round british tea biscuits',
  510.             'round british tea biscuits with heart motif',
  511.             'round chocolate british tea biscuits',
  512.             'round chocolate british tea biscuits with heart motif',
  513.             'snickerdoodles',
  514.             'stroopwafels',
  515.         'white chocolate-coated cookies',
  516.         'zebra cookies',
  517.     ]);
  518.     mult += .2 * this._count_upgrades([
  519.         'bat cookies',
  520.         'bell biscuits',
  521.         'christmas tree biscuits',
  522.         'candy cane biscuits',
  523.         'eyeball cookies',
  524.         'ghost cookies',
  525.         'holly biscuits',
  526.             'madeleines',
  527.         'mistletoe biscuits',
  528.             'palets',
  529.             'palmiers',
  530.         'present biscuits',
  531.         'pumpkin cookies',
  532.             'sables',
  533.         'skull cookies',
  534.         'slime cookies',
  535.         'snowflake biscuits',
  536.         'snowman biscuits',
  537.         'spider cookies',
  538.     ]);
  539.     mult += .25 * this._count_upgrades([
  540.         'ardent heart biscuits',
  541.             'caramoas',
  542.         'eternal heart biscuits',
  543.             'fig gluttons',
  544.         'gingerbread men',
  545.         'gingerbread trees',
  546.         'golden heart biscuits',
  547.             'grease\'s cups',
  548.             'jaffa cakes',
  549.             'loreols',
  550.         'pure heart biscuits',
  551.             'sagalongs',
  552.             'shortfoils',
  553.         'sour heart biscuits',
  554.         'weeping heart biscuits',
  555.             'win mints',
  556.     ]);
  557.     mult += .3 * this._count_upgrades([
  558.         'rose macarons',
  559.         'lemon macarons',
  560.         'chocolate macarons',
  561.         'pistachio macarons',
  562.         'hazelnut macarons',
  563.         'violet macarons',
  564.     ]);
  565.  
  566.     if ('a lump of coal' in upgrades)       mult += .01;
  567.     if ('an itchy sweater' in upgrades)     mult += .01;
  568.     if ('specialized chocolate chips' in upgrades)  mult += .01;
  569.     if ('designer cocoa beans' in upgrades)     mult += .02;
  570.     if ('underworld ovens' in upgrades)     mult += .03;
  571.     if ('exotic nuts' in upgrades)          mult += .04;
  572.     if ('arcane sugar' in upgrades)         mult += .05;
  573.     if ('improved jolliness' in upgrades)       mult += .15;
  574.     if ('increased merriness' in upgrades)      mult += .15;
  575.     if ('santa\'s dominion' in upgrades)        mult += .50;
  576.     if ('santa\'s legacy' in upgrades)
  577.         mult += (this._santa_level + 1) * .1;
  578.  
  579.     heavenly_mult = 0;
  580.     if ('heavenly chip secret' in upgrades)  heavenly_mult += .05;
  581.     if ('heavenly cookie stand' in upgrades)  heavenly_mult += .2;
  582.     if ('heavenly bakery' in upgrades)  heavenly_mult += .25;
  583.     if ('heavenly confectionery' in upgrades)  heavenly_mult += .25;
  584.     if ('heavenly key' in upgrades)  heavenly_mult += .25;
  585.     mult += .02 * this._heavenly_chips * heavenly_mult;
  586.  
  587.     cps = 0;
  588.     rates = this.rates();
  589.     for (i = 0; i < counts.length; i++)
  590.         cps += counts[i] * rates[i];
  591.  
  592.     if ('santa\'s milk and cookies' in upgrades) milk *= 1.05;
  593.     if ('kitten helpers' in upgrades)   mult *= 1 + milk * .05;
  594.     if ('kitten workers' in upgrades)   mult *= 1 + milk * .1;
  595.     if ('kitten engineers' in upgrades) mult *= 1 + milk * .2;
  596.     if ('kitten overseers' in upgrades) mult *= 1 + milk * .2;
  597.     if ('kitten managers' in upgrades)  mult *= 1 + milk * .2;
  598.     if ('elder covenant' in upgrades)   mult *= .95;
  599.  
  600.     return cps * mult;
  601. }
  602.  
  603. Game.prototype.rate_mouse = function(cps)
  604. {
  605.     var base = 1;
  606.     var bonus;
  607.     var building_mult;
  608.     var cps_mult;
  609.     var doubles;
  610.  
  611.     var upgrades = this._upgrades;
  612.  
  613.     if ('reinforced index finger' in upgrades) base++;
  614.  
  615.     doubles = 0;
  616.     if ('carpal tunnel prevention cream' in upgrades)   doubles++;
  617.     if ('ambidextrous' in upgrades)             doubles++;
  618.  
  619.     building_mult = 0;
  620.     if ('thousand fingers' in upgrades) building_mult += .1;
  621.     if ('million fingers' in upgrades)  building_mult += .5;
  622.     if ('billion fingers' in upgrades)  building_mult += 2;
  623.     if ('trillion fingers' in upgrades) building_mult += 10;
  624.     if ('quadrillion fingers' in upgrades)  building_mult += 20;
  625.     if ('quintillion fingers' in upgrades)  building_mult += 100;
  626.     if ('sextillion fingers' in upgrades)   building_mult += 200;
  627.  
  628.     bonus = building_mult * this.building_count();
  629.  
  630.     cps_mult = .01 * this._count_upgrades([
  631.         'plastic mouse',
  632.         'iron mouse',
  633.         'titanium mouse',
  634.         'adamantium mouse',
  635.         'unobtainium mouse',
  636.         'eludium mouse',
  637.         'wishalloy mouse',
  638.     ]);
  639.    
  640.     var mult = ('santa\'s helpers' in upgrades) ? 1.1 : 1;
  641.  
  642.     bonus += cps_mult * cps;
  643.     return compute_rate(base, doubles, bonus) * mult;
  644. }
  645.  
  646. Game.prototype.rate_cursor = function()
  647. {
  648.     var base = BASE_RATES[0];
  649.     var bonus;
  650.     var doubles = 0;
  651.     var building_mult = 0;
  652.  
  653.     var upgrades = this._upgrades;
  654.  
  655.     if ('reinforced index finger' in upgrades) base += .1;
  656.  
  657.     if ('carpal tunnel prevention cream' in upgrades)   doubles++;
  658.     if ('ambidextrous' in upgrades)             doubles++;
  659.  
  660.     if ('thousand fingers' in upgrades) building_mult += .1;
  661.     if ('million fingers' in upgrades)  building_mult += .5;
  662.     if ('billion fingers' in upgrades)  building_mult += 2;
  663.     if ('trillion fingers' in upgrades) building_mult += 10;
  664.     if ('quadrillion fingers' in upgrades)  building_mult += 20;
  665.     if ('quintillion fingers' in upgrades)  building_mult += 100;
  666.     if ('sextillion fingers' in upgrades)   building_mult += 200;
  667.     if ('septillion fingers' in upgrades)   building_mult += 400;
  668.     if ('octillion fingers' in upgrades)    building_mult += 800;
  669.  
  670.     bonus = building_mult * this.building_count();
  671.     return compute_rate(base, doubles, bonus);
  672. }
  673.  
  674. Game.prototype.rate_grandma = function()
  675. {
  676.     var base = BASE_RATES[1];
  677.     var doubles = 0;
  678.  
  679.     var counts = this._counts;
  680.     var upgrades = this._upgrades;
  681.  
  682.     if ('forwards from grandma' in upgrades)    base += .3;
  683.     if ('one mind' in upgrades)     base += counts[1] * .02;
  684.     if ('communal brainsweep' in upgrades)  base += counts[1] * .02;
  685.     if ('elder pact' in upgrades)       base += counts[7] * .05;
  686.  
  687.     doubles += this._count_upgrades([
  688.         'steel-plated rolling pins',
  689.         'lubricated dentures',
  690.         'prune juice',
  691.         'double-thick glasses',
  692.         'farmer grandmas',
  693.         'worker grandmas',
  694.         'miner grandmas',
  695.         'cosmic grandmas',
  696.         'transmuted grandmas',
  697.         'altered grandmas',
  698.         'grandmas\' grandmas',
  699.         'antigrandmas',
  700.         'bingo center', 'bingo center', // count twice
  701.         'ritual rolling pins',
  702.         'naughty list',
  703.         'rainbow grandmas',
  704.         'aging agents',
  705.     ]);
  706.  
  707.     return compute_rate(base, doubles);
  708. }
  709.  
  710. Game.prototype.rate_farm = function()
  711. {
  712.     var base = BASE_RATES[2];
  713.     var doubles = 0;
  714.  
  715.     var upgrades = this._upgrades;
  716.  
  717.     if ('cheap hoes' in upgrades) base++;
  718.  
  719.     doubles += this._count_upgrades([
  720.         'fertilizer',
  721.         'cookie trees',
  722.         'genetically-modified cookies',
  723.         'gingerbread scarecrows',
  724.         'pulsar sprinklers',
  725.     ]);
  726.  
  727.     return compute_rate(base, doubles);
  728. }
  729.  
  730. Game.prototype.rate_factory = function()
  731. {
  732.     var base = BASE_RATES[3];
  733.     var doubles = 0;
  734.  
  735.     var upgrades = this._upgrades;
  736.  
  737.     if ('sturdier conveyor belts' in upgrades) base += 4;
  738.  
  739.     doubles += this._count_upgrades([
  740.         'child labor',
  741.         'sweatshop',
  742.         'radium reactors',
  743.         'recombobulators',
  744.         'deep-bake process',
  745.     ]);
  746.  
  747.     return compute_rate(base, doubles);
  748. }
  749.  
  750. Game.prototype.rate_mine = function()
  751. {
  752.     var base = BASE_RATES[4];
  753.     var doubles = 0;
  754.  
  755.     var upgrades = this._upgrades;
  756.  
  757.     if ('sugar gas' in upgrades) base += 10;
  758.  
  759.     doubles += this._count_upgrades([
  760.         'megadrill',
  761.         'ultradrill',
  762.         'ultimadrill',
  763.         'h-bomb mining',
  764.         'coreforge',
  765.     ]);
  766.  
  767.     return compute_rate(base, doubles);
  768. }
  769.  
  770. Game.prototype.rate_shipment = function()
  771. {
  772.     var base = BASE_RATES[5];
  773.     var doubles = 0;
  774.  
  775.     var upgrades = this._upgrades;
  776.  
  777.     if ('vanilla nebulae' in upgrades) base += 30;
  778.  
  779.     doubles += this._count_upgrades([
  780.         'wormholes',
  781.         'frequent flyer',
  782.         'warp drive',
  783.         'chocolate monoliths',
  784.         'generation ship',
  785.     ]);
  786.  
  787.     return compute_rate(base, doubles);
  788. }
  789.  
  790. Game.prototype.rate_alchemy_lab = function()
  791. {
  792.     var base = BASE_RATES[6];
  793.     var doubles = 0;
  794.  
  795.     var upgrades = this._upgrades;
  796.  
  797.     if ('antimony' in upgrades) base += 100;
  798.  
  799.     doubles += this._count_upgrades([
  800.         'essence of dough',
  801.         'true chocolate',
  802.         'ambrosia',
  803.         'aqua crustulae',
  804.         'origin crucible',
  805.     ]);
  806.  
  807.     return compute_rate(base, doubles);
  808. }
  809.  
  810. Game.prototype.rate_portal = function()
  811. {
  812.     var base = BASE_RATES[7];
  813.     var doubles = 0;
  814.  
  815.     var upgrades = this._upgrades;
  816.  
  817.     if ('ancient tablet' in upgrades) base += 1666;
  818.  
  819.     doubles += this._count_upgrades([
  820.         'insane oatling workers',
  821.         'soul bond',
  822.         'sanity dance',
  823.         'brane transplant',
  824.         'deity-sized portals',
  825.     ]);
  826.  
  827.     return compute_rate(base, doubles);
  828. }
  829.  
  830. Game.prototype.rate_time_machine = function()
  831. {
  832.     var base = BASE_RATES[8];
  833.     var doubles = 0;
  834.  
  835.     var upgrades = this._upgrades;
  836.  
  837.     if ('flux capacitors' in upgrades) base += 9876;
  838.  
  839.     doubles += this._count_upgrades([
  840.         'time paradox resolver',
  841.         'quantum conundrum',
  842.         'causality enforcer',
  843.         'yestermorrow comparators',
  844.         'far future enactment',
  845.     ]);
  846.  
  847.     return compute_rate(base, doubles);
  848. }
  849.  
  850. Game.prototype.rate_antimatter_condenser = function()
  851. {
  852.     var base = BASE_RATES[9];
  853.     var doubles = 0;
  854.  
  855.     var upgrades = this._upgrades;
  856.  
  857.     if ('sugar bosons' in upgrades) base += 99999;
  858.  
  859.     doubles += this._count_upgrades([
  860.         'string theory',
  861.         'large macaron collider',
  862.         'big bang bake',
  863.         'reverse cyclotrons',
  864.         'nanocosmics',
  865.     ]);
  866.  
  867.     return compute_rate(base, doubles);
  868. }
  869.  
  870. Game.prototype.rate_prism = function()
  871. {
  872.     var base = BASE_RATES[10];
  873.     var doubles = 0;
  874.  
  875.     var upgrades = this._upgrades;
  876.  
  877.     if ('gem polish' in upgrades) base += 1000000;
  878.  
  879.     doubles += this._count_upgrades([
  880.         '9th color',
  881.         'chocolate light',
  882.         'grainbow',
  883.         'pure cosmic light',
  884.         'glow-in-the-dark',
  885.     ]);
  886.  
  887.     return compute_rate(base, doubles);
  888. }
  889.  
  890. Game.prototype._count_upgrades = function(names)
  891. {
  892.     var sum = 0;
  893.     var upgrades = this._upgrades;
  894.     for (var i = 0; i < names.length; i++)
  895.         if (names[i] in upgrades)
  896.             sum++;
  897.     return sum;
  898. }
  899.  
  900. function time_for_one(cookies, cps, a)
  901. {
  902.     var need_a = a[2] - cookies;
  903.  
  904.     return need_a<0 ? 0 : need_a/cps;
  905. }
  906.  
  907. function time_for_both(cookies, cps, a, b)
  908. {
  909.     var need_a;
  910.     var need_b;
  911.     var time;
  912.  
  913.     // I'm not sure if I should take into account how many cookies are
  914.     // currently being had
  915.     cookies = 0;
  916.  
  917.     need_a = a[2] - cookies;
  918.     if (need_a < 0) {
  919.         cookies = -need_a;
  920.         need_a = 0;
  921.         time = 0;
  922.     } else {
  923.         cookies = 0;
  924.         time = need_a / cps;
  925.     }
  926.  
  927.     need_b = b[2] - cookies;
  928.     if (need_b >= 0)
  929.         time += need_b / a[3];
  930.  
  931.     return time;
  932. }
  933.  
  934. function compare_time(cookies, cps, lhs, rhs)
  935. {
  936.     var time_lhs;
  937.     var time_rhs;
  938.  
  939.     time_lhs = time_for_both(cookies, cps, lhs, rhs);
  940.     time_rhs = time_for_both(cookies, cps, rhs, lhs);
  941.  
  942.     return time_lhs - time_rhs;
  943. }
  944.  
  945. function sorted_suggestions(cookies, cps, suggestions)
  946. {
  947.     function cmp(a, b) {
  948.         return compare_time(cookies, cps, a, b);
  949.     }
  950.  
  951.     var copy = suggestions.slice(0);
  952.     copy.sort(cmp);
  953.     return copy;
  954. }
  955.  
  956. function verify_transitive(cookies, cps, options)
  957. {
  958.     var left, right;
  959.     var i, j;
  960.     var transitive = true;
  961.     for (i = 0; i < options.length - 1; i++) {
  962.         left = options[i];
  963.         for (j = i + 1; j < options.length; j++) {
  964.             right = options[j];
  965.             if (compare_time(cookies, cps, left, right) > 0) {
  966.                 transitive = false;
  967.                 break;
  968.             }
  969.         }
  970.         if (!transitive) break;
  971.     }
  972.     var optimal = true;
  973.     left = options[0];
  974.     for (i = 1; i < options.length; i++) {
  975.         if (compare_time(cookies, cps, left, right) > 0) {
  976.             optimal = false;
  977.             break;
  978.         }
  979.     }
  980.     if (transitive && optimal)
  981.         console.info('transitive', transitive, 'optimal', optimal);
  982.     else
  983.         console.error('transitive', transitive, 'optimal', optimal);
  984. }
  985.  
  986. function sets_equal(lhs, rhs)
  987. {
  988.     var sz_lhs = 0;
  989.     var sz_rhs = 0;
  990.     for (var key in lhs) {
  991.         if (!(key in rhs)) return false;
  992.         sz_lhs++;
  993.     }
  994.     for (var key in rhs)
  995.         sz_rhs++;
  996.     return sz_lhs == sz_rhs;
  997. }
  998.  
  999. function Simulation(options)
  1000. {
  1001.     this.constructor = Simulation;
  1002.  
  1003.     var real = null;
  1004.     var game = null;
  1005.  
  1006.     if (options) {
  1007.         if (options.game != null)
  1008.             game = options.game;
  1009.         if (options.real != null)
  1010.             real = options.real;
  1011.     }
  1012.     if (game == null)
  1013.         game = new Game;
  1014.     if (real == null)
  1015.         real = real_game();
  1016.  
  1017.     this._game = game;
  1018.     this._real = real;
  1019.     this._last_cps = null;
  1020. }
  1021. Simulation.prototype = {};
  1022. Simulation.prototype.game = function()
  1023. {
  1024.     return this._game;
  1025. }
  1026. Simulation.prototype.refresh_from_real = function()
  1027. {
  1028.     var i;
  1029.     var important = false;
  1030.     var key;
  1031.  
  1032.     var game = this._game;
  1033.     var real = this._real;
  1034.  
  1035.     var real_available = {};
  1036.     for (i = 0; i < real.UpgradesInStore.length; i++) {
  1037.         // TODO it wouldn't hurt if this removed
  1038.  
  1039.         var name;
  1040.         var upgrade = real.UpgradesInStore[i];
  1041.         name = upgrade.name.replace(/\/.*/, '').
  1042.             replace('&eacute;', 'e').toLowerCase();
  1043.         real_available[name] = null;
  1044.     }
  1045.     if (!sets_equal(game.available_upgrades(), real_available)) {
  1046.         important = true;
  1047.         game.available_upgrades(real_available);
  1048.     }
  1049.  
  1050.     game.clicks(real.cookieClicks);
  1051.     game.cookie_total(real.cookiesEarned);
  1052.     game.cookies(real.cookies);
  1053.  
  1054.     for (key in real.Objects) {
  1055.         var building = real.Objects[key];
  1056.         var id = building.id;
  1057.         var amt = building.amount;
  1058.         if (game.count(id) != amt) {
  1059.             game.count(id, amt);
  1060.             important = true;
  1061.         }
  1062.     }
  1063.  
  1064.     game.golden_cookies(real.goldenClicks);
  1065.     if (game.heavenly_chips() !=
  1066.         game.heavenly_chips(real.prestige['Heavenly chips']))
  1067.         // not likely :)
  1068.         important = true;
  1069.     if (game.milk() != game.milk(real.AchievementsOwned * .04))
  1070.         important = true;
  1071.     if (game.santa_level() != real.santaLevel) {
  1072.         game.santa_level(real.santaLevel);
  1073.         important = true;
  1074.     }
  1075.  
  1076.     var real_upgrades = {};
  1077.     for (key in real.Upgrades) {
  1078.         var name;
  1079.         var upgrade = real.Upgrades[key];
  1080.         if (upgrade.constructor != real.Upgrade) continue;
  1081.         if (upgrade.bought) {
  1082.             name = upgrade.name.replace(/\/.*/, '').
  1083.                 replace('&eacute;', 'e').toLowerCase();
  1084.             real_upgrades[name] = null;
  1085.         }
  1086.     }
  1087.     if (!sets_equal(game.upgrades(), real_upgrades)) {
  1088.         important = true;
  1089.         game.upgrades(real_upgrades);
  1090.     }
  1091.     return important;
  1092. }
  1093. Simulation.prototype.make_suggestions = function()
  1094. {
  1095.     var cps;
  1096.     var mouse_cps;
  1097.     var options;
  1098.  
  1099.     var game = this._game;
  1100.     var upgrades = game.upgrades();
  1101.     var available = game.available_upgrades();
  1102.  
  1103.     cps = game.total_cps();
  1104.     if (cps != this._last_cps) {
  1105.         console.info('CPS is now', cps * Math.pow(10, -12), 'trillion');
  1106.         this._last_cps = cps;
  1107.     }
  1108.     mouse_cps = game.rate_mouse(cps) * 5;
  1109.     cps += mouse_cps;
  1110.  
  1111.     options = [];
  1112.     for (var i = 0; i < BASE_COSTS.length; i++) {
  1113.         var cost = game.building_cost(i);
  1114.         var new_cps;
  1115.         var new_mouse_cps;
  1116.  
  1117.         game.purchase(i);
  1118.         new_cps = game.total_cps();
  1119.         new_mouse_cps = game.rate_mouse(new_cps) * 5;
  1120.         new_cps += new_mouse_cps;
  1121.         game.purchase_undo(i);
  1122.  
  1123.         options.push(['b', i, cost, new_cps]);
  1124.     }
  1125.     var upgrade_mult = 1;
  1126.     if ('toy workshop' in upgrades) upgrade_mult *= .95;
  1127.     if ('santa\'s dominion' in upgrades) upgrade_mult *= .98;
  1128.     for (var upgrade in available) {
  1129.         var cost = UPGRADE_COST[upgrade];
  1130.         if (cost == null) continue;
  1131.         cost *= upgrade_mult;
  1132.         var new_cps;
  1133.         var new_mouse_cps;
  1134.  
  1135.         game.upgrade(upgrade);
  1136.         new_cps = game.total_cps();
  1137.         new_mouse_cps = game.rate_mouse(new_cps) * 5;
  1138.         new_cps += new_mouse_cps;
  1139.         game.upgrade_undo(upgrade);
  1140.  
  1141.         options.push(['u', upgrade, cost, new_cps]);
  1142.     }
  1143.    
  1144.     if (isNaN(game.total_cps())) {
  1145.         alert('critical wizard failure!');
  1146.     }
  1147.  
  1148.     var choice;
  1149.     var non_heavenly_choice;
  1150.     var clicks = game.clicks();
  1151.     var cookie_total = game.cookie_total();
  1152.     var cookies = game.cookies();
  1153.  
  1154.     options = sorted_suggestions(cookies, cps, options);
  1155.     verify_transitive(cookies, cps, options);
  1156.  
  1157.     for (var i = 0; i < options.length; i++) {
  1158.         if (options[i][0] == 'b')
  1159.             options[i] = { type: 'building', id: options[i][1] };
  1160.         else
  1161.             options[i] = { type: 'upgrade', id: options[i][1] };
  1162.     }
  1163.     return options;
  1164. }
  1165. Simulation.prototype.update_ui = function()
  1166. {
  1167.     var important = this.refresh_from_real();
  1168.     var suggestions;
  1169.     if (important) {
  1170.         this._last_suggestions = suggestions =
  1171.             this.make_suggestions();
  1172.         console.info('new suggestions!',
  1173.             suggestions[0], suggestions[1], suggestions.slice(2));
  1174.     } else {
  1175.         // just refresh the suggestions; sometimes cookie clicker
  1176.         // likes to remove my suggestions, i think
  1177.  
  1178.         suggestions = this._last_suggestions;
  1179.         // this shouldn't happen
  1180.         if (!suggestions) return;
  1181.     }
  1182.  
  1183.     this._clear_suggestions();
  1184.  
  1185.     for (var i = 0; i < 3; i++) {
  1186.         var color;
  1187.         switch (i) {
  1188.         case 0:
  1189.             color = 'rgb(0, 255, 0)';
  1190.             break;
  1191.         case 1:
  1192.             color = 'rgb(255, 127, 0)';
  1193.             break;
  1194.         default:
  1195.             color = 'rgb(255, 0, 0)';
  1196.         }
  1197.  
  1198.         var overlay = document.createElement('span');
  1199.         overlay.className = 'suggestion';
  1200.         overlay.style.display = 'block';
  1201.         overlay.style.height = '25px';
  1202.         overlay.style.width = '40px';
  1203.         overlay.style.backgroundColor = color;
  1204.         overlay.style.position = 'relative';
  1205.         overlay.style.left = '20px';
  1206.         overlay.style.top = '20px';
  1207.         overlay.style.fontSize = '1.5em';
  1208.         overlay.style.fontWeight = 'bold';
  1209.  
  1210.         overlay.appendChild(document.createTextNode('[' + (i+1) + ']'));
  1211.  
  1212.         var node = this._find_node(suggestions[i]);
  1213.         node.appendChild(overlay);
  1214.     }
  1215. }
  1216. Simulation.prototype._find_node = function(suggestion)
  1217. {
  1218.     if (suggestion.type == 'building') {
  1219.         var buildings = document.getElementsByClassName(
  1220.             'product');
  1221.         return buildings[suggestion.id];
  1222.     } else {
  1223.         var upgrades = document.getElementById('upgrades').
  1224.             getElementsByClassName('upgrade');
  1225.         for (var i = 0; i < upgrades.length; i++) {
  1226.             var id;
  1227.             var m;
  1228.             var name;
  1229.             var onclick = upgrades[i].onclick;
  1230.  
  1231.             if (!onclick) continue;
  1232.  
  1233.             m = /UpgradesById\[(\d+)\]/.exec(
  1234.                 onclick.toString());
  1235.             if (!m) continue;
  1236.  
  1237.             id = Number(m[1]);
  1238.             name = this._real.UpgradesById[id].name.
  1239.                 replace(/\/.*/, '').
  1240.                 replace('&eacute;', 'e').
  1241.                 toLowerCase();
  1242.             if (name == suggestion.id)
  1243.                 return upgrades[i];
  1244.         }
  1245.     }
  1246.     return null;
  1247. }
  1248. Simulation.prototype._clear_suggestions = function ()
  1249. {
  1250.     var overlays = document.getElementsByClassName('suggestion');
  1251.     for (var i = overlays.length-1; i >= 0; i--) {
  1252.         var overlay = overlays[i];
  1253.         overlay.parentNode.removeChild(overlay);
  1254.     }
  1255. }
  1256. window.Simulation = Simulation;
  1257.  
  1258. function begin(simulation)
  1259. {
  1260.     simulation.update_ui();
  1261.     setTimeout(function () { begin(simulation) }, 100);
  1262. }
  1263. function wait_and_begin()
  1264. {
  1265.     var real = real_game();
  1266.  
  1267.     if (real && real.cookiesEarned) {
  1268.         simulation = new Simulation({ real: real });
  1269.         setTimeout(function () { begin(simulation) }, 100);
  1270.     } else
  1271.         setTimeout(wait_and_begin, 1000);
  1272. }
  1273.  
  1274. var simulation;
  1275. wait_and_begin();
  1276.  
  1277. var secret = window.secret = {};
  1278. secret.best_wrinklers = function ()
  1279. {
  1280.     var game = real_game();
  1281.     var mult = Math.pow(10, -12);
  1282.     var wrinklers = game.wrinklers.
  1283.         map(function(w,i){ return { sucked: w.sucked * mult, id: i } }).
  1284.         filter(function(w){ return w.sucked > 0 });
  1285.     wrinklers.sort(function(a,b){ return b.sucked - a.sucked });
  1286.     return wrinklers;
  1287. }
  1288.  
  1289. secret.best_wrinklers_str = function ()
  1290. {
  1291.     function fmt(w)
  1292.     {
  1293.         return '[' + w.id + ']=' + w.sucked.toFixed(2);
  1294.     }
  1295.     return this.best_wrinklers().map(fmt).join(', ');
  1296. }
  1297.  
  1298. secret.total_cookies = function ()
  1299. {
  1300.     return this.total_cookies_raw() * Math.pow(10, -15);
  1301. }
  1302.  
  1303. secret.total_cookies_raw = function ()
  1304. {
  1305.     var game = real_game();
  1306.     return this.wrinkler_cookies() + game.cookies;
  1307. }
  1308.  
  1309. secret.wrinkler_cookies = function ()
  1310. {
  1311.     var game = real_game();
  1312.     var sucked = 0;
  1313.     for (var i = 0; i < game.wrinklers.length; i++)
  1314.         sucked += game.wrinklers[i].sucked;
  1315.     return sucked * 1.1;
  1316. }
  1317.  
  1318. secret.should_squish = function ()
  1319. {
  1320.     function rates()
  1321.     {
  1322.         var res = [];
  1323.         for (var i = 0; i < 10; i++)
  1324.             res.push(1 - .05*i + .055*i*i);
  1325.         return res;
  1326.     }
  1327.     function times()
  1328.     {
  1329.         var res = [];
  1330.         for (var i = 1; i <= 10; i++)
  1331.             res.push(10000 / (30 * i));
  1332.         return res;
  1333.     }
  1334.  
  1335.     function cookies_forgone(rate_0, rate_1)
  1336.     {
  1337.         var r = rates();
  1338.         var t = times();
  1339.  
  1340.  
  1341.         var sum_after = 0;
  1342.         var total_time = 0;
  1343.         for (var i = 0; i < 10; i++) {
  1344.             sum_after += r[i] * t[i];
  1345.             total_time += t[i];
  1346.         }
  1347.  
  1348.         var sum_before = 6 * rate_0 * total_time;
  1349.         sum_after *= rate_1;
  1350.  
  1351.         return sum_before - sum_after;
  1352.     }
  1353.  
  1354.     function available(costs, cookies)
  1355.     {
  1356.         var cost = costs[costs.length-1];
  1357.  
  1358.         var bought = 0;
  1359.         while (cookies > cost) {
  1360.             cookies -= cost;
  1361.             bought++;
  1362.         }
  1363.         return bought;
  1364.     }
  1365.  
  1366.     var game = real_game();
  1367.     if (game == null) return false;
  1368.     var simulation = new Simulation({ real: game });
  1369.     simulation.refresh_from_real();
  1370.  
  1371.     // C_l = cookies lost by squishing wrinklers
  1372.     // T_e = time to break even
  1373.     //
  1374.     // T_p = time to earn P_c cookies with all wrinklers
  1375.     // T_p = C_p / (R_0 * 6)
  1376.     //
  1377.     // T_e = time to break even
  1378.     // T_e = (R_1 - R_0) / C_p + T_w
  1379.  
  1380.     // rate before prisms
  1381.     var rate_0 = simulation.game().total_cps();
  1382.  
  1383.     var costs = simulation.game().costs();
  1384.     var total_cookies = this.total_cookies_raw();
  1385.     var prisms = available(costs, total_cookies);
  1386.     if (!prisms)
  1387.         return false;
  1388.     while (prisms--)
  1389.         simulation.game().purchase(costs.length-1);
  1390.  
  1391.     // rate after prisms
  1392.     var rate_1 = simulation.game().total_cps();
  1393.  
  1394.     var squish_cost = cookies_forgone(rate_0, rate_1);
  1395.  
  1396.     var time_recover = Math.sqrt(2 * squish_cost / (rate_1 - rate_0));
  1397.  
  1398.     // how many cookies could i gain right now in that recovery time?
  1399.     var recovery_cookies = 6 * rate_0 * time_recover;
  1400.    
  1401.     return total_cookies > recovery_cookies;
  1402. }
  1403.  
  1404. var should_squish = false;
  1405. setInterval(function () {
  1406.     var should = secret.should_squish();
  1407.     if (should && !should_squish)
  1408.         console.info("SQUISH SQUISH SQUISH");
  1409.     should_squish = should;
  1410. }, 10000);
  1411.  
  1412. function Autoclicker()
  1413. {
  1414.     this._interval = null;
  1415.     this._thread = null;
  1416.     this._game = real_game();
  1417. }
  1418. Autoclicker.prototype = {};
  1419. Autoclicker.prototype.enable = function (interval)
  1420. {
  1421.     if (!interval) return;
  1422.     if (this._thread) this.disable();
  1423.  
  1424.     var self = this;
  1425.     this._interval = interval;
  1426.     this._thread = setInterval(function(){ self._click() }, interval);
  1427. }
  1428. Autoclicker.prototype.disable = function ()
  1429. {
  1430.     if (this._thread) {
  1431.         clearInterval(this._thread);
  1432.         this._thread = null;
  1433.         this._interval = null;
  1434.     }
  1435. }
  1436. Autoclicker.prototype._click = function ()
  1437. {
  1438.     var game = this._game;
  1439.     if (game.seasonPopup.life) {
  1440.         game.seasonPopup.click();
  1441.     } else if (game.goldenCookie.life) {
  1442.         game.goldenCookie.click();
  1443.     } else {
  1444.         game.ClickCookie();
  1445.     }
  1446. }
  1447. secret.autoclicker = new Autoclicker();
  1448.  
  1449. })();
  1450.  
  1451. }
  1452.  
  1453. var script = document.createElement('script');
  1454. script.type = 'text/javascript';
  1455. script.appendChild(document.createTextNode(
  1456.     Secret_cookie_wizard.toString() + '\nSecret_cookie_wizard();\n'));
  1457.  
  1458. document.body.appendChild(script);
Add Comment
Please, Sign In to add comment