Show HN: 2048 in 2048 bytes
js1k.com
js1k.com
- 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?
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 : 4Yeah, just played, and it stops after the "GG" alert.
// 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. (Math.random()*2+1)<<1
Math.random()>.25?2:4
But still too much, I only have 2 bytes to spare :)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.
Great job though! loving all these clones.
https://gist.github.com/datatravelandexperiments/9578313
Needs C99 and curses; e.g.
cc -std=c99 2048.c -lcurses
Note: This is pretty awful code, but I'd rather go to sleep than use up the blanks to make it cleaner. Don't write like this.The changed rule that allows spawning blocks at any time makes it easier indeed, but not that much easier, so nice modification.
Was this change intentional, or a side-effect of the simplified code?
We should not be able to make new card appear when no other one can move.
Actually not that easy, but much more fun.
If you have a static solution, please show it.
I won't point out the bugs/differences that've been mentioned. I dug it, either way.
What really hit me, playing this version, is how much relatively small changes in a really simple game can dramatically alter the strategy and difficulty of the experience
Dug it either way though
(Just keep on pressing right to reproduce)
http://johan-nordberg.com/2048/
(or if you're in the future the js1k crew might have updated my submission already, in that case, forget you read this, it was perfect from the start, whoa i need a break, my brain is trying to find ways to write this comment using fewer characters, commas are nice, sleep)
The addition of the block being added no matter the move is an escape round the original (and obviously more verbose, probably why excluded) method of calculating moves remaining.
All in all, decent effort, but it's not 100% true to it's aim
I want to be able to go on! :)
EDIT: I bet this would be a smash hit in Apple Store (at least I checked and couldnt find exact replica). I bet there are few people working on it right now...
I think it is some hisenbug related to that js1k loads all entries by injecting the script in a iframes src attribute.
EDIT: clicking anywhere to focus the iframe makes it stop
Out of 3 times playing, it has some this 3 times.
2 2 4 2
32 16 8 4
64 128 64 16
1024 512 256 128