donno2048/snake
Fork: 23 Star: 853 (更新于 2024-12-06 11:39:43)
license: MIT
Language: Assembly .
A minimal snake in assembly
最后发布版本: v29 ( 2024-04-20 03:03:25)
Snake
This is an x86 snake game made for DOS, but there is also a version that requires no BIOS, bootloader or OS.
The game was covered on Hackaday.
Running
Online demo
To test the code you can view the online demo which updates for every change in snake.asm (Use your arrow keys on PC or swipe on mobile).
Self-hosting
If you want to test the code yourself you need to install the requirements for the build process and run it on your computer.
Installation
I'm using nasm
and python3
which can be installed with apt install nasm python3 -y
.
Building
To test it just run main.sh and open http://localhost:8000.
Motivation
Inspired by "Can you fit a whole game into a QR code?" by @itsmattkc which was also featured on Hackaday.
It was made to create the smallest "fun" game possible.
For the people mentioning jinX's snake64 I'd note that without disparaging the achievement made by jinX, his implementation does not obey the same restrictions mine does: In his version, the snake can go through the right side directly to the left side but not from top to bottom, food items randomly spawn so there could be 30 simultaneously, some random pixels are turning white, you need to use 4, 6, 8, 2 keys to move instead of the arrows, you must start the game with downwards movement or it crashes, you have to clear
the screen before starting the game, you have to initialize the correct video mode ahead, when you go through the top and supposed to lose you can just go back down, and as jinX stated "It will not work if you run a game from DOSBox terminal. It requires 0 (or 50h, 80h, 0D0h...) value in port 60h on start."
For the countless people saying I'm intentionally not mentioning the Hugi Size Coding Competition (a competition in which the competitors had to make the smallest nibbles game to win) here is my reply to one such comment (from when the game was still 133 bytes):
Firstly, it seems that you didn't even read the rules of the "Nibbles" game:
in the inside of this border a "snake" is supposed to grow, whose size is one pixel at the beginning. after starting the program, the snake's size shall grow one pixel more in each repetition of the program's main-loop.
Which is simply not the same as snake and a lot less difficult to implement.
Secondly, the implementations from this competition have flaws (not that they're not good but I'm saying it doesn't make my version bad) like, for example from the comments in the winning entry:
game can't handle any other keys but keypad arrow keys, you need to start it by typing pause|nibbles in DOS prompt and then hitting an arrow key
and
Because top memory segment in PSP is environment dependant[sic] you need version suitable for your environment
and it doesn't even work on DOSBox because of some special configurations needed.
From the second place entry:
When starting this program, press the 2 (DOWN) key __IMMEDIATELY__
And it too won't work without setting the cycle count and changing it sometimes breaks the game
As for the third place
press '8','4','6' but not '2' once game begins immediately
and the game breaks in the same way the second place does (and needs the same cycle adjusting) but the walls are also broken.
I'll look at the fourth place entry and stop wasting my time doing this,
Well, just looked at it and couldn't make it to boot
And lastly, what place is your entry to the competition? Before you criticize other people first check your criticism is correct and try doing it yourself before you judge.
Thanks for the feedback anyways :)
P.S. I didn't even claim my version was ideal, the main point of the post was asking for help, and this comment actually made me feel better about my implementation in a way, as in an actual size optimization competition someone had a submission of 121 bytes for just a line extending over the screen and my entire snake game (which obviously contains this functionality just as a small part of the entire program) takes only 12 bytes more now, and if I can fix the PR only 7 bytes more.
AFAIK This is the smallest snake game ever made.
Perspectives
It is so small I could fit it into a single QR:
It's 58 bytes.
How little is 58 bytes? Well, this line of text weighs more than 70 bytes.
And so does this arbitrary sequence of emojis: 👩🏼❤️💋👨🏼🧔🏽♀️👩🏼❤️💋👨🏼
An empty C program generated with gcc -Os -w -xc - <<< "main;"
on linux-x86_64 is 15776 bytes.
Hex
c53800b80000cd108b3789fcba0a2
0e54021c3000fbbd00778f5e460f6
ead414d5449801f039d8ab96d01c7
1d672e029d3880f75fa5b883779db
Comparison
My version | MattKC's version | ibara's version | EimaMei's version | |
---|---|---|---|---|
Bytes | 58 | ~1400 (compressed) | 2024 | 2953 |
QR | ||||
Link | https://github.com/donno2048/snake | https://mattkc.com/etc/snakeqr/ | https://github.com/ibara/snakeqr | https://github.com/EimaMei/snake-qr |
最近版本更新:(数据更新于 2024-10-11 09:10:44)
2024-04-20 03:03:25 v29
2024-01-22 01:14:53 v28
2023-11-21 04:35:34 v27
2023-09-23 04:14:03 v26
2023-09-11 03:53:13 v25
2023-08-08 15:43:02 v24
2023-07-26 23:50:53 v23
2023-07-26 22:10:01 v22
2023-07-13 17:35:34 v21
2023-07-12 04:20:14 v20
主题(topics):
assembly, dos, snake-game, x86
donno2048/snake同语言 Assembly最近更新仓库
2024-08-20 01:46:05 BLAKE3-team/BLAKE3
2024-08-13 17:59:17 bird-sanctuary/bluejay
2024-01-17 22:35:56 SheerSt/pokewilds
2022-03-27 23:38:05 mathiasvr/bluejay
2022-03-17 21:09:30 below/HelloSilicon
1970-01-01 00:00:00 vxunderground/MalwareSourceCode