New js1k demo and missing piece · Aug 15, 14:00

The latest and most likely final version of my js1k game is online. I have also posted it here in case the other site is down.

I did what I could to reduce the size and add more and more(albeit small) features. I tried to find the shortest (but not fastest) algorithms, change the data structure representation, check every byte of javascript syntax and replace all strings that appeared more than twice in the resulting program. Now I’m pretty much out of ideas unless I start cutting features again.
Btw. my favourite parts are the “interlaced” arrays I used. So instead of writing ['#eb2','#b22','#229','#290'] I wrote '#eb2290' and then used substr to get the values. Oh and there is also a reason that # stayed in the front. It simply saved me a +1 when mapping the color values [1,2,3,4] to the visible colors.

As a bonus, I uploaded the script I used to “compile” the demo. It’s ugly but that’s not the point. It’s easier than manual compression and most likely more effective than generic programs.
So here’s a short summary of what it does: The first part simply replaces longer variable names for short ones with hardcoded names.
The second part wraps everything in a string and then replaces the most common substrings (figured out by hand as they can overlap, etc.) and adds replace and eval to put the original strings back in place at runtime and run the program. The pool of letters to the top of the python program is used as replacements. Note that none of these letters must be used in the demo or as replacement in the first part, which is why I rather used “Final [Score]” instead of “Game Over”. ^^ I could have probably saved a few bytes by making the replacements recursive (they’re now done in the same order in python and javascript) allowing me to catch overlapping strings but that would have required more intelligence on the python side to give hints when something goes wrong because wrong it did go. ;) The numbers in the comments are estimates how much bytes I saved with every replacement.
The third part takes it a step further and wraps everything in another string to replace the replace functions and thus make their use less expensive.

That’s it. Play the game, it’s fun. :)

Update: I added recursive replacements which was enough to add a persistent highscore.

— arne

---

Kommentare

Textile-Hilfe