Your task is to program a model of an parameterized island consisting of an array of locations (for example, a 100x20 matrix). The locations will be populated with plants and animals. Animals can:
- eat plants and/or other animals (if their location has suitable food),
- move (to neighboring locations),
- breed (if two of a kind exist in a location),
- die of hunger or be eaten.
When creating your host of animals, you should use OOP as much as possible: all species will derive from one abstract Animal class, which will contain the behavior that is common to all animals. If specific animals have specific features in regards to their feeding, reproduction, movement, etc., then they need to override the methods of the Animal class.
Here's what you need to do:
1. Create a class hierarchy:
Carnivores: Wolf, Boa, Fox, Bear, Eagle
Herbivores: Horse, Deer, Rabbit, Mouse, Goat, Sheep, Boar, Buffalo, Duck, Caterpillar
The table below shows how likely an animal is to eat "food" if it is in the same location as that "food". Let's look at the situation where "a wolf eats a rabbit". The number in the table is 60. This means that if a wolf and rabbit are in the same location, there is a 60% chance that the wolf will eat the rabbit. You need to use a multithreaded random number generator.
|Weight per animal, kg||Maximum number of animals of this species per location||Maximum speed (number of location) per turn||Number of kilograms of food required to fully feed the animal|
2. An animal must have methods for eating, breeding, and choosing a direction for movement.
3. You can implement the eat method in the herbivore and carnivore classes. But be careful, the herbivore duck eats caterpillars.
4. In specific classes representing particular species, you can modify all the methods to suit the characteristics of the animal.
5. You need to create at least 10 herbivore species and 5 carnivore species (described in Item 1).
Of course, it is possible to write the entire program on one thread using only loops. But we need practice working with multithreading, so you must use threads and thread pools. One scheduled pool to run recurring tasks for plant growth and animal actions, and a task to display system statistics. Alternatively, you can display the statistics in a task with the plants or animals. Inside the animal action task, you can use another thread pool — an ordinary one. You decide which tasks to assign to this pool.
Mandatory parts of the task:
Optional parts of the task:
About settings (if you decide to add them)
To make it convenient to change the various settings when starting the program (the island size, the maximum allowable number of plants / animals at one location, the probability that a particular type of animal will move, the number of offspring in different species, etc.), you need to put all these settings somewhere, for example, in a separate class. It should be possible to change the following settings:
- island size
- duration of a clock cycle in the simulation
- the number of animals of each species at the start of the simulation
- condition for stopping the simulation (e.g. all the animals have died)
- number of offspring for each type of animal
Unicode (if you decide to do pseudographics)
You can use Unicode characters to depict the animals: 🐃, 🐻, 🐎, 🦌, 🐗, 🐑, 🐐, 🐺, 🐍, 🦊, 🦅, 🐇, 🦆, 🐁, 🐛.
GO TO FULL VERSION