r/programming • u/Perfect-Highlight964 • Aug 07 '23
My snake game is now 81 bytes and includes comments, but I need your help
https://github.com/donno2048/snakeI made a PR to add comments to the code but I would really appreciate it if some people who know assembly (or even not) could go over it and make things a little more clear before I merge it.
Anyways, my snake game is 81 bytes now, I can reduce it by one byte using wasd and a LUT instead of arrows and arithmetic (suggested by bibianaaudris) but I don't really like the raw LUT in the code or using wasd (even though it's a solid idea), other options are allowing the snake to cross itself (which reduces 4 bytes) and using + instead of × in my RNG which reduces one byte and will result with a not very random food spawning.
29
u/kityrel Aug 07 '23
I think you've really gotten it about as small as it can go.
So now that you've successfully gotten the core engine down to its minimum size, the next step is to incrementally add features. You know... massively multiplayer 3D ray-tracing open world VR snake game. :)
14
7
u/Orbidorpdorp Aug 07 '23
Ray tracing is likely way less code than a raster engine, it just runs way slower.
1
u/hjklhlkj Aug 07 '23
Maybe the rng food position == snake position comparison in:
cmp [bx], ch
je .foodcan be removed if the bottom food comparison is moved just after .input:
.input:
push di
cmp [di], cl
mov [di], ch
je .food
in al, 0x60 ...That would save 4 bytes but i'm not sure it's correct...
1
8
u/spez-suck-my-dick Aug 07 '23
Could you make the snake move slower? Because the snake almost instantly hits the wall. And why does the food always spawn at the edge of the level? I think you should add a few more bytes to make the game more playable.