Objectives: Introduce a new type of bacteria that moves in groups.
The new type of bacteria to be coded at this stage is characterized primarily by a specific mode of movement (in groups): the bacterium closest to nutrient sources will exert an attractive force on the others. This is therefore an example where the force governing movement is not the zero vector!
You are asked here to:
Bacteria moving in groups will be represented using a generic class GroupMotilityBacterium. Each of them will belong to a group (BacteriaGroup).
There may be several groups in a culture dish. The difference between one group and another will be based on:
Let’s start by modeling the concept of a group more precisely.
A BacteriaGroup will simply be characterized by:
A BacteriaGroup will be a simulable object whose update method is responsible for updating the “ leader ” bacterium at each simulation step. A BacteriaGroup is not drawable as such.
[Question Q4.11]: A culture dish will now also contain BacteriaGroups that it must evolve. Given that we want to have a Laboratory::addSwarm method that adds a BacteriaGroup (empty of bacteria) to each culture dish and can be called as follows:
getEnv().addSwarm(id)); // id is the string identifying the groupWhat changes do you make and to which class(es) to integrate this?
Answer this question in your REPONSES file and implement these changes.
The features that can reasonably be expected for the BacteriaGroup are:
Feel free to add other methods if necessary.
Let’s now complete the GroupMotilityBacterium class outlined earlier. A GroupMotilityBacterium is a Bacterium (it has all the generic characteristics of bacteria). For simplicity, we assume that it knows the BacteriaGroup to which it belongs.
[Question Q4.12]: A GroupMotilityBacterium must have a force governing its movement, just like single bacteria. What relationships do you establish to model this force?
Answer this question in your REPONSES file and implement the empty shell of the GroupMotilityBacterium class by setting up these inheritance relationships.
A GroupMotilityBacterium divides like a Bacterium, but must produce a GroupMotilityBacterium (belonging to the same group as the original bacterium).
Finally, to simplify matters, GroupMotilityBacteriums have no mutable characteristics other than their color.
[Question Q4.13] Given the above, which methods already present in the bacteria class hierarchy must you redefine in GroupMotilityBacterium?
Answer this question in your REPONSES file.
A GroupMotilityBacterium will be drawn as a Bacterium. If it is the " leader ", also ensure that in "debug" mode (the isDebugOn function in Application.hpp), a red ring is drawn around it (see the videos below).
The constructor of a GroupMotilityBacterium will take as parameters its position and a pointer to the BacteriaGroup to which it belongs.
The constructor will be responsible for adding the bacterium to its BacteriaGroup.
[Question Q4.14] If you examine the onEvent method in the previous program example, you will see that placing a GroupMotilityBacterium requires calling getEnv().addBacteriumToSwarm(id, const Vec2d& position);. The purpose of this method is to add a GroupMotilityBacterium to the current swarm by integrating it into the group with identifier id of that swarm. What do you need to add to your code and where to implement this functionality ?
[Question Q4.15] A GroupMotilityBacterium is therefore added to the box like all the others (it is part of the box’s collection of bacteria). Do you think the BacteriaGroup destructor should do anything?
[Question Q4.16] When a GroupMotilityBacterium dies, it should no longer be counted in its BacteriaGroup. What do you need to add to your code and where to ensure this constraint is met?
Answer these questions in your REPONSES file, justifying your choices.
Drawing on what you've done so far for the other bacteria and taking into account the description above, implement all the features of the BacteriaGroup except for the one related to movement (the move method).
To test this section, you can use the provided test GraphicalTests/GroupMotilityTest.cpp, which can be run using the target groupMotilityTest (which you will have taken care to uncomment in the file CMakeLists.txt).
This test allows you to create bacteria with group behavior using the keys from '1' to '3'.
When the first nutrient source appears, create a bacterium—using the '1' key, for example—by placing it on the nutrient source. This bacterium should immediately appear as the “ leader ” and begin feeding.
Create other bacteria from the same BacteriaGroup (using the same key) on other nutrient sources. You should also be able to observe changes in “ leadership ” depending on the proximity of nutrient sources, as well as phenomena such as division and color mutation.
| ← Here, the 1 key is used first (green bacteria), followed by the 2 key. The change in "leadership" based on proximity to nutrients should be visible. Color changes can be observed following cell division (facilitated by the prior creation of abundant nutrients). |
The move method will be coded similarly to what you did in MonotrichousBacterium.
The differences will lie in the following two points:
To test this part, you can use the same test as before.
This test allows you to create bacteria with group behavior using the keys '1' to '3'.
Delay the generation of nutrients by adjusting the parameter ["generator"] ["nutrient delay"], then:
You should also be able to observe changes in “leadership” depending on proximity to nutrient sources, as well as all other expected behaviors (disappearance, division, color change, etc.)
| ← Here, the 1 key is used first (green bacteria), followed by the 2 key. The simulation is slowed down, with relatively few nutrients, to allow for better observation of the movement dynamics. Under faster conditions with more nutrients, divisions should be observable, as in the previous video. |
You recently learned that destructors must be virtual when used polymorphically.
Review the existing destructors in your code in light of this advice (if you don’t see the point of this, ask us questions ;-))