Skip to content

Instantly share code, notes, and snippets.

@relsqui
Last active December 23, 2015 23:29
Show Gist options
  • Save relsqui/6710411 to your computer and use it in GitHub Desktop.
Save relsqui/6710411 to your computer and use it in GitHub Desktop.
A cookie accountancy script for Cookie Clicker.
"""
C:\home\relsqui> ./cookiecountant.py --help
usage: cookiecountant.py [-h] [-q N] [-c N] [-b N] price
Tool for planning Cookie Clicker expenditures. Supply the current price of a
building you're interested in, and cookiecountant will give you the total cost
to build more of them. (You can specify cookie quantities/rates in millions,
billions, etc. if you like--as long as the input is consistent, the output
will match its magnitude.)
positional arguments:
price current price of the building you want
optional arguments:
-h, --help show this help message and exit
-q N, --quantity N how many buildings you want
-c N, --cps N your current cookies per second
-b N, --budget N how many cookies you have to spend
C:\home\relsqui> ./cookiecountant.py 127.255 --cps 11.205 --quantity 50 --budget 46400
You can buy 28 buildings now, for 41,626 cookies.
The next 22 buildings will cost 876,865 cookies (21.7 hours).
"""
#!/usr/bin/python
from sys import argv
import argparse
def next_n(price, n):
sum = 0
for i in xrange(n):
sum += price
price = price*1.15
return (sum, price)
def time_string(seconds):
if seconds > 3600*24:
return "{:.1f} days".format(seconds/3600/24)
if seconds > 3600:
return "{:.1f} hours".format(seconds/3600)
if seconds > 60:
return "{:.1f} minutes".format(seconds/60)
return "{:.0f} seconds".format(seconds)
parser = argparse.ArgumentParser(description="""
Tool for planning Cookie Clicker expenditures. Supply the current price of a
building you're interested in, and cookiecountant will give you the total cost
to build more of them. (You can specify cookie quantities/rates in millions,
billions, etc. if you like--as long as the input is consistent, the output
will match its magnitude.)
""")
parser.add_argument("price", type=float,
help="current price of the building you want")
parser.add_argument("-q", "--quantity", type=int, default=0, metavar="N",
help="how many buildings you want")
parser.add_argument("-c", "--cps", type=float, default=0, metavar="N",
help="your current cookies per second")
parser.add_argument("-b", "--budget", type=float, default=0, metavar="N",
help="how many cookies you have to spend")
args = parser.parse_args()
total_price = 0
number_bought = 0
next_price = args.price
cps_string = ""
if args.budget:
while (total_price + next_price < args.budget and
number_bought < args.quantity):
total_price += next_price
next_price *= 1.15
number_bought += 1
print("You can buy {} buildings now, for {:,.0f} "
"cookies.".format(number_bought, total_price))
if args.quantity:
args.quantity -= number_bought
if args.quantity > 0:
total_price, next_price = next_n(next_price, args.quantity)
if args.cps:
cps_string = " ({})".format(time_string(total_price/args.cps))
print("The next {} buildings will cost {:,.0f} "
"cookies{}.".format(args.quantity, total_price, cps_string))
elif not args.budget:
for x in (5, 10, 15, 20, 25):
next_total, next_price = next_n(next_price, 5)
total_price += next_total
if args.cps:
cps_string = (" ({})".format(time_string(total_price/args.cps)))
print("The next {: >2} buildings will cost {:,.0f} "
"cookies{}.".format(x, total_price, cps_string))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment