Conway's Game of Life% | Godot Speedrun #1

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello i'm a fellow today i'm going to be speedrunning go.engine now you might be wondering what that means and i can explain basically for every episode in this series i am going to create a new speedrun category for godot and then i'm going to get the world record for it today i'm going to be speedrunning conway's game of life percent which is the category where i create conway's game of life if you don't know conway's game of life is basically a game where you have a grid like this this is pretty small but it's just for the example and you have dead cells and the live cells so let's say this cell here this black one is alive and then all these other ones are dead i'll add another alive one so he has a friend basically when you run the simulation there are some rules that will determine which cells will die which cells will survive and which cells will become alive these are the rules here i just have them open in case i need to reference them which i probably will but that's what i'm going to be doing today so i have this empty project here i just changed a few settings to half my grid here it's 32 by 32 all right speedrun is starting in three two one go okay so let's start by making a main scene here i'll just call it main save it and i'll add a tile map here and i'll call it grid and i need a tile set i do not have a sprite so that's um kind of an oversight i'm going gonna use the go dot icon how do i set the grid here there it is here we go now we have to go oh wow he is big okay i'm gonna have to turn down the scale here to 1 divided by 64. that is 0. you know what i'm just gonna make a texture real quick this is just one white pixel because i don't really want to figure out how to scale this guy down and i also don't want this to be godot icons everywhere so okay great i have my texture new tile set and i'll put in my i have to move my timer here put in a live hopefully i can center that right it's probably fine okay i think that should be good uh it's not good i need to turn down the cell size here there it is ah isn't that beautiful that's what you love to see okay i'm just gonna make a a little smiley face here for testing and now we can finally create a script here i mean i guess that's the grid part done right all right let's change the split here find the neighbors all right so i'll just add a function here called step i don't need an underscore there and i'll do four x in wait hold on i'll call himself for cell in grid dot get what's the function here let me see the documentation get used south that's what i want used south so this will give me all of the live cells and wait actually i want to go through all the dead cells too so i need to get all of the cells i guess i'll just go for cell in range wait i'll change it to x and y so i can have like a for loop inside a for loop so you know i'm just gonna have a size variable here and now we can do wait i don't want get i'll just use normal guess cell because then i don't have to turn it into a vector what do i want to do with this is equal equal to zero so that means it's alive and if it's negative one then it's dead so this is this will get me all of my live cells so let's look at our rules here any live cell with two or three live neighbors survives maybe i should make a function called get neighbors i'm gonna do that function get neighbors x and y this uh colon here is defines the type of that variable let's go to our my whiteboard here what i want to do is i want to get let's just say i'm focusing on this cell i want to get this one and this one and i think also the diagonals too is that right i think that's right yeah yeah that's right okay i'm going to use a for loop again for i in range x minus one and then x plus one wait no that's not right first so for this loop i want to get this oh that's my camera hold on i want to get from x minus 1 to x plus 1. hold on how does the range function work again i can give it to values right yeah i can't so i had it right x minus 1 and x plus 1. and then i'll do four j in range y minus one to y plus one so this is basically the same loop i have here except it's only looping through that's my camera again it's only looping through all of the neighbors of the cell so it would go through this one this one this one this one this one this one and also itself actually which might be a problem so yeah and also not in that order it would go from i think it's going to go from top to bottom and then left to right so yeah i'm going to go if grid dot get cell i j is equal equal to zero actually what i can do is make an array here i'll just call it array short for array and then i'll append this to array so just like that and so this will give me an array of all of the neighbors and then i also need to get rid of the case where it's where i j is equal to x y so if i is equal equal to x and j is equal equal to y then continue so this continue will break out of this loop wait hold on i don't want it to break out of the loop i wanted to skip this one wait no break no break would break out of the loop continue will continue to the next iteration of the loop so i had it right so i think this should work and then i'll just return array so this that should get me all of the neighbors i just do var n is equal to get neighbors um x y actually i think all i need for this is the number of neighbors not where the neighbors actually are so instead of returning an array i'm going to return n which will be the numbers of of neighbors far n is equal to zero and i'll just do okay lf grid dot get cell i j is equal equal to one so this will check if the cell is alive then i will do n plus equals one there we go now all i need to do is check the number of neighbors so what was my thing here any lifestyle with fewer than two live neighbors dies okay um if n is less than two then then i'm gonna store this in a variable here this get cell function so i'm just going to call it cell and then put that at the top if our cell is equal to that okay if cell is zero then it's alive so if n is less than two then cell is equal to negative one wait i should use set cell actually zero no negative one okay any live cell with two or three live neighbors lives okay l if n is equal go to two or n is equal to three then i'll just copy this and actually actually i want to do nothing so i'll just actually i don't need this function i don't need this one at all because i'm not doing it anything to it so just get rid of that any live cell with more than three life neighbors dies okay if n is greater than three then paste that okay so that's the killing done that's the basically all i need to do to live cells and then any dead cell with exactly three life neighbors becomes a lifestyle okay well actually what i can do here is instead of having a whole another if statement here i'll just do or n is greater than three okay and alif so actually there's only two options here so i'm just gonna put an else okay and three live neighbors becomes a lifestyle exactly three else i'll just do an lf to make this shorter alif n is equal equal to three then copy this grid dot set cell zero okay i think that's actually i think that might be it actually what i'll do is i'll have a timer in my main scene here timer and i'll just put it to 0.2 and then auto start and i'll put this in a timeout and then i'll connect timeout to step so that will so now step will run every time the timer runs out so [Music] let's see if this works oh um okay maybe my no let's see basically when i ran it it went for one step and then everything just died i think that's what happened so definitely that definitely was not supposed to happen um huh oh okay i figured out what's wrong it only took me like six minutes look there's the problem right there i tried to see if it's won but i should have been checking if it's zero because in tile sets the first tile is zero the second tile is one like an array and i totally forgot about that so now now i think it should work dang it it still didn't work um okay let's see hold on a second maybe it's because i used an and here i think yeah that's the problem because i'm checking if it's not so this is basically skipping all of the ones that have either of them true so basically what's happening here is it's skipping this one it's skipping this one it's skipping this one and it's skipping this one so i'm pretty sure that's what's happening so i should change that to an ore there we go so hopefully hopefully it's gonna work now i think i think it should work come on god dang it seriously oh [Music] okay i missed something look if you see here in this example it goes print range two to five and then in the output it goes 2 3 4 so it does not include it's not inclusive for the second value so what i should do here is x plus 2 and y plus 2. i think what was happening here is since i it doesn't include the last value then like it wasn't checking all these and it wasn't checking any of these either so yeah that would definitely cause problems so let's see if i think hopefully cross your fingers i think this will work come on okay something happened but i don't think that was right wait hold on a second that might have actually been right let's just look at this real quick because if it has two neighbors then it survives and it has three neighbors it also survives so basically the only ones that have two neighbors is this one here which has these two this one which has these two and then those will immediately die after that because after the next iteration they won't have any more neighbors to live with so i think was that that might have actually been correct and my drawing here is just bad at showing the game of life so let's see what does a glider look like because if you look at this example here you can create these little glider things but i not sure how to create them um i'm just going to try and copy it just just wing it very cool pun me i think that's what a glider is supposed to look like let's see so if if my game of life here is correct it should start flying downwards and like diagonally okay um i might have constructed it wrong let's see okay that is the correct formation of a glider so if this works then that should start flying diagonally to the bottom right please okay it didn't work i just thought of something you know what it could be is that since i'm updating my cells before i check the next cells that could be messing with it so what i'm saying is that while i'm in my loop here my cells are already being updated while it's looping so like if i were like for example at x 1 y 12 and then it dies i would set the cell to negative 1 but then i would go down to x x1 y13 and it's gonna be different because my cell has changed already so that could be what's causing problems so i'm gonna try to fix that let's see i'm just gonna make an array here called live and it's um i'm gonna all the cells that live i am going to let's just go with an else here and then live dot dot line live dot append vector 2 x y and then also do that here for the ones that survive and okay i think that's all i need to do here and then on the step i need to clear live at the beginning so i'm not taking the live cells from the previous frame and at the end here i need to do four what i should do before this actually is clear the tile map is there a function for that let's see yes clear grid dot clear and for cell in live grid dot set cell v the difference between set cell and set so v is that set cell v uses a vector 2 so it's uh easier for my life here because all i have to do is write cell instead of cell.x and then cell.y so that's why i use that sophie i've been trying to bug fix this for maybe 20 minutes now and so i just want this to be done with so please please just work nope it did not work expected two arguments oh right i forgot that was a dumb mistake okay come on great it's still god dang it um it almost worked i think oh you know what here this is the problem i forgot to change that because not only do i need to get not only do i need to add the cells that live to live but i also need to not do to get rid of this set cell here because that is also messing with it so i'm going to just change this to if n is equal equal to 2 and no or n is equal to 3 then i change it okay please i think i am pretty like 80 let's go with 80 sure that this will work just i just have hope come on yes it works finally look at that glider oh it's beautiful speed run finished complete that's conway's game of life oh my goodness yes finally that's my speed run it took 45 minutes look at them they're gonna kiss oh that's cool wow that exploded that was pretty cool all right so that is the very first ever godot speedrun of any category conway's game of life percent done in 46 minutes and 23 seconds let's go oh my goodness okay so that's all for this video um thank you for watching if you want to see more speed runs then uh i guess leave a like actually usually i ask you not to leave a like but i am just so grateful that i finally got this to work that i will allow you to like just this once but i am still not allowing you to subscribe or to ring that bell so do not do those under any circumstances alright thank you for watching and i'll see you in the next video bye
Info
Channel: Afely
Views: 269
Rating: undefined out of 5
Keywords: Godot, Gamedev, Speedrun, Programming, Coding
Id: fJrLBhEkdTw
Channel Id: undefined
Length: 19min 51sec (1191 seconds)
Published: Sat Oct 23 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.