implementing the iteration of the next state of the cells