Placeholder Image

Subtitles section Play video

  • hello.

  • This week I created artificial life of the command.

  • Prompt.

  • Of course.

  • Just look at how complicated and sophisticated this life is.

  • I've got clusters of individuals forming families and groups, fighting for resources and competing for space, that breeding and multiplying.

  • And occasionally you'll see them sending out a member of the family to go and interact with other clusters.

  • I am, of course, talking about the British mathematician John Conway's Game of Life, which is a class of cellular automatic.

  • Now you might think that a really complicated behavior like this would take several thousands of lines of code to implement.

  • In fact, it doesn't.

  • It takes about three.

  • And this is why cellular automatic really cool.

  • You can take a very simple rule set.

  • Spread it across a hugely parallel processing substrate, and the resulting emergent behavior can exhibit all sorts of really complicated phenomena.

  • Like several of my other videos.

  • This video will use Theo well, see consul game engine, and you can click the little link above to see more details about that.

  • But essentially all it does is wrap up the command prompt in a display buffer so I can draw to it easily.

  • To use the console game engine, you need to create a class that inherits from it and over right to methods which are our music.

  • Create on on user update.

  • I've called this class the game of life and in our in main function.

  • Now all we need to do is create an instance of the class the game of life class on Tell it what dimensions of the console we want.

  • So to start with, I'm going to use 1 60 characters across by 100.

  • Down on each character is going to be eight by eight pixels and then call the start function, which will then repeatedly call the unusual update function.

  • This album holds a particular special place in my heart.

  • For as long as they have been computers.

  • There have been people programming John Conway's game of life for them now for a number of years.

  • I worked in academia, and I worked in a field where we developed a technology called cellular process for a raise.

  • These were highly parallel processing devices, and to test them, we would always run game of life because if we saw that it could ruin life, it could probably do all the other complicated things.

  • We needed them today.

  • I'm not going to go into the history of game of life.

  • There's an excellent Wikipedia article that will do just that and we'll be using This article is a source of inspiration to try out different patterns.

  • The sheer amount of research into game of life is vast.

  • Mathematicians, Lovett computer scientists love it on people have proven that it's got all sorts of fantastic properties.

  • For example, it's quite possible to set up a pattern where the little critters will move around, implements a fully functional computer, a member of the patterns which could emulate circuits.

  • And people are using it for generating music and all sorts of interesting sequences.

  • But fundamentally, the whole phenomena stems from very simple rules, and I mean very simple rules.

  • And this is why it's such an interesting algorithm.

  • How do you get all of this complex?

  • We call it emergent behavior out of such a simple rule set.

  • So how do we make silly little tomato?

  • Well, the first thing you're going to need is a grid, and in this case I'm using a two dimensional grid off squares where a cell is directly connected to its immediate neighbors.

  • Every cell in the grid executes a program, and all of these programs are identical, but they operate on local data.

  • Each cell contains a memory which can be used to store its current state and for game of life.

  • This is very simple.

  • It's simply on off, but it could be much more complicated.

  • Each cell has the ability to interact on, communicate with its neighbors.

  • And finally, But this is the most important part.

  • All of the cells run a program, but they all run the same program and they all run the same program synchronized with each other.

  • This gives way to the S I m d paradigm single instruction, multiple data where a single instruction is broadcast across the whole processing array, but it uses its local data to operate on.

  • So this s I M D approach.

  • Coupled with a neighbor.

  • Communication gives rise to cellular water matter.

  • The program for game of life is very simple.

  • Step one, we count our neighbors.

  • So let's assume I am this cell in the middle here on.

  • I have some alive neighbors.

  • When I was going to be indicated by red dots.

  • We can only talk to the neighbors in our immediate vicinity, so this gives us a three by three square around the active cell, and we can count how many red dots are in this square.

  • So in this case, it's three.

  • Now.

  • This is where we introduce some very simple rules.

  • Let's consider the rules.

  • When the style is alive, I'II its output.

  • It's set toe one, so it's got blue dot or it's a red daughter.

  • If the cell is alive and has less than two neighbors, it dies from loneliness.

  • If it has greater than three neighbors, it dies from overcrowding.

  • Otherwise, the cell has a good number of neighbors, and it's happy we'll put a smiley face on and it stays alive.

  • Now let's consider a dead cell.

  • It's not out putting anything, but in the weird world of John Conway, if a cell has three neighbors and it's dead, those three neighbors get together and produce a living cell.

  • And so, in this instance, this cell now becomes active.

  • In fact, so does this one, because it to also has three active neighbors.

  • And that's it really is how simple the rules set is, but there is one more important thing to do.

  • We have to do everything at the same time, we cannot scroll through the cells one by one and update them is necessary.

  • Instead, we have to treat all of the cells as if they're in one hee park of time.

  • As we carry on schooling through the cells, we can't count the ones that have already been set on this sea park, or else this one would also become alive.

  • And then this one would also become a life on these air incorrect results.

  • Having seen how simple the rule set is, it's time to do this in code.

  • And I'm going to do this by creating to two dimensional arrays one that represents the output on one that represents the current state of the cell.

  • So the output is what basically will see on the screen on DTH.

  • E state is the current memory within the cell.

  • In the unused create function, I'm going to know allocate the memory for my 22 dimensional race on.

  • I'm going to use the screen wait thin screen heights.

  • So that's 360 by the 100 characters that we set before, and this means I can choose.

  • A council of any size on life should function appropriately just for good practice on, then going to set both of these rays two zeros.

  • Now we're working with two D raise.

  • It's often needed to work with two dimensional coordinates, so I'm going to create a little lambda function here.

  • Thio make it a little bit easier for me to access the array, and in this case, I want this lambda function to return the value off the output array.

  • Depending on my accent y coordinates I'm using the screen went Fear to multiply.

  • By the way, we're going to treat the our news update function as if it's a single iPAQ.

  • So every time this function is called, we're going to do a full update of the entire array.

  • But before we start to modify the state of the ray, we need to store it in the output.

  • So now we're free to interrogate the output on dhe change the state of the cell.

  • I'm going to use two nested four loops to iterated through all of the cells, and you'll notice I'm starting them from the coordinates one on.

  • I'm going to the screen with minus one on the screen.

  • Height minus one.

  • I'm doing this to avoid reading memory, which isn't there.

  • They're actually several approaches in cellular autumn art about what to do with the boundaries.

  • In this case, I'm just ignoring it.

  • They're going to remain fixed.

  • But some people do actually prefer to happen.

  • Going periodic.

  • So ask the cells.

  • Activity goes off one side, it appears on the other.

  • The first part of the algorithm said we need to count the number of cells in our immediate neighborhood.

  • Well, I can use the cell lambda function that I created before to help me with this.

  • So it's just the current coordinates minus one.

  • And this is the northwesterly cell now, because the value is either a 01 I could just keep adding these and count them as I go.

  • In this case, I'm not moving along in the X axis.

  • I'm gonna put a plus zero in here just to keep it consistent.

  • But I'm still on the robe off and I do this for all of my neighbors.

  • So here is the northwest on here is the Southeast.

  • I don't need to behave differently, depending on whether the current cell is alive or dead.

  • And we can do that by just checking the output.

  • So if the current cell is alive, it's set to one.

  • Now, if I'm alive and I have two or three neighbors are said, before I'll remain alive, I'll carry on being alive.

  • However, in any other condition, I'll die.

  • So here I've got a little Boolean check on.

  • I'm kinda cheating.

  • I'm forcing a Boolean to be an interview value in this case.

  • So if I've got two neighbors or three neighbors, I remain alive cause it'll return true.

  • Anything else will return false and kill the cell.

  • If I'm not alive, then I only become alive if the number of neighbors is equal to three.

  • Since we're iterating through all the cells in a nested full loop, I might as well take advantage of this opportunity to draw them.

  • And to do this all, I'm going to do it again, check whether the current cell is alive or not, And if it is, I'm going to draw a white character, and if it isn't, I'm going to draw a black character, and that's it.

  • The highlighted code is all we need to implement game of life.

  • Let's run it and see what happens.

  • So you can see the council has popped up.

  • But hang on, there's no life.

  • Oh dear.

  • Well, that's because we haven't got any starting cells.

  • We initialize all of our memory to zero to begin with.

  • But we need some cells to breed to produce a new cell to test if the algorithm works or not.

  • I'm going to go through each cell on dhe, set this state randomly to zero or one.

  • Let's try again.

  • Perfect.

  • There we go.

  • We can see life quite happily living.

  • I'm going to have a little bit of input handling code here to check whether I'm holding down the space cake because I only want life to evolve.

  • If I'm holding the key down, This allows us to stop it and analyze it.

  • Hold the space down on let go and we can see life stops.

  • As people began to study the game of life, they realized that certain patterns exhibited certain behaviors.

  • The Wikipedia article lists some of these, and I thought it would be fun to try and still do them more closely.

  • So instead of starting with a random state for all of the cells, I'm going to manually set the state of some of the cells.

  • Now I could do this like so where I manually specified the coordinates of the cells and put them into the array.

  • However, this will make it a bit tedious to enter the patterns.

  • I'm going to try something a bit more visual has before I'm going to create a little lambda function.

  • Except this time it's for setting the value of the cell.

  • So again it takes an X and A Y corners.

  • It also takes a type string.

  • The contents of this Lambda function will iterated through the string character by character.

  • And if the character is a hash, it specifies a one in that state location.

  • Otherwise, it's a zero.

  • This leaves us now with a much nicer syntax, for specifying starting shapes where I can visually see what the shape should look like to start with.

  • Let's have a look.

  • This is the pen, Tommy.

  • No, I don't like the space bar thing now, and instead I'm just going to slow the third down with a weight.

  • So from that starting point, we can see it grow and we can see we've got some spinners and some gliders, the gliders of the ones that travel a great distance.

  • Let's try something a bit more interesting.

  • The Gospel Glider gun.

  • This is an example of an automatic producing something with more usable output.

  • Let's take a look.

  • So here we can see that some bouncing back and forth between two starting points, but it continuously emits gliders.

  • Our little lifeforms have managed to create a sequence.

  • And don't forget it's really complicated.

  • Behavior is implemented with just two if statements.

  • Mathematicians also found out that is possible to have patterns which exhibit infinite growth.

  • Have a look at this one.

  • This one's all implemented in a single line.

  • I like the symmetry of this one.

  • Cellular automata on a sequential machine like my desktop PC can be quite demanding of the process, sir, so I'm going to set it back.

  • Two.

  • Just doing a random start intercepted to release mode, and I'm going to double the resolution of my counsel but half the size of the front and just let it run away.

  • Cellular Tomato is an intriguing field of research, and I've only shown one very simple album, the mouths of many, many hundreds.

  • It's not just interesting to mathematicians and computer scientists.

  • People are now searching for it in biology the most some evidence to suggest that cells in the body might also interact in this way.

  • Whatever you might think.

  • I think there is a definite beauty to the emergent behavior from such a simple rule set.

  • As usual, all the source code is gonna be available on get help.

  • If you've enjoyed this video, give me a big thumbs up.

  • I think about subscribing and I'll see you next time.

hello.

Subtitles and vocabulary

Click the word to look it up Click the word to find further inforamtion about it