Eco Simulation  «Prev 

next empty Squares - Exercise

Creating next() for empty squares

Objective: Write a version of next() that determines how to fill an empty square in the simulation.

Instructions

Here are some fairly simple rules for determining how to fill an empty square:
  1. Check if there are other foxes nearby. If there are at least two of them, fill the square with a fox.
  2. If the square is still empty, check if there are any other rabbits nearby. If there are at least two, fill the square with a rabbit.
  3. If the square is still empty, check if there is any grass nearby. If there is, fill the square with grass.
  4. If the square is still empty, leave it that way.

Remember, you can use sum to determine how many of a particular lifeform are nearby the current square.
The code you've examined so far for the living class is also available in a file named living.cpp, which can be found in the compressed course download file.
Paste your code below and click the Submit button when you are ready to submit this exercise.