My snake game is now 54 bytes
Posted by Perfect-Highlight964@reddit | programming | View on Reddit | 172 comments
The game is now only 1 byte away from fitting in a version 3 QR Code.
The new version has the side effect of making the left wall do a "kaleidoscope" effect every time you lose.
The main change was storing the offset to the head position from end of the screen instead of from start, but also abusing the PSP in a complementary way.
I think this PR is pretty easy to understand as there are only 6 pretty independent major changes, switching BX and SI, the two mentioned earlier, position reset method, new head position calculation, different snake character setting, all the changes are needed together to reduce the size but you can understand them one by one.
Silly-Advertising826@reddit
Omg the cutest
-vemla@reddit
This is awesome, ambitious thing to do!
Perfect-Highlight964@reddit (OP)
Thanks
nascentt@reddit
Every time I think you've perfected this, you take it even further.
DiligentRooster8103@reddit
Next stop, 53 bytes and a Nobel prize in golfology.
karuna_murti@reddit
we want 50 bytes
PeopleNose@reddit
"Make it bits"
Fancy-Snow7@reddit
Who has that kind of space available?
preludeoflight@reddit
Nice thing at 50 bytes is you can probably just yell the ones and zeroes at someone to xmit it.
Mognakor@reddit
Watch this person recite the entire snake bytecode from memory.
F0lks_@reddit
Probably NASA
Perfect-Highlight964@reddit (OP)
Thanks 😊
Park_Mujinn@reddit
The kaleidoscope effect is basically a feature now. Ship it and call it "enhanced visual feedback."
Enough_Court_6212@reddit
waos
omerakbarkhan@reddit
Very nice 👍
Financial_Skirt7851@reddit
i waiting for mario......
Able-Football-7846@reddit
Hey buddies what's with the 3 qr code what do you mean by fitting your game in that? Can anyone explain the concept behind it?
Perfect-Highlight964@reddit (OP)
QR Codes are divided into "types" the smaller the QR it could obviously hold less information, they come in "sizes" 1-40. Version 2 can only hold 32 bytes and version 1, 17 bytes.
Able-Football-7846@reddit
Thankyou.
alexbruf@reddit
Small enough to actually run on a mechanical computer
Maleficent-Season713@reddit
what coding language?
Perfect-Highlight964@reddit (OP)
x86 assembly
Maleficent-Season713@reddit
nice man!
Perfect-Highlight964@reddit (OP)
Thanks
PoisnFang@reddit
Bro I turned reddit off for over a year, and I pop back on and this is one of the first things I see. How can you still possibly be working on this???? I have seen your posts for the past like 8 years or something. I cant imagine what level of OCD you have to deal with...
Perfect-Highlight964@reddit (OP)
Lol, I actually dropped it off for a year and suddenly remembered it, so I thought I could maybe reduce some more bytes with a "fresh look".
ZirePhiinix@reddit
Are you using the QR code version that has less redundancy? I think you can fit more payload. It's been a while, but most people didn't even know about being able to reduce redundancy.
Perfect-Highlight964@reddit (OP)
It won't matter version 3 is at maximum 53-bytes
IssaMeTiki2@reddit
Yeah, but if he can optimize further, there might be a way to squeeze in an extra byte. Sometimes, a fresh look at the code can reveal unexpected tricks.
ItsEntDev@reddit
clanker
surj08@reddit
Hard R
slakmehl@reddit
Appreciate lack of micro-transactions
Minimalist aesthetic clean, but a little self-indulgent
Single-player campaign narrative felt a little phoned in
6.3/10
surj08@reddit
Does it require an Internet connection to play single player? Cause like... I need that to survive now
Jybun@reddit
Oh please tell me that last joke was a reference to this game being on old phones lol. That's super clever!
mrt54321@reddit
Lol. Time for vibe coding? It never fails
Eric_Prozzy@reddit
Yup, never fails to make everything 100x worse
ashvy@reddit
"My snake game is now 54 Terabytes :)"
le_birb@reddit
Too much water
mohamed_am83@reddit
Respect! And ... why!?!
Perfect-Highlight964@reddit (OP)
Because it's there
spartan22891@reddit
Nice, Star Trek reference?
Perfect-Highlight964@reddit (OP)
Not that I know of
mohamed_am83@reddit
Convincing :)
mjd5139@reddit
We do what we must because we can.
progfrog@reddit
For the good of all of us?
iceman012@reddit
Except the ones who ate their own tail.
Pilchard123@reddit
But there's no sense crying over every mis-snake
somebodddy@reddit
You just keep on trying 'till you run out of cake
kiswa@reddit
Except the ones who are dead.
light-triad@reddit
We choose to go to the moon in this decade and do the other things, not because they are easy, but because they are hard.
irobeth@reddit
Same reason people work on upping their bench-press, sorta?
It's an iterative discipline, the problem constraints are clear, so is the challenge, and it has an obvious figure-of-merit. Almost immediately you exhaust all low-hanging fruit, and the exercise becomes a 'combat' against the physical constraints of the medium.
As you constantly learn more about software, you get to frame this problem as "maybe I can I use the new knowledge I gained", and you start to gain intimate knowledge about this problem space which can further export into your 'real career', especially if you're planning to go into embedded spaces or systems programming
Also at the end of it, you get to flex on people like "heh, yeah, I'm at 54 bytes right now" and the look on their faces while they think something like "shit, my legal fucking name is that long" becomes its own reward
Nervous_Ad7874@reddit
Wrote a python app at work that just squeezes in at 500mb.
cedarSeagull@reddit
I'm sorry if this is a stupid question, but what's the reason for trying to fit it into a QR code? I assume something will happen when i snap a picture of the QR code, but maybe I'm wrong?
Perfect-Highlight964@reddit (OP)
Because of MattKC's video where he tried to do the same
squigs@reddit
Is there a graph of size against time? I'm wondering how long it will be until this is a single byte, and which byte it will be.
ILikeCutePuppies@reddit
It will be '~' byte.
No-Variation6178@reddit
That would be fascinating! I imagine the curve flattens quickly when you get into double digits – each byte saved now probably requires a totally new approach. Going from 100 bytes to 50 is one thing, but squeezing out that last handful may take ages. I'm rooting for the one-byte milestone though – even if it's just for the fun of the challenge.
devraj7@reddit
And then you can just gzip it down to zero bytes.
sheep1e@reddit
Lossy compression ftw
ketralnis@reddit
Try all 256 of them and find out. Easy peasy
sheep1e@reddit
Sounds hard. I have a better idea. This game is 432 bits. If it can be shrunk down to one bit, it means there are only two values we need to try. And in fact both of those values work. One is a straight snake, zero is a snake eating its own tail.
Perfect-Highlight964@reddit (OP)
I've never made such a graph but it would be interesting to see
KierenBoal@reddit
I've graphed it in a comment above - threw together some C# code that would pull all commits on snake.asm, then uses nasm to compile it, then grabs the file size of the *.bin output file.
Comment link: https://www.reddit.com/r/programming/comments/1odhklb/comment/nkvsuwp/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button
Salty_Employee_8944@reddit
Might have to do a logarithmic y axis as few bytes changes are not invisible
Vennom@reddit
Please! Would love to see that on the github
Perfect-Highlight964@reddit (OP)
I'm going to be a bit busy in the next couple of days, but might add it afterwards
KierenBoal@reddit
I quickly threw together some code to graph the byte size over time. The code downloads all the past 122 commits, compiles them as assembly, and logs the file size. Code was thrown together quickly so take it with a grain of salt, of course.
Imgur link: https://imgur.com/S1UZvZ5
Pastebin of data: https://pastebin.com/1n4JAwte
muntoo@reddit
Roughly matches my hacked together 5 liner:
havok_@reddit
“My snake game size grapher is now under 5 lines”
ZorbaTHut@reddit
Just call the SNEK opcode, I dunno why OP hasn't done this yet
One_Economist_3761@reddit
That’s a RISCy move.
ShinyHappyREM@reddit
^^*CISCy
festusssss@reddit
0x45
Diche_Bach@reddit
Singularity software . . .
West_Till_2493@reddit
My guess is a snake byte
FizixMan@reddit
Babe, wake up! A new SummoningSalt video just dropped!
s0ulbrother@reddit
Do you tell the people in your life about this and what do they think? Like I try to tell my wife about work at times and she gets incredibly bored
Perfect-Highlight964@reddit (OP)
I don't tell anyone (almost) actually, not because I hide it but it just never came up, my girlfriend knows about it and is a little interested but she won't go as far as reading the code or something.
s0ulbrother@reddit
I just explained or tried to explain to my wife why this is a pretty awesome project. She did not care or see the point. Sorry lol
moratnz@reddit
"Honey, honey - my snake is really really small"
"I know..."
s0ulbrother@reddit
This man must have a giant snake with how willing he is to make the smaller one possible
phyphor@reddit
I guess it would be bad to raise a bug, right?
(Before you eat a pellet you can reverse direction without dying.)
soguesswhat@reddit
This is absolutely devastating news
EquationTAKEN@reddit
But does it qualify? At the start of the game, you're allowed to turn 180 degrees with one button-press.
Fingerbob73@reddit
Sorry, I know it's pedantic. In your ReadMe comment on bytes, you've misspelt "sentence".
Perfect-Highlight964@reddit (OP)
Damn, didn't notice, thanks!
(If I wasn't pedantic as well this project wouldn't go anywhere passed 130 bytes)
ApokatastasisPanton@reddit
In the readme you say:
I don't see the difference with a snake game. Can you explain?
Perfect-Highlight964@reddit (OP)
In nibbles there's no food mechanism and in most versions no walls, so you could go right through the bottom/top and the snake just continues to grow one pixel each frame
iceman012@reddit
What causes the left wall to do the kaleidoscope effect?
Perfect-Highlight964@reddit (OP)
It's complicated to explain, you'd better read the code if you're interested
iceman012@reddit
You have high expectations for my abilities to read assembly!
I'll see what I can learn.
Perfect-Highlight964@reddit (OP)
Awesome
IncognitoErgoCvm@reddit
I was messing around on the online demo; just curious about some things I saw.
Before eating the first piece, the snake is capable of reversing itself in-place.
You can use the gap left in the trail by eating food as a crossing point
If I press an un-mapped key, like
r, the snake will start moving diagonally and lose the game, but its diagonal path continues in the next games as well.To what extent are these necessary for your minimization?
Perfect-Highlight964@reddit (OP)
Shit, answered yesterday but it bugged or something, 1. the collision detection is based on the former tile not turns so it's problematic to reduce, could elongate the snake to solve possibly 2. could actually use a different value for the ADC instead of
dh(0x22,0x23,0x24,0x26,0x28,0x2a,0x2b,0x2c,0x2e,0x2f,0x30,0x32,0x33,0x34,0x36,0x38,0x3a,0x3b,0x3c,0x3e) or even switch to SBB (with either 0xc3,0xc4,0xcb,0xcc,0xcf,0xd0,0xd3,0xd4,0xdb,0xdc) or even use a different opcode instead ofor al, 0x29to formmov [si], dlwhich would give many more values to put there, which means I would be able to adjust the entire main loop to solve it but those are a bunch of options to go through and I don't have the time, might do it sometime 3. yes, this is the result of handling input with arithmetic and not branching, I expect users to only input valid keyskauefr@reddit
You'll eventually reach a point where its easier to brute force every length N program and check if it's a valid snake game.
Perfect-Highlight964@reddit (OP)
2^53 options for a 53-bytes variation is so huge, so I don't think it's feasible.
And even if I were to get to let's say 20 bytes and the next iteration would only have to go over 2^20 or even 2^15 options it'd take decades to check them all, because it's not enough to run the game and look at it for a while, you have to check all kinds of edge cases.
somebodddy@reddit
Yes, but you only need to check edge cases to the programs who passed the initial screening.
Perfect-Highlight964@reddit (OP)
True
CanIDevIt@reddit
More - 2^((8+53)) right?
Perfect-Highlight964@reddit (OP)
(2^8)^53 actually, missed that 😅
superxpro12@reddit
So you're sayin there's a chance
irobeth@reddit
I feel like if you get to the point that you succeed at doing this, you can claim your nobel prize in computing for offering a proof of the halting problem
Perfect-Highlight964@reddit (OP)
I can't agree, because being able to determine halting in some programs (in this case the set of programs under 53-bytes) is not equivalent to being able to do so for all of them
irobeth@reddit
yeah i guess that's fair, but it's still impressive if you manage to formally verify 2^15 different automatically generated potential assemblies; i feel like that's gotta be laying the groundwork somehow
cgaWolf@reddit
I know it's not feasable yet, but the idea is hilarious. 1000 monkeys & shakespeare ^•^
woodnoob76@reddit
Some old meme pics or vids resurface on Reddit every year, eventually boring. And here is you, mad lad as you are, resurfacing now and then but with new increments. Redefining perfection again and again by proving that something can still be removed without compromising the whole
florinandrei@reddit
If normal patterns still apply, then some corporate giant will implement Snake in a single CPU instruction, stealing your idea and rendering your project irrelevant.
And then their own software division will screw it up in the compiler, which will generate a 27 GB installer that will require a cloud account and a monthly subscription.
Just kidding, but you know what I mean.
__konrad@reddit
My paint app is 51 bytes long:
uBMAzRC4AQDNM7gDAM0zgPsCdBSA+wF18aAyAUpJ0em0DLcAzRDr4rgDAM0QuABMzSEP(base64)michaelpaoli@reddit
Ah, fun challenges, ... I implemented Tic-Tac-Toe in sed.
meong-oren@reddit
what kind of black magic is this
Hidden_driver@reddit
We are still waiting for the DLSS3 support
BlueGoliath@reddit
Imagine Snake being made using UE5.
Akaino@reddit
Imagine snakes with Dune worms
BigBossLittleFiddle@reddit
Metal Gear Solid Delta entered the chat
Bitmugger@reddit
I love you can drive through the 'hole' in your snake when you eat food and your snake is getting long. Adds a new element of game play
TurboGranny@reddit
I'm looking forward to the day where you figure out how to do it with 1 byte. I believe in you.
I believe you'll get on a CPU design team and sneak this snake game in as part of the processor instruction set and the single byte is the register that launches it. And if course you will have done this just to prove you could.
ashvy@reddit
Then Christopher Domas gon do a keynote talk on this hidden x86 instruction set
darksapra@reddit
So what is game and what is not? For example is the logic to handle input in mobile/pc part of the 54 bytes?
Perfect-Highlight964@reddit (OP)
The logic is to handle input from PC only, the web version converts mobile input to PC input to allow playing from mobile
darksapra@reddit
I see, that's great!
BlueGoliath@reddit
Insane dedication.
Perfect-Highlight964@reddit (OP)
Maybe I'm a bit too obsessive
user_8804@reddit
Which parts of your life are you neglecting for this?
MPGaming9000@reddit
I was thinking the same thing lol. I know I've sure given up many nights and weekends for the sake of coding projects. Looking back on it I'm not sure it was really worth it. lol not like the code was going anywhere. I could have taken more time with it in hindsight.
dont_know_yt@reddit
Everything else
Princess_Azula_@reddit
And people like you are why we have nice things as a society c:
BlueGoliath@reddit
Grass man, grass! There are snakes outside too!
Don't recommend playing games with them though.
pjmlp@reddit
Great achievement, it reminds me of demoscene challenges. :)
TheoreticalDumbass@reddit
This must not produce an ELF executable right? IIRC you'd need 120 bytes on just the headers
No_Source_859@reddit
That’s super impressive! I love how you managed to compress the game down to just 54 bytes—it's like a mini marvel of coding. Have you tried adding any power-ups or features without blowing up the size? Would be cool to see how far you can push it!
WatchOutIGotYou@reddit
You're genuinely incredible
leros@reddit
I love this. This reminds me of a project I had to do in intro to embedded engineering. We had to program a micro controller in assembly to output sound waves through a self made DAC. I went a step beyond and wrote code for a mini music player that pulled WAV files off an SD card. It had pause, play and next track functions all in 110 bytes of assembly. I optimized it under 100 just for fun.
fluidtoons@reddit
That sounds so fun! Do you still do any embedded stuff?
leros@reddit
Not seriously. I'll use an Arduino or ESP32 to solve a problem but electronics is not specifically a hobby anymore.
VictoryMotel@reddit
Not cool to make a post like this assuming everyone knows what you're talking about and without linking the actual base project page. Is this asm or javascript?
NotUniqueOrSpecial@reddit
Editing your replies to pretend you didn't completely overlook that the post was a link to the repo is super fucking childish.
Moreover, given what you actually said in your previous "I don't even know what this is you should have a link" replies, asking for
Is just double super disingenuous.
Grow up.
VictoryMotel@reddit
You're having a meltdown over just asking for more context up front.
It seems like you pick fights over nonsense quite a bit, here you are arguing over "star wars fandom" while everyone tries to convince you that you're being ridiculous.
https://old.reddit.com/r/videos/comments/1kjqb9w/media_literacy_and_the_superman_trailer/mrrp1ex/
NotUniqueOrSpecial@reddit
My brother in Christ, you have no idea what a meltdown is.
I'm calling out your dishonest behavior; you could've just said "oh, my bad", but you had to edit multiple comments, instead.
Like, I actually approve/applaud going through people's history to get a handle on who they are/how to respond to them.
But if you had to go back 10+ pages/5 months into my history, you're really grasping at straws, lol.
VictoryMotel@reddit
I don't think any of this is about me, I think you're frustrated and saw a down voted post to pile on to.
Most of your post history is you going around in circles, trying to denigrate people the grammar of people who obviously speak english as a second language, clutching your pearls over people who aren't aware of niche events, nitpicking technical details on people making generalizations, and generally being super insecure and insulting while not explaining yourself.
It also seems like your actual programming knowledge comes from reading headlines, there is no real insight into actual programming, just sys admin level knowledge of what certain programs do.
Perfect-Highlight964@reddit (OP)
The project is linked, it's a snake game in 54-bytes, I thought it's pretty self explanatory, but maybe I'm already too used to the idea in my own head
NotUniqueOrSpecial@reddit
No, that person's just...really not observant.
VictoryMotel@reddit
All I'm suggesting is linking to the actual gitthub instead of just a PR, putting a line that it is written in asm for DOS and maybe linking to the previous posts.
NotUniqueOrSpecial@reddit
The post is literally a link to the repo.
NotUniqueOrSpecial@reddit
The post is literally a link to the project. What in God's name are you complaining about?
roxgib_@reddit
I reckon if a decade ago you'd surveyed the top 100 computer scientists in history and asked them how short this could get down to, none of them would have guessed even close to this low. Truely incredible stuff, keep it up!
SahSon@reddit
Someone tell the vape web server guy he can now host snake on it as well.
uhmhi@reddit
Neat. Now turn the QR code itself into a snake game.
serendipitousPi@reddit
You are nuts in the best way possible.
ric2b@reddit
The kaleidoscope effect is interesting, do you have a defined line of what you'd consider a bug or are you willing to accept weirder and weirder side effects as you try to shrink it further?
Perfect-Highlight964@reddit (OP)
As long as the basic functionality is maintained, and every single element is distinguishable and unified (in the sense that every wall looks the same, every snake character looks the same, every apple looks the same, and none have overlapping looks) I don't care for the side effects
ric2b@reddit
Fair enough, so as long as the game is still reliably playable you'll accept the weirdness, basically.
Perfect-Highlight964@reddit (OP)
ig
Tai9ch@reddit
Why is there a food hole, and why can't you go through it?
Both_String_5233@reddit
After reading the comments on a post on r/vibecoding (reddit suggestion), I was ready to cry myself to sleep. Thank you for restoring my faith in humanity, this is awesome!
JBatjj@reddit
Pressing esc makes you fast travel to the right.
_Invictuz@reddit
I have no idea what I'm looking at but I am impressed.
mr_birkenblatt@reddit
Impressive that you still find new stuff!
zackyy01@reddit
How many hours a week on average do you dedicate to this madness?
Odd_Ninja5801@reddit
I got bored back in the 90s when I was testing 1960s Assembler code for Y2K and I built a working Othello game using REXX on an IBM Mainframe. But honestly this just blows anything I've ever done out of the water. Insane dedication to push the envelope to this extent to try and compress the game down.
I'm genuinely intrigued to see where it goes from here. Brilliant stuff.
TooLateQ_Q@reddit
The technology is almost here
satireplusplus@reddit
Uses a math instead of branches trick for the input keys, but pressing anything other than direction keys gives pure random madness lol. Try it!
Lunchboxsushi@reddit
Why is it so fucking big, these developers now a days man! I'LL HAVE YOU YOU KNOW WE SENT PEOPLE TO THE MOON WITH DUCT TAPE AND SPIT.
Legit impressive, but can it run doom?
Squigglificated@reddit
Awesome! I bet that 1 byte is keeping you awake at night though.
Perfect-Highlight964@reddit (OP)
We'll see, I hope not ...
TheDevilsAdvokaat@reddit
How many bites?
curien@reddit
Depends how well you play, obviously.
ApplicationMaximum84@reddit
That's impressive to fit into 33 lines of assembly.
roastedferret@reddit
I'm fairly certain you're insane, but at least it's applied well.
church-rosser@reddit
Quality post OP!
church-rosser@reddit
Quality post OP!
code_investigator@reddit
Glorious!
Perfect-Highlight964@reddit (OP)
Thanks!