I broke the shark game. Explain how and how/if I can fix it?
March 17, 2019 10:33 AM   Subscribe

So as you know, I've been playing the Shark Game. I recently got "lots" of everything, which is at least a nonillion (10^30). I decided that since I can view the specific amounts in the log, my new goal would be to get a googol of everything (10^100). I left it running with an auto-clicker overnight that would triple my total resources every few seconds. Now the log lists some of my resources as "infinity". However, I can't seem to use those resources to buy anything.

So I was using a modified trick convert everything to clams, then use the clam pearls processing to convert the clams to crystals. You end up with 3 times as much value as you had before when you do this. To get the required science, every 6 cycles, I parked everything in kelp for 30 seconds and converted the sea apples to science.

I left this running overnight. When I woke up I converted everything to residue in the recycler, checked the log and had infinity residue (called junk in the log). I also had infinity science and sea apples.

I thought "Cool! New goal, infinity of everything!" But when I tried to park it all in fish to buy nurse sharks and dolphin biologists I the number of fish didn't go up. And I can click the button to buy nurse sharks or nurse biologists, but the number doesn't go up.

Based on my experimenting, it looks like any item where the price goes up over time I can't buy. However, I can process my infinity into anything with a fixed price. So I can use the recycler and get lots of fish/clams/etc. etc. I can process those things into lots of sharkonium etc. etc. But I can't recycle into machines, or buy producers or machines or anything where the price goes up over time.

Here are two lines from my log:
junk: Object { amount: NaN, totalAmount: Infinity, incomeMultiplier: 1 }
​kelp: Object { amount: NaN, totalAmount: Infinity, incomeMultiplier: 2

What happened?

Can I recover or is this the end of the road for my shark game?
posted by If only I had a penguin... to Computers & Internet (7 answers total) 3 users marked this as a favorite
TBH this is a kind of problem I typically just avoid rather than think about, but programming languages often don't handle large numbers well by default. In my browser, Math.pow(10, 308) returns a definite integer (though probably an unsafe integer for some purposes), but Math.pow(10, 309) basically gives up and calls the result Infinity. Once you have reached Infinity and start doing other operations on it, there are several ways to return NaN (Not a Number), as you can see in the Wikipedia page WCityMike linked. I can't guess which operation tripped up this program, but it's in JavaScript, so maybe you could contact the developer and suggest they use a library like Crunch to do arbitrary precision integer arithmetic throughout the program until it hits fundamental resource limits on your computer. Otherwise, you've probably hit a fundamental limitation in the language.
posted by Wobbuffet at 11:33 AM on March 17, 2019 [1 favorite]

Without looking at the code and hence only making speculations, my short answer is I think you may have hit the limits of the game, and the numbers got too big for the game to handle. In code, "infinity" is not a number you can perform any sort of mathematical functions on (ie you cant deduct the price of something from infinity), so unless the developer has accounted for this edge use case or scenario in all places, you might be out of luck.

Reddit's /r/incremental_games is pretty active, you might want to post there and see if someone more familiar with the game can help you more.
posted by cgg at 12:31 PM on March 17, 2019

My (educated) guess is that this is probably the result of overflow. As Wobbuffet says, 1.79e308 is the largest number supported by JavaScript (but is unsafe), and probably your game ended up multiplying or adding two numbers that exceeded that limit. So, I can likely fix this (for some value of 'fix'), but this is going to require you to cut-n-paste some javascript into your console. Generally this is a bad idea (by which I mean, don't usually let strangers on the internet run arbitrary code on your computer) but maybe you'll make an exception since I've helped you with Shark Game before. I'm going to suggest you EXPORT YOUR GAME (do options -> export then cut and paste the magic string it puts in the text box next to 'export' into a plain text editor like Notepad [windows] or TextEdit [mac] and save that to your hard drive somewhere safe), and then run the following code snippet:
window.traverse = function(x) {
  if (isArray(x)) {
  } else if ((typeof x === 'object') && (x !== null)) {

window.traverseArray = function(arr) {
  arr.forEach(function (x,ind,arr) {
    if (Number.isNaN(x) || x === Number.POSITIVE_INFINITY) {
      arr[ind] = Math.pow(10,300); //set the array value to 10^300

window.traverseObject = function (obj) {
  for (var key in obj) {
    if (obj.hasOwnProperty(key)) {
      if (Number.isNaN(obj[key]) || obj[key] === Number.POSITIVE_INFINITY) {
        obj[key] = Math.pow(10,300); //set the object property to 10^300

window.isArray = function(o) {
  return Object.prototype.toString.call(o) === '[object Array]'

Just cut and paste all of that into your browser's developer console which I introduced you to in that earlier question (and then press enter). This should execute basically instantly.

What this will do is examine every value in your SharkGame object and, if it finds one that is NaN or infinite, will reset it to 10^300. I have no idea how quickly values climb in the game so there is some guesswork in this choice of fix (which is to say, that value may not back off enough if things are growing via multiplication, since it's only tens of millions below the limit). You may have to change those 2 lines I've commented (comments are the double-slash bits that look like plain english) to some other value instead (e.g,. Math.pow(10,200) is 10^200). If you have to run the code more than once (i.e., because you need to adjust the value it uses to be lower), you'll have to re-import your saved state with all the NaNs before doing subsequent runs.
posted by axiom at 3:15 PM on March 17, 2019 [3 favorites]

(I decided a couple of days ago to write an updated/refactored version of the game. I'll post it in projects if/when I finish it.)
posted by bendy at 3:20 PM on March 17, 2019 [6 favorites]

One last note, this code assumes the game grows things in a positive direction. If you find something which should be negative has become positive inappropriately memail me and I'll tweak the code to handle negative values as well.
posted by axiom at 3:20 PM on March 17, 2019 [1 favorite]

Response by poster: Fantastic, Axium! I will try this tonight.

Bendy,... are you the game's programer?
posted by If only I had a penguin... at 5:48 PM on March 17, 2019

I am not the game's programmer but I can see some places where the code (and the UI) can use some updating. The developer has left the code completely open source so anyone can edit it.
posted by bendy at 12:00 AM on March 18, 2019

« Older My Brain Won't Ever Shut Up & It Is Ruining My...   |   The other type of scone Newer »
This thread is closed to new comments.