Writing the base classes
Before we do any simulation, we should start by writing the basic classes we'll be using, describing the behavior of the system's elements. To make our code easy to navigate, let's write those classes in a dedicated file using VS Code, as we did in Chapter 6, First Script – Geocoding with Web API, and Chapter 7, Scraping Data from the Web with Beautiful Soup 4. Pay attention to the highlighting—VS Code is very helpful at spotting typos and other problems with the code.
Now, let's get to it. Let's first create a herbivore class. To keep it simple, our animals will breed without mating, they will just add another instance of the same class, with a certain probability. As we'll be dealing with certainty, we will use ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access