Instantly share code, notes, and snippets.
Created
January 15, 2014 03:15
-
Star
(1)
1
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save graywh/8430144 to your computer and use it in GitHub Desktop.
cookie clicker cps calculation code written in a semi-functional style
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'base64' | |
BUILDINGS = { | |
# name => [price, rate] | |
'cursor' => [15, 0.1], | |
'grandma' => [100, 0.5], | |
'farm' => [500, 4], | |
'factory' => [3000, 10], | |
'mine' => [10000, 40], | |
'shipment' => [40000, 100], | |
'alchemy lab' => [200000, 400], | |
'portal' => [1666666, 6666], | |
'time machine' => [123456789, 98765], | |
'antimatter condenser' => [3999999999, 999999], | |
} | |
def building?(item) | |
BUILDINGS.has_key?(item) | |
end | |
UPGRADES = { | |
# name => [price, { prerequisites }, effect, identity] | |
'Reinforced index finger' => [100, { 'cursor' => 1 }, 2, 1], | |
'Carpal tunnel prevention cream' => [400, { 'cursor' => 1 }, 2, 1], | |
'Ambidextrous' => [10000, { 'cursor' => 10 }, 2, 1], | |
'Thousand fingers' => [500000, { 'cursor' => 20 }, 0.1, 0], | |
'Million fingers' => [50000000, { 'cursor' => 40 }, 0.5, 0], | |
'Billion fingers' => [500000000, { 'cursor' => 80 }, 2, 0], | |
'Trillion fingers' => [5000000000, { 'cursor' => 120 }, 10, 0], | |
'Quadrillion fingers' => [50000000000, { 'cursor' => 160 }, 20, 0], | |
'Quintillion fingers' => [50000000000000, { 'cursor' => 200 }, 100, 0], | |
'Sextillion fingers' => [500000000000000, { 'cursor' => 240 }, 200, 0], | |
'Plastic mouse' => [50000, {}, 1, 0], | |
'Iron mouse' => [5000000, {}, 1, 0], | |
'Titanium mouse' => [500000000, {}, 1, 0], | |
'Adamantium mouse' => [50000000000, {}, 1, 0], | |
'Unobtainium mouse' => [5000000000000, {}, 1, 0], | |
'Forwards from grandma' => [1000, { 'grandma' => 1 }, 0.3, 0], | |
'Steel-plated rolling pins' => [10000, { 'grandma' => 1 }, 2, 1], | |
'Lubricated dentures' => [100000, { 'grandma' => 10 }, 2, 1], | |
'Prune juice' => [5000000, { 'grandma' => 50 }, 2, 1], | |
'Double-thick glasses' => [100000000, { 'grandma' => 100 }, 2, 1], | |
'Farmer grandmas' => [50000, { 'farm' => 15 }, 2, 1], | |
'Worker grandmas' => [300000, { 'factory' => 15 }, 2, 1], | |
'Miner grandmas' => [1000000000, { 'mine' => 15 }, 2, 1], | |
'Cosmic grandmas' => [4000000, { 'shipment' => 15 }, 2, 1], | |
'Transmuted grandmas' => [20000000, { 'alchemy lab' => 15 }, 2, 1], | |
'Altered grandmas' => [166666600, { 'portal' => 15 }, 2, 1], | |
'Grandmas\' grandmas' => [12345678900, { 'time machine' => 15}, 2, 1], | |
'Antigrandmas' => [3999999999900, { 'antimatter condenser' => 15 }, 2, 1], | |
'Cheap hoes' => [5000, { 'farm' => 1 }, 1, 0], | |
'Fertilizer' => [50000, { 'farm' => 1 }, 2, 1], | |
'Cookie trees' => [500000, { 'farm' => 10 }, 2, 1], | |
'Genetically-modified cookies' => [25000000, { 'farm' => 50 }, 2, 1], | |
'Gingerbread scarecrows' => [500000000, { 'farm' => 100 }, 2, 1], | |
'Sturdier conveyor belts' => [30000, { 'factory' => 1 }, 4, 0], | |
'Child labor' => [300000, { 'factory' => 1 }, 2, 1], | |
'Sweatshop' => [3000000, { 'factory' => 10 }, 2, 1], | |
'Radium reactors' => [150000000, { 'factory' => 50 }, 2, 1], | |
'Recombobulators' => [3000000000, { 'factory' => 100 }, 2, 1], | |
'Sugar gas' => [100000, { 'mine' => 1 }, 10, 0], | |
'Megadrill' => [1000000, { 'mine' => 1 }, 2, 1], | |
'Ultradrill' => [10000000, { 'mine' => 10 }, 2, 1], | |
'Ultimadrill' => [500000000, { 'mine' => 50 }, 2, 1], | |
'H-bomb mining' => [10000000000, { 'mine' => 100 }, 2, 1], | |
'Vanilla nebulae' => [400000, { 'shipment' => 1 }, 30, 0], | |
'Wormholes' => [4000000, { 'shipment' => 1 }, 2, 1], | |
'Frequent flyer' => [40000000, { 'shipment' => 10 }, 2, 1], | |
'Warp drive' => [2000000000, { 'shipment' => 50 }, 2, 1], | |
'Chocolate monoliths' => [40000000000, { 'shipment' => 100 }, 2, 1], | |
'Antimony' => [2000000, { 'alchemy lab' => 1 }, 100, 0], | |
'Essence of dough' => [20000000, { 'alchemy lab' => 1 }, 2, 1], | |
'True chocolate' => [200000000, { 'alchemy lab' => 10 }, 2, 1], | |
'Ambrosia' => [10000000000, { 'alchemy lab' => 50 }, 2, 1], | |
'Aqua crustulae' => [200000000000, { 'alchemy lab' => 100 }, 2, 1], | |
'Ancient tablet' => [16666660, { 'portal' => 1 }, 1666, 0], | |
'Insane oatling workers' => [166666600, { 'portal' => 1 }, 2, 1], | |
'Soul bond' => [1666666000, { 'portal' => 10 }, 2, 1], | |
'Sanity dance' => [83333300000, { 'portal' => 50 }, 2, 1], | |
'Brane transplant' => [1666666000000, { 'portal' => 100 }, 2, 1], | |
'Flux capacitors' => [1234567890, { 'time machine' => 1 }, 9876, 0], | |
'Time paradox resolver' => [987653210, { 'time machine' => 1 }, 2, 1], | |
'Quantum conundrum' => [98765456789, { 'time machine' => 10 }, 2, 1], | |
'Causality enforcer' => [1234567890000, { 'time machine' => 50 }, 2, 1], | |
'Yestermorrow comparators' => [123456789000000, { 'time machine' => 100 }, 2, 1], | |
'Sugar bosons' => [39999999990, { 'antimatter condenser' => 1 }, 99999, 0], | |
'String theory' => [399999999900, { 'antimatter condenser' => 1 }, 2, 1], | |
'Large macaron collider' => [3999999999000, { 'antimatter condenser' => 10 }, 2, 1], | |
'Big bang bake' => [199999999950000, { 'antimatter condenser' => 50 }, 2, 1], | |
'Reverse cyclotrons' => [3999999999000000, { 'antimatter condenser' => 100 }, 2, 1], | |
'Oatmeal raisin cookies' => [99999999, {}, 5, 0], | |
'Peanut butter cookies' => [99999999, {}, 5, 0], | |
'Plain cookies' => [99999999, {}, 5, 0], | |
'Sugar cookies' => [99999999, {}, 5, 0], | |
'Coconut cookies' => [999999999, {}, 5, 0], | |
'White chocolate cookies' => [999999999, {}, 5, 0], | |
'Macadamia nut cookies' => [999999999, {}, 5, 0], | |
'Double-chip cookies' => [99999999999, {}, 10, 0], | |
'White chocolate macadamia nut cookies' => [99999999999, {}, 10, 0], | |
'All-chocolate cookies' => [99999999999, {}, 10, 0], | |
'Dark chocolate-coated cookies' => [999999999999, {}, 15, 0], | |
'White chocolate-coated cookies' => [999999999999, {}, 15, 0], | |
'Eclipse cookies' => [9999999999999, {}, 15, 0], | |
'Zebra cookies' => [9999999999999, {}, 15, 0], | |
'Snickerdoodles' => [99999999999999, {}, 15, 0], | |
'Stroopwafels' => [99999999999999, {}, 15, 0], | |
'Macaroons' => [99999999999999, {}, 15, 0], | |
'Empire biscuits' => [99999999999999, { 'Snickerdoodles' => true, 'Stroopwafels' => true, 'Macaroons' => true }, 15, 0], | |
'British tea biscuits' => [99999999999999, { 'Empire biscuits' => true }, 15, 0], | |
'Chocolate british tea biscuits' => [99999999999999, { 'British tea biscuits' => true }, 15, 0], | |
'Round british tea biscuits' => [99999999999999, { 'Chocolate british tea biscuits' => true }, 15, 0], | |
'Round chocolate british tea biscuits' => [99999999999999, { 'Round british tea biscuits' => true }, 15, 0], | |
'Round british tea biscuits with heart motif' => [99999999999999, { 'Round chocolate british tea biscuits' => true }, 15, 0], | |
'Round chocolate british tea biscuits with heart motif' => [99999999999999, { 'Round british tea biscuits with heart motif' => true }, 15, 0], | |
'Madeleines' => [199999999999999, {}, 20, 0], | |
'Palmiers' => [199999999999999, {}, 20, 0], | |
'Palets' => [199999999999999, {}, 20, 0], | |
'Sables' => [199999999999999, {}, 20, 0], | |
'Caramoas' => [999999999999999, { 'heavenly chip' => 1 }, 25, 0], | |
'Sagalongs' => [999999999999999, { 'heavenly chip' => 2 }, 25, 0], | |
'Shortfoils' => [999999999999999, { 'heavenly chip' => 3 }, 25, 0], | |
'Win mints' => [999999999999999, { 'heavenly chip' => 4 }, 25, 0], | |
'Fig gluttons' => [999999999999999, { 'heavenly chip' => 10 }, 25, 0], | |
'Loreols' => [999999999999999, { 'heavenly chip' => 100 }, 25, 0], | |
'Jaffa cakes' => [999999999999999, { 'heavenly chip' => 500 }, 25, 0], | |
'Grease\'s cups' => [999999999999999, { 'heavenly chip' => 2000 }, 25, 0], | |
'Skull cookies' => [444444444444, {}, 20, 0], | |
'Ghost cookies' => [444444444444, {}, 20, 0], | |
'Bat cookies' => [444444444444, {}, 20, 0], | |
'Slime cookies' => [444444444444, {}, 20, 0], | |
'Pumpkin cookies' => [444444444444, {}, 20, 0], | |
'Eyeball cookies' => [444444444444, {}, 20, 0], | |
'Spider cookies' => [444444444444, {}, 20, 0], | |
'Bingo center/Research facility' => [100000000000, { 'Grandmas\' grandmas' => true }, 4, 1], | |
'Specialized chocolate chips' => [10000000000, { 'Bingo center/Research facility' => true }, 1, 0], | |
'Designer cocoa beans' => [20000000000, { 'Specialized chocolate chips' => true }, 2, 0], | |
'Ritual rolling pins' => [40000000000, { 'Designer cocoa beans' => true }, 2, 1], | |
'Underworld ovens' => [80000000000, { 'Ritual rolling pins' => true }, 3, 0], | |
'One mind' => [160000000000, { 'Underworld ovens' => true }, 1, 0], | |
'Exotic nuts' => [320000000000, { 'One mind' => true }, 4, 0], | |
'Communal brainsweep' => [640000000000, { 'Exotic nuts' => true }, 1, 0], | |
'Arcane sugar' => [1280000000000, { 'Communal brainsweep' => true }, 5, 0], | |
'Elder pact' => [2560000000000, { 'Arcane sugar' => true }, 1, 0], | |
'Kitten helpers' => [9000000, { 'milk' => 52 }, 0.05, 0], | |
'Kitten workers' => [9000000000, { 'milk' => 100 }, 0.1, 0], | |
'Kitten engineers' => [9000000000000, { 'milk' => 200 }, 0.2, 0], | |
'Kitten overseers' => [900000000000000, { 'milk' => 300 }, 0.2, 0], | |
'Heavenly chip secret' => [11, { 'heavenly chip' => 1 }, 0.1, 0], | |
'Heavenly cookie stand' => [1111, { 'Heavenly chip secret' => true }, 0.4, 0], | |
'Heavenly bakery' => [111111, { 'Heavenly cookie stand' => true }, 0.5, 0], | |
'Heavenly confectionery' => [11111111, { 'Heavenly bakery' => true }, 0.5, 0], | |
'Heavenly key' => [1111111111, { 'Heavenly confectionery' => true }, 0.5, 0], | |
} | |
def upgrade?(item) | |
UPGRADES.has_key?(item) | |
end | |
def upgrade_unlocked?(game, item) | |
if upgrade?(item) | |
UPGRADES[item][1].all? do |prereq, n| | |
if upgrade?(prereq) | |
upgrade_bought?(game, prereq) | |
else | |
count(game, prereq) >= n | |
end | |
end | |
end | |
end | |
def cost(game, item, n=1) | |
if building?(item) | |
# (0...n).map { |i| (BUILDINGS[item][0] * 1.15 ** (game[item] + i)).round }.inject(&:+) | |
(BUILDINGS[item][0] * ((1.15 ** (count(game, item) + n) - 1) - (1.15 ** count(game, item) - 1)) / 0.15).round | |
#.tap {|x| puts "#{n} #{item} costs #{x}" } | |
elsif upgrade?(item) | |
UPGRADES[item][0] + UPGRADES[item][1].map do |prereq, n| | |
cost(game, prereq, ([0, n - count(game, prereq)].max rescue nil)) || 0 | |
end.inject(&:+) | |
else | |
0 | |
end | |
end | |
def new_game(params = {}) | |
{ | |
'cursor' => 0, | |
'grandma' => 0, | |
'farm' => 0, | |
'factory' => 0, | |
'mine' => 0, | |
'shipment' => 0, | |
'alchemy lab' => 0, | |
'portal' => 0, | |
'time machine' => 0, | |
'antimatter condenser' => 0, | |
'milk' => 0, | |
'heavenly chip' => 0, | |
'upgrades' => [], | |
}.merge(params) | |
end | |
def count(game, item) | |
if building?(item) || item == 'heavenly chip' || item == 'milk' | |
game[item] | |
end | |
end | |
def count_non_cursor_buildings(game) | |
( | |
count(game, 'grandma') + | |
count(game, 'farm') + | |
count(game, 'factory') + | |
count(game, 'mine') + | |
count(game, 'shipment') + | |
count(game, 'alchemy lab') + | |
count(game, 'portal') + | |
count(game, 'time machine') + | |
count(game, 'antimatter condenser') | |
) | |
end | |
def milk(game) | |
game['milk'] | |
end | |
def heavenly_chip(game) | |
game['heavenly chip'] | |
end | |
def upgrade_bought?(game, item) | |
game['upgrades'].include?(item) | |
end | |
def upgrade(game, item) | |
if upgrade?(item) | |
if upgrade_bought?(game, item) | |
UPGRADES[item][2] | |
else | |
UPGRADES[item][3] | |
end | |
end | |
end | |
def buy(game, item, n=1) | |
if building?(item) | |
game.merge({item => game[item] + n}) | |
elsif upgrade?(item) | |
game = UPGRADES[item][1].inject(game) do |g, (prereq, n)| | |
buy(game, prereq, ([0, n - count(game, prereq)].max rescue 0)) | |
end | |
game['upgrades'] = game['upgrades'] | [item] | |
game | |
else | |
game | |
end | |
end | |
def cps(game, frenzy=1) | |
base_cps(game) * multipliers(game) * frenzy | |
end | |
def base_cps(game) | |
cursor_cps(game) + | |
grandma_cps(game) + | |
farm_cps(game) + | |
factory_cps(game) + | |
mine_cps(game) + | |
shipment_cps(game) + | |
alchemy_lab_cps(game) + | |
portal_cps(game) + | |
time_machine_cps(game) + | |
antimatter_condenser_cps(game) | |
end | |
def mouse_cpc(game, click_frenzy=1, frenzy=1) | |
click_frenzy * ( | |
upgrade(game, 'Reinforced index finger') * | |
upgrade(game, 'Carpal tunnel prevention cream') * | |
upgrade(game, 'Ambidextrous') + | |
count_non_cursor_buildings(game) * ( | |
upgrade(game, 'Thousand fingers') + | |
upgrade(game, 'Million fingers') + | |
upgrade(game, 'Billion fingers') + | |
upgrade(game, 'Trillion fingers') + | |
upgrade(game, 'Quadrillion fingers') + | |
upgrade(game, 'Quintillion fingers') + | |
upgrade(game, 'Sextillion fingers') | |
) + | |
cps(game, frenzy) * ( | |
upgrade(game, 'Plastic mouse') + | |
upgrade(game, 'Iron mouse') + | |
upgrade(game, 'Titanium mouse') + | |
upgrade(game, 'Adamantium mouse') + | |
upgrade(game, 'Unobtainium mouse') | |
) / 100.0) | |
end | |
def cursor_cps(game) | |
count(game, 'cursor') * | |
(BUILDINGS['cursor'][1] * | |
upgrade(game, 'Reinforced index finger') * | |
upgrade(game, 'Carpal tunnel prevention cream') * | |
upgrade(game, 'Ambidextrous') + | |
count_non_cursor_buildings(game) * ( | |
upgrade(game, 'Thousand fingers') + | |
upgrade(game, 'Million fingers') + | |
upgrade(game, 'Billion fingers') + | |
upgrade(game, 'Trillion fingers') + | |
upgrade(game, 'Quadrillion fingers') + | |
upgrade(game, 'Quintillion fingers') + | |
upgrade(game, 'Sextillion fingers') | |
)) | |
end | |
def grandma_cps(game) | |
count(game, 'grandma') * | |
(BUILDINGS['grandma'][1] + upgrade(game, 'Forwards from grandma') + | |
(upgrade(game, 'One mind') + upgrade(game, 'Communal brainsweep')) * count(game, 'grandma')/50.0 + | |
upgrade(game, 'Elder pact') * count(game, 'portal')/20.0 | |
) * | |
upgrade(game, 'Steel-plated rolling pins') * | |
upgrade(game, 'Lubricated dentures') * | |
upgrade(game, 'Prune juice') * | |
upgrade(game, 'Double-thick glasses') * | |
upgrade(game, 'Farmer grandmas') * | |
upgrade(game, 'Worker grandmas') * | |
upgrade(game, 'Miner grandmas') * | |
upgrade(game, 'Cosmic grandmas') * | |
upgrade(game, 'Transmuted grandmas') * | |
upgrade(game, 'Altered grandmas') * | |
upgrade(game, 'Grandmas\' grandmas') * | |
upgrade(game, 'Antigrandmas') * | |
upgrade(game, 'Bingo center/Research facility') * | |
upgrade(game, 'Ritual rolling pins') | |
end | |
def farm_cps(game) | |
count(game, 'farm') * | |
(BUILDINGS['farm'][1] + upgrade(game, 'Cheap hoes')) * | |
upgrade(game, 'Fertilizer') * | |
upgrade(game, 'Cookie trees') * | |
upgrade(game, 'Genetically-modified cookies') * | |
upgrade(game, 'Gingerbread scarecrows') | |
end | |
def factory_cps(game) | |
count(game, 'factory') * | |
(BUILDINGS['factory'][1] + upgrade(game, 'Sturdier conveyor belts')) * | |
upgrade(game, 'Child labor') * | |
upgrade(game, 'Sweatshop') * | |
upgrade(game, 'Radium reactors') * | |
upgrade(game, 'Recombobulators') | |
end | |
def mine_cps(game) | |
count(game, 'mine') * | |
(BUILDINGS['mine'][1] + upgrade(game, 'Sugar gas')) * | |
upgrade(game, 'Megadrill') * | |
upgrade(game, 'Ultradrill') * | |
upgrade(game, 'Ultimadrill') * | |
upgrade(game, 'H-bomb mining') | |
end | |
def shipment_cps(game) | |
count(game, 'shipment') * | |
(BUILDINGS['shipment'][1] + upgrade(game, 'Vanilla nebulae')) * | |
upgrade(game, 'Wormholes') * | |
upgrade(game, 'Frequent flyer') * | |
upgrade(game, 'Warp drive') * | |
upgrade(game, 'Chocolate monoliths') | |
end | |
def alchemy_lab_cps(game) | |
count(game, 'alchemy lab') * | |
(BUILDINGS['alchemy lab'][1] + upgrade(game, 'Antimony')) * | |
upgrade(game, 'Essence of dough') * | |
upgrade(game, 'True chocolate') * | |
upgrade(game, 'Ambrosia') * | |
upgrade(game, 'Aqua crustulae') | |
end | |
def portal_cps(game) | |
count(game, 'portal') * | |
(BUILDINGS['portal'][1] + upgrade(game, 'Ancient tablet')) * | |
upgrade(game, 'Insane oatling workers') * | |
upgrade(game, 'Soul bond') * | |
upgrade(game, 'Sanity dance') * | |
upgrade(game, 'Brane transplant') | |
end | |
def time_machine_cps(game) | |
count(game, 'time machine') * | |
(BUILDINGS['time machine'][1] + upgrade(game, 'Flux capacitors')) * | |
upgrade(game, 'Time paradox resolver') * | |
upgrade(game, 'Quantum conundrum') * | |
upgrade(game, 'Causality enforcer') * | |
upgrade(game, 'Yestermorrow comparators') | |
end | |
def antimatter_condenser_cps(game) | |
count(game, 'antimatter condenser') * | |
(BUILDINGS['antimatter condenser'][1] + upgrade(game, 'Sugar bosons')) * | |
upgrade(game, 'String theory') * | |
upgrade(game, 'Large macaron collider') * | |
upgrade(game, 'Big bang bake') * | |
upgrade(game, 'Reverse cyclotrons') | |
end | |
def multipliers(game) | |
milk_multipliers(game) * base_multipliers(game) | |
end | |
def base_multipliers(game) | |
prestige_multipliers(game) + cookie_multipliers(game) + 1 | |
end | |
def prestige_multipliers(game) | |
[ 'Heavenly chip secret', 'Heavenly cookie stand', 'Heavenly bakery', | |
'Heavenly confectionery', 'Heavenly key' ].inject(0) do |m, u| | |
m + upgrade(game, u) * heavenly_chip(game) | |
end / 100.0 | |
end | |
def cookie_multipliers(game) | |
(['Oatmeal raisin cookies', 'Peanut butter cookies', 'Plain cookies', 'Sugar cookies', | |
'Coconut cookies', 'White chocolate cookies', 'Macadamia nut cookies', | |
'Double-chip cookies', 'White chocolate macadamia nut cookies', 'All-chocolate cookies', | |
'Dark chocolate-coated cookies', 'White chocolate-coated cookies', | |
'Eclipse cookies', 'Zebra cookies', 'Snickerdoodles', 'Stroopwafels', 'Macaroons', | |
'Empire biscuits', 'British tea biscuits', 'Chocolate british tea biscuits', | |
'Round british tea biscuits', 'Round chocolate british tea biscuits', | |
'Round british tea biscuits with heart motif', 'Round chocolate british tea biscuits with heart motif', | |
'Madeleines', 'Palmiers', 'Palets', 'Sables', | |
'Skull cookies', 'Ghost cookies', 'Bat cookies', 'Slime cookies', 'Pumpkin cookies', 'Eyeball cookies', 'Spider cookies', | |
'Specialized chocolate chips', 'Designer cocoa beans', 'Underworld ovens', 'Exotic nuts', 'Arcane sugar', | |
].inject(0) do |m, u| | |
m + upgrade(game, u) | |
end + | |
[ 'Caramoas', 'Sagalongs', 'Shortfoils', 'Win mints', 'Fig gluttons', 'Loreols', 'Jaffa cakes', 'Grease\'s cups', | |
].inject(0) do |m, u| | |
m + upgrade(game, u) | |
end) / 100.0 | |
end | |
def milk_multipliers(game) | |
['Kitten helpers','Kitten workers','Kitten engineers','Kitten overseers', | |
].inject(1) do |m, u| | |
m * (1 + upgrade(game, u) * milk(game)/100.0) | |
end | |
end | |
def lucky(game, frenzy=1) | |
cps(game) * 60 * 20 * frenzy | |
end | |
def effiency_score(game, item, current_cps=nil) | |
current_cps ||= cps(game) | |
item_cost = cost(game, item) | |
delta_cps = cps(buy(game, item)) - current_cps | |
(item_cost / current_cps) + (item_cost / delta_cps) | |
end | |
UPGRADE_IDS = [ | |
'Reinforced index finger', 'Carpal tunnel prevention cream', | |
'Ambidextrous', 'Thousand fingers', 'Million fingers', 'Billion fingers', | |
'Trillion fingers', 'Forwards from grandma', 'Steel-plated rolling pins', | |
'Lubricated dentures', 'Cheap hoes', 'Fertilizer', 'Cookie trees', | |
'Sturdier conveyor belts', 'Child labor', 'Sweatshop', 'Sugar gas', | |
'Megadrill', 'Ultradrill', 'Vanilla nebulae', 'Wormholes', 'Frequent flyer', | |
'Antimony', 'Essence of dough', 'True chocolate', 'Ancient tablet', | |
'Insane oatling workers', 'Soul bond', 'Flux capacitors', | |
'Time paradox resolver', 'Quantum conundrum', 'Kitten helpers', | |
'Kitten workers', 'Oatmeal raisin cookies', 'Peanut butter cookies', | |
'Plain cookies', 'Coconut cookies', 'White chocolate cookies', | |
'Macadamia nut cookies', 'Double-chip cookies', 'Sugar cookies', | |
'White chocolate macadamia nut cookies', 'All-chocolate cookies', | |
'Quadrillion fingers', 'Prune juice', 'Genetically-modified cookies', | |
'Radium reactors', 'Ultimadrill', 'Warp drive', 'Ambrosia', 'Sanity dance', | |
'Causality enforcer', 'Lucky day', 'Serendipity', 'Kitten engineers', | |
'Dark chocolate-coated cookies', 'White chocolate-coated cookies', | |
'Farmer grandmas', 'Worker grandmas', 'Miner grandmas', 'Cosmic grandmas', | |
'Transmuted grandmas', 'Altered grandmas', 'Grandmas\' grandmas', | |
'Bingo center/Research facility', 'Specialized chocolate chips', | |
'Designer cocoa beans', 'Ritual rolling pins', 'Underworld ovens', | |
'One mind', 'Exotic nuts', 'Communal brainsweep', 'Arcane sugar', | |
'Elder pact', 'Elder pledge', 'Plastic mouse', 'Iron mouse', | |
'Titanium mouse', 'Adamantium mouse', 'Ultrascience', 'Eclipse cookies', | |
'Zebra cookies', 'Quintillion fingers', 'Gold hoard', 'Elder covenant', | |
'Revoke elder covenant', 'Get lucky', 'Sacrificial rolling pins', | |
'Snickerdoodles', 'Stroopwafels', 'Macaroons', 'Neuromancy', | |
'Empire biscuits', 'British tea biscuits', 'Chocolate british tea biscuits', | |
'Round british tea biscuits', 'Round chocolate british tea biscuits', | |
'Round british tea biscuits with heart motif', | |
'Round chocolate british tea biscuits with heart motif', | |
'Sugar bosons', 'String theory', 'Large macaron collider', 'Big bang bake', | |
'Antigrandmas', 'Madeleines', 'Palmiers', 'Palets', 'Sables', | |
'Kitten overseers', 'Sextillion fingers', 'Double-thick glasses', | |
'Gingerbread scarecrows', 'Recombobulators', 'H-bomb mining', | |
'Chocolate monoliths', 'Aqua crustulae', 'Brane transplant', | |
'Yestermorrow comparators', 'Reverse cyclotrons', 'Unobtainium mouse', | |
'Caramoas', 'Sagalongs', 'Shortfoils', 'Win mints', 'Perfect idling', | |
'Fig gluttons', 'Loreols', 'Jaffa cakes', 'Grease\'s cups', | |
'Heavenly chip secret', 'Heavenly cookie stand', 'Heavenly bakery', | |
'Heavenly confectionery', 'Heavenly key', 'Skull cookies', 'Ghost cookies', | |
'Bat cookies', 'Slime cookies', 'Pumpkin cookies', 'Eyeball cookies', | |
'Spider cookies', 'Persistent memory', 'Wrinkler doormat' | |
] | |
ACHIEVEMENTS = [ # 1=counts toward milk | |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, | |
1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, | |
1, 1, 1, 1, 0, 1, 1, 1, 1 | |
] | |
def load_game(string) | |
string = Base64.decode64(string.chomp('%21END%21').gsub(/%3D/,'=')) | |
parts = string.split('|') | |
version, empty, timestamps, preferences, stats, buildings, upgrades, achievements = parts | |
buildings = Hash[[['cursor', 'grandma', 'farm', 'factory', 'mine', 'shipment', 'alchemy lab', 'portal', 'time machine', 'antimatter condenser'], buildings.split(';').map {|b| b.split(',')[0].to_i }].transpose] | |
upgrades = upgrades.split(';').map{|u| u.to_i.to_s(2)[1...-1].reverse }.join.scan(/../).map.with_index {|u,i| UPGRADE_IDS[i] if u[1] == '1' }.reject(&:nil?) | |
milk = achievements.split(';').map{|a| a.to_i.to_s(2)[1...-1].reverse }.join.scan(/./).map.with_index {|a,i| ACHIEVEMENTS[i] if a == '1' }.reject(&:nil?).inject(&:+) * 4 | |
prestige = prestige(stats.split(';')[8].to_i) | |
new_game(buildings.merge({ 'upgrades' => upgrades, 'milk' => milk, 'heavenly chip' => prestige })) | |
end | |
def prestige(cookies) | |
(((1 + 8 * cookies / 10**12) ** 0.5 - 1) / 2).floor | |
end | |
SHORT_NAMES = ['', '(,k)', '(M)', '(B,G)', '(T)', '(Qa,P)', '(Qi,E)', '(Sex,Z)', '(Sep,Y)', '(Oct)', '(Non)', '(Dec)', '(Undec)', '(Duodec)', '(Tredec)'] | |
def beautify(cookies) | |
n = Math.log(cookies, 10).floor / 3 | |
# a = cookies.round(m) | |
# b = (cookies - a).round(m+3) | |
if n > 1 | |
m = n * -3 | |
"#{cookies.round.to_s.slice(0...m)}.#{cookies.round.to_s.slice(m...(m+3))} x 1000^#{n} #{SHORT_NAMES[n]}" | |
else | |
cookies.to_s.sub(/...(\.|$)/, ',\0') | |
end | |
end | |
# Float.class_eval do | |
# def to_s | |
# if self.abs > 0 | |
# n = Math.log(self.abs, 10).floor / 3 | |
# # a = cookies.round(m) | |
# # b = (cookies - a).round(m+3) | |
# if n > 1 | |
# m = n * -3 | |
# r = self.abs.round.to_s | |
# "#{self < 0 ? '-' : ''}#{r.slice(0...m)}.#{r.slice(m...(m+3))} #{SHORT_NAMES[n]}" | |
# else | |
# cookies.super.sub(/...(\.|$)/, ',\0') | |
# end | |
# else | |
# super | |
# end | |
# end | |
# end | |
# Fixnum.class_eval do | |
# def to_s | |
# self.to_f.to_s | |
# end | |
# end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment