Javascript Game of Tron In 226 Bytes 115
Have you upgraded your hardware to play something beefier than 140-byte Tetris?
New submitter alokmenghrajani writes with "a detailed view of how we size-optimized a game of Tron to just 226 bytes." It's also optimized for Chrome, and very fast.
1KB Chess For The Sinclair (Score:5, Informative)
Re:1KB Chess For The Sinclair (Score:5, Informative)
Actually it was only 672 bytes - the 1024 byte memory had to include the screen memory also, much like shared video memory today - could take up to 768 of the 1024 bytes for a full 32x24 screen! (the chess game only used an 11-line screen for the board etc)
And it's even considered by some to be the greatest program ever written. [kuro5hin.org]
Re: (Score:3, Interesting)
And what about the 20 MB browser and all other cram below it? I can do a 3D FPS in 0 lines of code by just inserting a DVD into my PS3! Yay for me!
Re: (Score:1)
Uh, mods, the AC was going for "funny". You might want to think before you moderate. See how well that FPS runs if you take the memory out of the computer.
He does have a good point about the 20 mb browser. A web browser shouldn't take near that much memory. I don't remember the first browser I used, but it came on a single floppy.
Re: (Score:2)
I had that, and it was indeed impressive -- and not just the programming for the game itself. I learned a few tricks studying its code.
Your linked article, though -- the computer was buggy? A hack and a kludge, perhaps, but impressive kludges and hacks. The only flaws I saw in it were the poorly fitting expansion modules (not needed for the chess game) and the membrane keyboard. But fuggy? What was buggy about it?
I wrote a two player battle tanks game for it in a couple hundred bytes of machine code, but it
Re: (Score:2)
Re: (Score:2)
Just tried it, it works fine in Firefox 13...
Re: (Score:2)
It works even on firefox 3.6.x
Re: (Score:2)
Re: (Score:3, Insightful)
Re: (Score:2)
And the "Tron" game I remember had a few other games, to boot.
Cool project, bad naming.
Damn. (Score:1)
Re: (Score:2)
I'm running chrome ( Version 19.0.1068.0 (0) ) and i get this nice fast black square....
Re: (Score:2)
Re: (Score:1)
working fine on 19.0.1074.0
press j k i l
Re: (Score:3)
Re: (Score:1)
Works on Firefox 11 just fine.
Re: (Score:2)
No it's not. It works fine under firefox. I'd write down what version I'm running, but I can't type that fast.
You can also look at the code, there's nothing non-standard in it.
Re:Damn. (Score:5, Informative)
I wouldn't be surprised if you could write the same game in under 226 bytes of Z80 or 6502 assembly, so doing it in a high-level language seems much less impressive.
Re: (Score:1, Interesting)
Under 226? instead of being a critical asshole, that "someone" who sits outside every event and just points, please post your code that does just that. Or, give people a fucking break and realize that pushing boundaries like this is what science, and computer science, is all about. Take off your cynical sunglasses and watch the world become so much more clear. Or not.
Re: (Score:1)
1. Computer science has got zilch to do with computers. It's a field of mathematics.
2. This "tron" program does not push the boundaries of any science.
3. Neither is it some a software engineering feat.
It's a hack with some neatness to it, that's about it.
Re: (Score:2)
Works fine in Safari. That said, if you press a key other than ijkl it does something random. I assumed wasd would work, and was very confused until I read the instructions.
I use Vimperator, you insensitive clod! Even ijkl don't work for me, and my fingers kept trying hjkl anyway!
Re: (Score:1)
Re: (Score:1)
Re: (Score:2)
Re: (Score:2)
Re: (Score:1)
and Opera 11.61 (although it is a little fast).
Version: 11.61
Build: 1250
Platform: Linux
System: x86_64, 3.0.0-16-generic
Re: (Score:2)
Firefox 3.6.x (latest 3.6 version) runs it fine.
Note that code itself suggests that game will not start until you press one of the four control buttons.
Re: (Score:2)
It worked OK in my old Mozilla's SeaMonkey v2.0.14 web browser. ;)
Neat, but (Score:1)
keyup instead of keydown makes the game play like junk. Much more apparently unresponsive.
Re: (Score:2)
portability (Score:1)
Tried it in ie9. It simply doesn't work.
Re:portability (Score:5, Interesting)
It works on chrome and firefox. This isn't a portability issue: normally developers add huge amounts of code to support IE. If it needs tweaking for IE, it would probably be 50% larger.
Re: (Score:2)
Huge as compared to 226 bytes.
Re: (Score:2)
If it needs tweaking for IE, it would probably be 50% larger.
The program uses an HTML5 canvas. So it would need a lot more than "tweaking" to work in IE. It would need a completely different implementation.
But IE 10.0 is supposed to (finally) have canvases.
Re: (Score:1)
Actually, does NOT work in my firefox.
But who cares. It just shows that it is highly and amazingly dependent upon the many megabytes of code that it sits on top of. It needs a javascript engine and a browser. You may as well add a byte code that invokes a game of Tron and claim it only needs 1 byte.
Re: (Score:2)
That's odd. Maybe you should report this to the dev, with your FF version, platform, etc. I played quite a while with FF and it worked fine. The controls are i,j,k,l, and you *may* need to click the black canvas to focus it.
Re: (Score:2)
Why do people love Chrome so much? It's proprietary software and comes from a company with shoddy business ethics.
Because it's lightweight and fast, it doesn't pop up with an upgrade notice every two weeks, it has a good standards-compliant rendering engine, and Mozilla desperately needs the competition.
Re: (Score:2)
Because it's lightweight
In what sense is Chrome lightweight? Of the five major browsers, Chrome is the second biggest memory consumer [tomshardware.com] and it comes bundled with Flash, which I personally don't have a use for.
Re: (Score:2)
And has a half-decent built-in PDF rendered. I classify chrome as about the only useable alternative to Acrobat Reader other than Apple's preview. The various free readers are quite unfinished in many ways, in comparison.
Re: (Score:2)
This is old, but you may want to take a look at Foxit Reader [foxitsoftware.com]
I haven't had to suffer Adobe Reader since I found it!
Re: (Score:2)
It's not bad perhaps, but I've tried very hard to use it a couple years ago, and quickly had to give up. Their whole operation has had a weird smell to it, as well: it seems perpetually borderline between a domain squatter and a real thing.
Re: (Score:2)
Controls? (Score:2)
I'd love to have another 226 bytes explaining the controls. They don't seem to make much sense...
Re: (Score:3, Informative)
IJKL instead of WASD or arrow keys. It saves space because IJKL is actually in alphabetical order, which makes it a neat modulus away from being the four directions.
2 player? (Score:5, Informative)
It's not really a game of Tron without a competing lightcycle. (Without fruit, it's not really a game of Snake either.)
Re:2 player? (Score:4, Interesting)
Re: (Score:2)
The original "Snake" was Centipede [wikipedia.org].
Calling this a game of "Tron" is a stretch (Score:5, Insightful)
Come to think of it, that might make a better movie than that last Tron.
Re: (Score:2)
I'd love to hear an explanation of that logic.
Re: (Score:2)
I don't know if you were aiming for troll, informative or funny. But you had me at contrapositive.
spam gives you points (Score:1)
if you keep spamming i,j,k and l, your score keeps going up.
also, why doesn't it work in firefox??
This again... (Score:5, Funny)
226 byte which I am sure include library calls, only runs on top of the multi megabyte of browser code, may use various other resources as well.
By this standard, I can write Tron in 1 bit.
1
There.
Call it the "Run Tron Bit". It runs on top of a full impletation of Tron.
Re:This again... (Score:4, Interesting)
226 byte which I am sure include library calls, only runs on top of the multi megabyte of browser code, may use various other resources as well.
By this standard, I can write Tron in 1 bit.
1
There.
Call it the "Run Tron Bit". It runs on top of a full impletation of Tron.
Anything that has a display of some sort has library calls to control that display. If you were writing this on an old C-64, it had a comprehensive sprite library that performed collision detection and perfectly synchronized updates, without you doing more than setting a few registers carefully. If you were playing 6502 machine code golf, you could probably write this in half the bytes. Switching to a graphics mode was (IIRC) a single assignment, clearing the screen was a function provided by the BASIC interpreter, and polling for key events was a simple call. Updating the display, naturally, involved writing to a predesignated area of memory. You could even switch back to text mode to print out GAME OVER when you were done.
In this example, the library calls, which are deliberately designed to be fairly verbose in order to promote readability, chew up much of their byte budget with verbose keywords like onkeyup, getContext, fillRect, etc.
Also, since you're dealing with complex libraries that provide lots features, code has to turn off some of those features. In this case, they actually generate javascript errors and ignore them. They then have to go through handling key events, handling movement and such, and all with some very cleverly compressed techniques. For instance, they grab the mod of the keyvalue and use that as an index to an array of values to update the player's direction.
Re: (Score:2)
Anything that has a display of some sort has library calls to control that display
Well, IIRC the Sinclair had a 2k rom. That would have to include the display as well as the BASIC language, keyboard detection, read/write to the cassette, etc. The tanks game I wrote for it I wrote in hand-assembled machine code was only a couple hundred bytes, not counting the display code in ROM. It read the keyboard directly, so both players could hold their keys down at the same time without conflicts. I would imagine tha
Re: (Score:3)
Re: (Score:2)
1
Hey, that's no one bit. That's a UTF-16 character, which means it is (or rather, may be) a full 32 bits! Back to the drawing board, young lad.
Re: (Score:3)
That's the source code before I run it through my self made, super optimized compiler.
Re: (Score:1)
It runs on top of a full impletation of Tron.
Fucking bloat!
This is going to make me sound old but (Score:2)
Even Shorter (Score:3, Interesting)
Re: (Score:2)
Re: (Score:1)
your are right, thanks! I'll update the code & give you credits.
i meant to write you are right. Thanks!
Re: (Score:1)
your are right, thanks! I'll update the code & give you credits.
i meant to write you are right. Thanks!
Seems someone else got there first, as it's been attributed to "skrounge" - oh well :(
Same thing in x86 asm (Score:4, Informative)
In any case, this [pastebin.com] is possibly the right version of the code. Should compile with NASM, and is even playable in Dosbox with arrow keys if you turn the emulation speed as low as it can go.
Re: (Score:2)
56 bytes of assembly language source code? I highly doubt it.
Re: (Score:3)
There's only 56 bytes that the computer has to read from somewhere to have a runnable program. In the case of Javascript, since there's no compiled bytecode, you have to download and run from the source. For assembly language, I think it's fair to measure the binary that results from assembling, since it's pretty much a 1:1 translation at that level.
Under DOS, I believe you could actually key the whole program's machine code in with Alt-Keypad sequences using "copy con: foo.com" as long as your program did
Re: (Score:1)
And how much supporting code? (Score:5, Insightful)
Re: (Score:2)
Re: (Score:2)
Yeah, seriously. In Python it would be just 11 bytes, 'import tron'.
Re: (Score:2)
If you cook a meal, do you say that you and the store clerk and the transport driver and the farmer and the butcher and the miller and the service technician at the electricity company cooked the meal?
Re: (Score:2)
Re: (Score:1)
If you're going that far, then how many more lines of code were required to write the kernel of your operating system?
You've just stuck your head down a rabbit hole, and the rabbit ripped your head off.
Re: (Score:2)
Invalid straw-man exception.
I don't think the byte size is important for "golf" purposes unless you count everything down to the bare metal. If they can do Tron in 226 bytes of x86 machine code, then I'll take note. Otherwise the size is only meaningful from a practical standpoint, e.g. how much more disk space and RAM will be necessary to use this program.
I can put "win.com" in autoexec.bat, but that doesn't mean I've implemented Windows 3.1 in 7 bytes.
Re: (Score:1)
No straw-man here. You're original comment was just all inclusive. All you said was "supporting code [...] necessary to run". So you would have to include all supporting code. If you had excluded OS level instructions, then I wouldn't have had a problem. Because if Tron had been written in Java, you would also have to include all the source for the JVM. Now, a C level program that compiled down to machine code, then cool. But you didn't specify the scope of "supporting code".
Re: (Score:2)
Given the size of that book, I'm pretty sure a Javascript Game of Thrones would need like 226 disk partitions.
Not particularly impressed by these (Score:1)
1) It's not really the game, something that kind of maybe looks sort of like the game
2) doesn't really even have the right functionality
3) is only a small bit of logic
Tron();
Tron in 7 bytes in javascript.
not tron (Score:5, Funny)
I think there's a difference between Tron and Suicidal Etch-A-Sketch
Etch-A-Sketch (Score:5, Funny)
Suicidal Etch-A-Sketch
Please leave Governor Romney out of this.
I set the interval to 50... (Score:3)
You mean "Nibbles" or "Worm"? (Score:2)
Useless to me... (Score:1)
... 226 bytes is cool and all, but is useless to me since it doesn't work on my platform. I would gladly accept it taking, say, even 15,000 bytes if it actually worked. It's not as if I can't afford the RAM.
I've seen this done with 120 characters - one line (Score:1)
"80 Micro" which held a contest, who could write the best one line program.
There was a trick to get more characters (an extra 10 or so) in one line I forget
now the total length but think around 120 characters (bytes) on one line.
This was done in Basic using Peeks and Pokes to keep them short.
Lot's of entries; most being this Java Tron cycle type, be it Tron, skiing downhill
or racing; just something controllable going forwards
Stupid? (Score:1)
Has all of /. gone stupid?
Sure it's a lame name for the "project", and it's barely playable, and doesn't work in all browsers... but is a freaking awesome piece of code and all I read here is childish whining. Go back to facebook.
What happened to /.?