- 10 Mar 2016
It is kind of obvious that for serious play of game of life we would need a computer to compute the next generation and the next and the next and even reach thousands of generations.
For this we would need three things:
- switch - check if a given cell is alive or dead using a switch/if statement. Based on the result we would know how to compute the neighbour cells.
- loop - do this thing 8 times for each given cell. So we need to do the same thing over and over again which happens in a loop. The same operation - again and again.
- arrays - this would be the most difficult part. The computer has to store the value for the different cells in a given way. What we could use is an array. Array could be of many dimensions which could make them pretty complex, but we would try to keep the complexity to a minimum.
- state machine - we would use this pattern to make the programming of the robot more understandable and easy.
Find the shortest solution in the 50 solutions for different programming languages in the list below:
Tasks description, submission and evaluation are available to subscribed users.
Subscribe now to access the full capacity and get feedback.
Let's talk for a moment about programming the Robotics Game of Life and for this we'll use a different programming language and as you can see by not using a computer it will be pretty difficult to compute the next generation.
Computers are really good at doing the same task over and over again and doing it in a very efficient way. So let's discuss how are we going to build a program, that would solve the Robotics Game of Life.
There are couple of things that we need in our programs in order to solve the Robotics Game of Life. First, we'll need some kind of a check and this is also known as a switch or if statement and because we looked at the field and we need a way to check is this cell alive or dead and for this we need a switch or an if. This is something we must know how to use. Then we must also do this for the other cells. So we need to do this for let's say 16 different cells, or a thousand or million different cells and this means doing the same thing over and over again. And for this we'll need a loop. This is another programming abstraction that we'll need to use. Then because we build a program, it needs to store some of the values we need to use arrays and I can assume that some of you are not familiar with arrays, so don't be discouraged with this, we'll get to work with them and we'll introduce you to arrays and also we have couple of videos that also introduce you to arrays. And we'll have most of the programs already ready, so you can just look at them and learn how to read them, instead of programming them from scratch and one last thing that we'll use is something that we called a state machine. And this is the way that we'd like to program our robots. Using a state machine.
and we are also thinking about other languages. For the EV3-G we'll have a program that solves the Robotics Game of Life on the screen and we'll also have a program that directly moves the robot on the field. So this is what we need to know and this is what we'll introduce you to in this course. Switch, loops, arrays and state machines. This is the general way we are going to program this Robotics Game of Life. The way we program our robot using switch, loop, array and state machines and the general algorithm for solving the Robotics Game of Life is the following, we have the grid and in it we would like to know if a given cell, let's say this one here should be alive in the next generation or not. And what we should do is actually find all the neighbors of this cell and the neighbors are these are the direct neighbors of our cell. And then we must count how many of them are alive and how many of them are dead. So we just move and we count. We count his one it dead, then we count this one it's alive, then we count this one, and all the others. So that's the that we program the robot, we can also count in the other way, we can count by rows.
And for those of you that already used arrays in other programs, we'll use a loop and a loop inside to do this and for the others we'll just provide the programs ready and as you have the programs already implemented you can just customize them and look at them and learn from them and in this way this will be both for intermediate students and beginners and for the beginners you can just look at the programs and try to customize them and if you consider yourself intermediate or even advanced, you can try to implement the programs from scratch. If you can't implement them from scratch you can just look a the solutions, that you have already provided. Again, the general way that we program and it's a general algorithm for Robotics Game of Life is just look at the neighbors of a cell, count how many of the cells are alive and then calculate if the given cell should be alive at the next generation or not.