Simulate Clicker (Cookie Clicker Project)

After finishing IIPP over at Coursera I was excited to start POC.  I found most of the stuff in IIPP fairly easy but I was shocked at how difficult the first project “Cookie Clicker” was.  For those of you thinking that this one is too difficult don’t worry the projects get easier as you progress.  This is a very difficult first project but it’ll get you going in the right direction for the others.

I’m going to go over what I thought was the most difficult part of this project with out completely giving it away.  Phase one is pretty basic stuff.  The really difficult one for me was phase two.  The difficult part about this one is deciphering what you need to do from the instructions provided.  Honestly the forums are nice but some times you have to read way to many useless comments to find something helpful, people trying to be cryptic to follow the honor code.

Psudo Code for a simple implementation:

  • Create a clone of the build info
  • Create a new ClickerState() object
  • Create a loop which will end when you PASS the duration (so when it’s greater than)
  • Each loop call the strategy() (make sure you send it the clone and the current time left)
  • Check for the None purchase and break the loop (it’s tempting but unnecessary to add a wait() here)
  • Determine your time_to_wait, this need be only be one line.  ( something along the lines of time_until(get_cost(next_purchase))
  • Now if that time plus the current time is PAST the duration you should “end the simulation” or break again
  • Wait for that time
  • Buy the item
  • Update the item
  • Also don’t forget to wait for the remaining time once your loop is complete.  (keeping this last wait outside the loop makes it easier to write)
  • Lastly return your game state

Some things that will help you along that I wish I would have done or thought of.

  • Use a while loop with break statements. (if or else blah then wait() is a bad idea)
  • Avoid putting in more than one wait() command inside the loop.  It will only result in you needing to write more code.
  • Just because they say “Also, if you have enough cookies, it is possible to purchase multiple items at the same time step.” It does not mean you should write a second loop.
    • If you study the simplicity of the psudo code above you’ll realize that if you save your wait, buy and update till the end then the next step in the loop (which will get the new result from your strategy) very well could purchase something without increasing your time at all.  Your time_until() function has the potential to return 0.  So a “time step” is not the same as a loop iteration in this instance.
  • They hide the description for the build_info class in the project description on a tiny little link check it out here:

I wish I could have understood this stuff the first time through, I spent over 12 hours on this project most of it pounding my head against the wall about this function.  Don’t get discouraged by the people posting on the forums that they got it done in x lines of code.  If people want to brag let them the important thing here is that you understand why and how this function actually works.

Hopefully this will help you along.  I’ll go over some stuff for phase 3 in my next post.

Tell me what you REALLY think...

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>