Giter VIP home page Giter VIP logo

snake's Introduction

Snake

This is an x86 snake game made for DOS.

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 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 60 bytes.

How little is 60 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
c53000b80000cd108b3f
8d22e54021c30837bbd0
0778f5e4606bc00ad414
d5449801c739df73dc30
1d79d8ad893a7bdc880f
83eb5079f95b202779d6

Comparison

My version MattKC's version ibara's version
Bytes 60 ~1400 2024
QR
Link https://github.com/donno2048/snake https://mattkc.com/etc/snakeqr/ https://github.com/ibara/snakeqr

snake's People

Contributors

dependabot[bot] avatar donno2048 avatar hen-ter avatar peterferrie avatar sapir1998 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

snake's Issues

Problem In Rendering

Hi,

The characters don't seem to render correctly for me in the browser.

This is what I see when I open the demo link:

image

Let me know if you need any more information for debugging it.

Does making walls unpassable and not allowing the snake to go 180 really worth it?

If I remove those lines:

snake/snake.asm

Lines 30 to 37 in f5625bb

sar bx, 0x1
lea ax, [di+bx+0x2]
mov bl, 0xA0
div bl
test ah, ah
jz start
cmp [di], ch
je start

The only effect it'll make on the game is that the snake will be able to go 180 degrees and pass through the right and left walls, this will also automatically reduce the size by seventeen bytes, and by making bx redundant may get it even to eighteen less...

Very fast, poor random

At least for me, in browser (firefox, linux), the game runs blazingly fast. Before, with the slow down as the snake grew, as long as I could survive to eat 2 or 3 times, then the speed became more reasonable, but with the new version which maintains full speed, I find it to be uncomfortably fast (but maybe it's just because I'm getting slow in my old age ;-) ). In addition, it seems that the randomization of food placement only happens when food is actually eaten, so I think you get the same sequence of food locations every game.

With the newly available speed, would it be feasible to tick the random number generator every game tick? You'd still only draw the food at the new location when the player ate the previous food, but the food placement will vary based on how many steps the snake has moved, rather than how many food the snake has eaten, thus adding randomization based on player actions. If a player managed to play identically, they would get an identical sequence of food, but most games would, I think, end up with more variation?

This only makes sense if there's some internal state to the random number generation, but it appears that's kept in dx, and if so, then generating more random numbers should change the sequence.

I'm not sure if it would help save any code size, but it doesn't seem like it would add any.

Is it even possible to reduce the size further?

I have been experimenting for hours and it either stays at 85 or wrecks up the game. Is it possible to go further? IMO, the only way is to compromise functionality. Either way, the result is already impressive.

Replacing `mov` with `rcr` doesn't work

Why doesn't replacing

snake/snake.asm

Lines 34 to 35 in 77ee28a

mov [bx], BYTE 0xFA ; store wall character (every character between 0x80 and 0xFE will work)
sub bx, 0x50 ; go one line backwards

with

rcr BYTE [bx], 1
add bx, BYTE -0x50

work as well?

(the sub is replaced with add to set the carry flag and rcr 1 with carry flag set ensures the highest bit of [bx] is set)

Use `and` instead of `test`

test has a latency of .2 while and has a latency of 1 (and so does add and sub) we want to make the game slower so we won't use test

Making the demo slow without lag

The demo should be slow and the current js hack is making the keyboard input laggy, also tried using Bret Johnson's SLOWDOWN utility with 100 cycles i.e.

Dos(canvas, { cycles: 100, onprogress: ()=>{} }).ready((fs, main) =>
    fs.extract("snake.zip").then(() =>
        main(["-c", "SLOWDOWN /Q/S:0/B:N snake"]).then(ci =>
            swipedetect(swipedir => swipedir && ci.simulateKeyPress(36 + swipedir))
        )
    )
);

But there is a speed bump whenever a key is entered on the keyboard

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.