forked from donno2048/snake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.py
97 lines (76 loc) · 3.96 KB
/
update.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from re import findall
README = '''# Snake
This is a snake game in assembly made for DOS.
The game was [covered in Hackaday](https://hackaday.com/2023/08/03/its-snake-in-a-qr-code-but-smaller/).
You can view the online [Demo](https://donno2048.github.io/snake/) (Use your arrow keys on PC or swipe on mobile).
Inspired by [Can you fit a whole game into a QR code?](https://youtu.be/ExwqNreocpg) by @itsmattkc which was also [featured in Hackaday](https://hackaday.com/2020/08/17/fitting-snake-into-a-qr-code/).
<details>
<summary>It was made to create the smallest "fun" game possible.</summary>
<br/>
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.
</details>
To build and run it use:
```sh
sudo add-apt-repository ppa:feignint/dosbox-staging
sudo apt update
sudo apt install nasm libsdl2-2.0-0 libsdl2-image-2.0-0 libsdl2-net-2.0-0 libopusfile0 dosbox-staging -y
git clone https://github.com/donno2048/snake
cd snake
nasm snake.asm -o snake.com -f bin
dosbox snake.com -c "cycles 1"
```
It is so small I could fit it into a single QR:
<img src="./snake.png" width="250"/>
It's `%i` bytes.
<details>
<summary>Hex</summary>
<br/>
```
%s
```
</details>
'''
hexdata = open("snake.hex").read().replace("\n", "")
length = len(hexdata)
for div in range(int(length ** .5), 0, -1):
if not length % div:
break
open("README.md", "w").write(README % (length // 2, "\n".join(findall('.' * (length // div), hexdata))))