1. 50
    1. 18

      1 int is enough if it’s a big int.

      1. 26

        Accessing RAM is just slicing into one really big int.

      2. 1

        I’m gonna be that person: someone please do it.

    2. 7

      I kind of feel that using several different integer sizes is “cheating”, even though I’m not really sure if cheating is a thing that can apply to this. I don’t know. As a reader, when I see “4 integers are enough to write a snake game”, I expect at least 4 uint16_ts, or 4 uint8_ts, or something smaller than a 64 bit integer. Really the title should be “136 bits is enough to write a snake game”.

      Like, I clicked on this to see if I could apply a similar technique in some bootloader code I’m writing, but the technique is just - “use really large integers” and “use bitmasks”. That feels anti-climactic and disappointing.

      At the same time, I don’t feel that this is the author’s fault, or the fault of the article. It’s just a dissonance of what I expected when I clicked on the article, which the author couldn’t have possibly known. At the same time, I can’t get past the fact that I feel cheated by this - “I made a snake game in 17 8-bit integers” isn’t nearly as interesting an article title, and it feels clickbaity because of that.

      1. 2

        I normally expect integer to mean 32 bits, but I guess it’s been long enough that 64 really is the standard now.

      2. 2

        Funnily enough, the total bits (32 + 64 + 20 + 2 + 8) do add up to less than 4 * 32. So perhaps you would have preferred it to be phrased as:

        • We will store the game map in a uint32_t where 1s will form the reptile’s body. The map will contain 4x8 positions. Enough to have fun!
        • We will keep two more uint32_ts as a directions array - this will be useful to move the snake around, while keeping its growing shape intact;
        • In the final uint32_t we will squeeze in:
          • four 5-bit integers for the positions of the head, the tail, the apple, and the (current) length.
          • 2 bits for input from the keyboard
          • 8 bits for looping.
        1. 2

          You are right, I believe that would’ve been a better choice of words.

      3. 2

        I think the title was unintentionally click baity, and may have created fake epectations. Didn’t meant to be extra-clever, I just wanted to use as few variables as possible and squeeze everything in as little as possible, just like some people in the embedded world are doing.

        The same feeling feeling of dissonance was shared by other people on Reddit, who downvoted the hell out of me and wrote some negative comments. Some guy even hate message me in the PM. Next time I will be more attentive with the titles.

        1. 2

          Yeah I mean, like I said I don’t blame you for this at all – it’s entirely me doing the leverage here. I’m really sorry you saw abuse from Reddit. TBH it’s not unexpected because I regard Reddit as a complete trashfire anyway and keep tabs on the SA thread mocking the hell out of them / alternately getting super shocked about the shit Redditors do. Fucked up that they went to your DMs too. Urgh.

    3. 1

      What if i want round edges on the snake when it turns? Surely more data would be needed then, e.g. if head is 0,0 and tail is 2,2, with no more information it is ambiguous which axis it went on the initial move from the tail.

      1. 3

        You express head and tail as offsets from the 0th bit of snake. To make it with round corners you need to modify a little the logic from move_snake() to make it “round”. Problem is the round idea doesn’t work well in such a limited grid as a with 4x8 possible positions.