Snake is a classic game in case you haven’t played before this is how it works you move a snake on a grid using your arrow keys you start out pretty small but whenever you eat an apple the snake Grows by one and a new Apple spawns somewhere else if you Accidentally run into yourself or run into a wall you lose but if your snake fills up the entire board you win this sounds like a really fun project for Redstone so without further Ado let’s get started just like all my other games we should probably display it on Redstone lamps so let’s start with a simple screen there we go perfect now the first big question is how do we want to represent the snake well the snake moves and when I hear moving I typically think of shift registers for example this is a shift register using locked Repeaters if this was our snake on these lamps we could move it like this but there’s a few problems with this approach for one the snake moves in all four directions so you would actually need a four directional shift register and there’s also the fact that different Parts of the snake move in different directions I mean if you’re snake looks like this then this part is moving right and this part is moving up so actually I don’t think shift registers are going to cut it uh what else could we do Well I know snake has been done a lot in software so I think I’m just gonna look online to see how people typically code it and hopefully we can find something easy enough to mimic with redstone I’ll see you guys in a bit okay I’m back and I’ve got some ideas from online but before I show you those ideas let’s get a little more formal about what we’re trying to implement here because as it turns out you don’t have to move the whole snake so we’re gonna have a board of cells and every cell is either part Of the snake blank or an apple on every iteration of the game there are two main things that happen one a new head spawns specifically it spawns in the direction that the player tells it to with the arrow keys and two the tail of the snake gets removed those two things put Together are essentially what moves the snake new head remove the tail new head remove the tail that gives us the illusion of movement okay but what happens when you eat an apple well I was looking at the Google version and when you eat an apple the tail kind of looks Like it freezes for a second so I think step number two should actually be if you didn’t eat an apple remove the tail and now this is what we’re implementing this is snake I mean you also have win lose detection but besides that this is the heart of the game Now let’s talk about those ideas I found online so unsurprisingly I found a lot of ways to do it some of them used counters others used linked lists or other data structures but what really stood out to me is this video right here by the gunmaster digital he made snake And Redstone as well and his approach to moving the snake is absolutely genius it’s completely different than anything else I’ve seen online and I want to show it to you his approach is to store every snake cell as an arrow pointing backwards to make a new head he just Moves in the direction the player says and points the new head towards the old head then to remove the tail this is where the genius kicks in he removes any cell that’s not pointing to the snake if we look at what all the arrows are pointing at the only arrow that isn’t Pointing to another part of the snake is the tail so the tail gets removed and yeah that’s the method in gunmaster’s video I honestly really like it it’s clever and it’s a pretty good fit for Redstone however there’s a problem and he mentioned it in his video the problem Is if the head of the snake passes by the tail the tail doesn’t get removed because during that frame it’s pointing to the snake and now the snake is locked in a loop and it just continues to grow indefinitely but when I saw that I immediately thought that might be Fixable because what if you just detected the head and if the tail is ever pointing to the head just make sure to remove it I mean I could be wrong here but I feel like that just fixes it and honestly even if I can’t fix it this Method is so nice that I think we should still use it for our game so now that we know our method let’s continue building since we’re storing arrows we know that every cell is going to have to have some memory to represent those arrows so I’m Going to make a bunch of signal strength memory cells there we go and now I can literally just assign the arrows to whatever signal strengths I want for now let’s use these assignments they might change later but that’s okay so if I put in a one and a 2 that literally means There’s a left Arrow here and an up Arrow here very nice the next best thing to build is probably the tail removal circuit because that sounds like it’ll be the hardest what I mean by tail removal is a thing that when I press this button it removes any cells that Are pointing to nothing and by remove I mean literally just set the cell back to zero right because zero is blank I’ll be back when I’ve made some progress oh my god dude this is way harder than I thought it was gonna be like I’m trying To not make it too big but it really seems like it needs more room alright see you in a bit okay unfortunately this did have to get a little bit big but I think tail removal might be working let’s uh grab that screen from earlier And connect it up so that we can test it okay first let’s just try one left arrow in the middle when I press this button it should delete itself because it’s pointing to nothing bruh let’s try again nice okay that was our first tail removal let’s try a bigger snake there We go bigger snake in there okay nice and and let’s go tail removal working flawlessly that’s kind of amazing next up let’s make the circuit that grabs the player’s input I say we just use some pressure plates for the arrow keys that should be fine yeah this is Perfect we can get all four signals out just like this we’re gonna need a little bit more logic though because right now if you get off of the pressure plates it needs to remember the last thing you pressed so let’s connect these lines to some memory latches there we go now it Remembers the last thing you pressed oh shoot I just realized look at this you can actually glitch it into saving two of them by stepping on two pressure plates at the same time that’s kind of annoying I mean we can make a circuit that forces it to choose only one of Them right in fact I think I’ve seen something like that before hold on yeah check this out so this thing chooses the rightmost input no matter what the inputs are which is perfect because now it’s impossible to Output more than one thing at a time let’s put this boy on The input nice even if we spam it like crazy now it just chooses one of them and of course it still remembers what we did last very cool I think that’s it for player input okay we’ve got tail removal we’ve got the player input now let’s make the circuit that spawns the new Head remember to spawn the new head we have to move according to the player input and point the new head towards the old head that second part is actually a lot easier than it sounds you can just use the opposite direction of the player input for example if I move left then I Know the new head needs a right arrow or if I move up the new head needs a down arrow it’s always the opposite direction this is going to be a big circuit so let’s get building all right well if I did everything right we should have a working head system There’s a lot going on here but uh to summarize I’m using a decoder to keep track of where the head is I’m using a pair of up down counters to move the head around and I’m using some ROM in the back to get the opposite arrow and Yeah that should be everything so let’s test it I’m actually really excited for this when I press this button it should spawn a new head okay I’ll take it let’s turn to the left and spawn another beautiful that’s so great and guess what now that we have a head system and a Tail system we can combine them to create movement I’ll just set up a clock to run both at the same time and hopefully we’ll be able to move the snake around okay the clock is ready it should just turn on when I flip this lever let’s also speed up the game a Little bit so that the snake moves faster and yo actually feels like snake Bro Look at that that is bro that is so cool movement done we’ve made some amazing progress so far but we’re not done yet the next thing to tackle is the apples so let’s talk about What exactly this new Apple system should do we need a system that spawns a random Apple detects if the snake eats the apple and if so do not remove the tail on that frame and spawn a new Apple randomly spawning an apple that’s not too bad there’s actually a ton of Redstone randomizers out there so I’m sure we could use them detecting when the snake eats the Apple that’s also not too bad you could have an and gate at every pixel to detect if the apple and the snake are both there once you have that detection signal it’s just a matter Of plugging it into the two things that it needs to do cancel the removal of the tail probably by subtracting a comparator or something and spawn a new Apple okay let’s try to make this thing wait wait wait wait wait wait wait wait wait there’s a problem there’s there’s a Huge problem how do I not think of this what if a new Apple spawns on the snake itself uh uh yeah I’m not sure how to deal with that to be completely honest if I don’t do anything about it then when it happens it’ll just get eaten Immediately which I mean is that really that bad yeah that’s bad that’s I can’t do that that’s just not how the game is supposed to work I guess I’m gonna have to make the Apple avoid the snake when it spawns but bro how the hell do I do That I’ll be back when I figure something out okay I’ve literally been trying to make a circuit that avoids the snake for way too long and I mean I’ve gotten pretty close but I just had an idea that I think might be better than all of this what if when the Apple Spawns on the snake we just ignore it I mean as long as the player doesn’t see it underneath it’s fine right eventually they’ll get off of it and we’re back to normal I know we’re deviating from the real game a little bit but trust me when I say this is way easier than trying to avoid the snake Okay I’ll see you guys when the Apple system is complete ladies and gentlemen we have apples at least we should I don’t know if it’s working yet but I hope so it all starts right here This is where the random Apple gets generated we have uh six binary randomizers three bits for x and three bits for y and then this Brown Line is the detection line it turns on when it detects that you’ve eaten an apple as promised it uses a bunch of and Gates Well kind of I had to modify them a little bit but it’s still just a bunch of and Gates the detection signal goes all the way over here and activates this latch which cancels the removal of the tail and of course it’s also plugged right back in to generate a new Apple And yeah that’s basically the entire Apple system it was definitely a bit of a challenge but it turned out to be pretty elegant let’s try this thing out alright I put an apple right above the snake you can see it there turn the lever on looks like it spawned a new Apple that’s Good wait no no stop why is it getting so big oh I forgot to reset this latch after it eats the Apple now it should work nice that’s much better and now I’m pretty sure the Apple system is fully working let’s go dude at this point we are basically done you Can actually play Snake on this thing I also put in the win lose detection off camera totally not because I forgot to hit record or anything but as you can see if you run into the wall The Game Stops and this lamp turns on which means We lost so all that’s really left to do is Aesthetics and there’s one thing aesthetic wise that’s kind of been bugging me this whole time you can’t always tell how the snake is shaped on the Google version you can because it’s animated for you but on our version Since it’s just a bitmap it’s kind of impossible sometimes is the snake like this or is it like this you have no way of knowing until you actually watch it move one idea I had to fix this was to spread out the pixels but that doesn’t really help you still have the same Problem however we have arrows right so what if we use the arrows to fill in the gaps whatever the arrows point to I’ll just light up that pixel as well that that could actually work now when you wind up the snake there’s always enough space to see what’s going on that’s Exactly what we need alright back in Minecraft let’s try to make a display that actually does this well good news I got it to work and it takes up the same amount of space that I was using originally the snake is uh thinner now and it looks so much better there’s no More confusion on how the snake is turning which is pretty amazing I might make a few more final touches to the display but other than that we are done I’ll see you in the Showcase Thank you foreign foreign If you like this video consider subscribing it’s free and you can always change your mind later I hope you learned something I hope you enjoyed peace out guys foreign Video Information
This video, titled ‘I Made Snake Game with just redstone!’, was uploaded by mattbatwings on 2023-01-04 18:30:08. It has garnered views and [vid_likes] likes. The duration of the video is or seconds.
Hi guys! Today I recreated the classic snake game with vanilla redstone. I hope you enjoy! Patreon: …