back

by jader201·12y ago·view on hn ↗
There are a few differences with this version:

- The game allows a new tile to spawn even if you move in a direction in which no tiles move.

- Only 2 tiles spawn. I don't think I've ever seen a 4 tile spawn.

- Once you reach 2048, the game continues.

Does anyone know whether these are intentional, or a side effect of the 2048 byte limitation?

3 comments
> The game allows a new tile to spawn even if you move in a direction in which no tiles move.

Additionally, if you attempt to move in a direction in which no tile move while the board is full, the game ends, even if there is another, valid move that's possible.

> Once you reach 2048, the game continues.

That's a bug, it should pop up a dialog with your score. Rest is intentional.

  newtile = 2 vs. newtile = Math.random() > 0.25 ? 2 : 4
Or:

    // in setup, use everywhere you use Math.random
    r=Math.random
    // generating a new tile
    newtile=(r()*2+1)<<1
That's a 50/50 chance and it's still a few more characters, obviously, but not nearly that many. Not spawning fours makes this a lot easier.
I'm using JSCrush (http://www.iteral.com/jscrush/) so it actually pays to write stuff out repeatedly instead of assigning short variables.

  (Math.random()*2+1)<<1
  Math.random()>.25?2:4
But still too much, I only have 2 bytes to spare :)
Do you have the uncrushed source somewhere?
> That's a bug, it should pop up a dialog with your score. Rest is intentional.

Yeah, just played, and it stops after the "GG" alert.

Yeah, it's a super buggy clone. But at least the fonts are nice.