Project 2024-25:
Simulation of a "predator-prey" model
Prey detection by vibration
Disclaimer: the automatically generated English translation is provided only for convenience and it may contain wording flaws. The original French document must be taken as reference!
Through this project, you will learn to create a complete program that is larger in scope than those you have worked with until now. Your program will also include a graphical component. From a computer science perspective, this project aims to strengthen your programming knowledge and help you practice the essential concepts of object-oriented programming: abstraction and encapsulation, inheritance, virtual methods, and polymorphism.
It is not recommended to print the entire project statement: additional information may be added along the way.Introduction
Every program must be designed before being implemented. This design phase aims to establish a computer modeling of the program's components and involves asking a number of questions:- What information does the program need and what are the relationships between this different information?
- What transformations will this information undergo?
- Who will have to decide, and based on which parameters, when these transformations will be applied?
- etc
The explanation below aims to outline in very broad terms the design we will propose for you to adhere to for this project.
First steps towards program design
When the program is launched, a window should open and display the macroscopic view of the simulation (the population-scale simulation). It will be possible using keyboard keys to view this environment at various scales or different locations:
![]() |
← Population-scale simulation → Here zoomed in on a part of the world |
![]() |
We can suspect that each of these elements on the screen will need to have a C++ equivalent in your code.
By using control keys, you will be able to switch to "individual scale simulation" mode. At this scale, you can more closely observe the mechanisms of predation in the scorpion. The window will then display only one scorpion, and you can create a lizard to observe how the scorpion approaches it.
Before reaching this stage, we will use a relatively abstract visualization of the scorpion, where it will be possible to observe its sensors, neurons and the waves it perceives.

When designing the program, you must not only identify the elements to be modeled, but also ask yourself a number of questions such as:
- how do the elements involved in the simulation interact with each other?
- do they have things in common, or are they completely independent?
- etc...
We outline for you below the fundamental elements that will be involved in the program to be implemented.
Basic Objects
Given the preceding description, the following classes seem to immediately impose their presence:
- a class to represent the environment to be simulated: it will list the animals present and the available food sources;
- another one for the animals of course, without whom nothing would happen :-)
- a class to represent food sources;
- classes to represent neurons, waves and other sensors.
More specifically, it will quickly become apparent that there are elements common to all animals, such as the fact that they have a position in the world, a movement speed, a gender, etc. There will also be (more or less) obvious differences such as how they feed.
We can therefore imagine a base class Animal to specify the characteristics and methods common to all inhabitants of the world. We will then need to specialize this base class (inheritance concept), to characterize attributes and methods specific to lizards and scorpions etc.
To summarize, we can thus anticipate the different elements involved in the simulation and gradually propose a possible design for the program. As you progress through the project, you will find detailed diagrams explaining the program architecture that we suggest you adhere to. It is essential to understand it in order to implement it correctly. It is obvious that other solutions, whether simpler, more complex, or simply different, exist. Each (simple or complex) generally has its advantages and disadvantages. However, the modeling we propose is reasonable, and following it will save you time.
Simulation Core and Graphical Displays
To perform the simulation, we will evolve the components of the program over time (the fauna, flora etc.).Time is sampled (we will talk about discrete time steps). At each time step, each animal, for example, may undergo or initiate a certain number of events depending on the context (feeding, avoiding an obstacle, etc.). These actions determine the evolution of the system over time. Of course, the components will need to be re-displayed after each event to effectively visualize the evolution of the system.
The system elements will therefore generally have:
- content (the data and methods for modeling them);
- a graphical representation (our way of displaying them);
- a behavior (the actions taken according to the context or how they should react to possible external events.
The project statement guidelines will help you achieve a design that moves in this direction.
The simulation core, which will evolve the world over time and take into account potential user interventions, will be provided. This core will allow:
- start the simulation;
- communicate possible user interventions to the program (for example, their wish to stop the simulation);
- and especially call "repeatedly" the methods necessary for running the simulation. One of your essential tasks in this project will be to provide these methods.
Graphic library
There is no standard library in C++ for defining graphical interfaces. Each of the existing libraries therefore has its own specificities (features, prototypes, etc).Among the possibilities:
- SDL
- wxWidgets
- Qt
- SFML (version 2.5 is installed on EPFL machines, but using version 2.6 will make no difference for our purposes)
It is this last option that we have chosen for its ease of use. It will provide you with the necessary features for graphics and event management in your program.
Registration
If you haven't registered yet, please before Monday March 17 at 9 a.m!
Steps
Create a project subdirectory in the ~/myfiles/cpp. All files relating to this project must be in the directory ~/myfiles/cpp/project.A schedule of the various stages is given in the description description. In addition, below you'll find tips on which classes to implement and how. We recommend recommended to follow these guidelines, but you can of course add or modify any elements you wish to customize your program.
The project is
designed to be made
by two. So share the work
the work as soon as you start to feel
comfortable with the subject.
Parallel and complementary
is certainly an instructive
instructive experience, but obviously requires good communication
communication between you to be effective.
Throughout the development process, you can check your program using small test programs. There are two ways of debugging your program possibilities (which are often used in conjunction with each other):
- use cost (or, much better, cerr) to identify where the program "crashes", as well as the the value of attributes at that point
- use "debuggeris indispensable for certain types of error.
Important: The statement provided is quite but will not necessarily not necessarily all indications. You should therefore supplement what you are given with a little personal investigation. The assistants - in particular your coach - are there to help are there to help you. It is also possible that additional may be provided along the way if necessary.
The necessary archives are supplied as and when required as they become necessary.
Don't forget comment your code and code cleanly. A part of the final score. What's more, it will make it easier when you have to re-read your code after several weeks.
Step 1: Utility class (warm-up)
Purpose: Implement a base class for modeling abstract entities that can be positioned and moved in a toric world.
Concepts concepts: classes, encapsulation, constructors, destructors and operator overloading
These concepts are explained in course 16, 17 & 18.Expected duration of coding : 1 week of supervised practical work (from Tuesday of week 5 included, to Tuesday of week 6 not included, according to the numbering of the course outline)
Click here to to access the statement for this part.
Step 2: Random walk
Aim: Implement abstract animals able to move randomly in their environment and move towards targets.
Concepts necessary: classes classes, constructors/destructors, operator overloading and inheritance
These concepts are explained in courses 16, 17, 18 & 19.Expected duration of coding2 weeks of practical work (from Tuesday of week 6 inclusive to Tuesday of week 8 exclusive, according to the numbering of the course outline) course outline)
Click here to to access the statement for this part.
Stage 3: Life cycles
Purpose: Simulate the complete life cycle of lizards and scorpions (food consumption, reproduction, predation, escape and death).
At the end of this stage, all the functionalities required to simulate population dynamics will be implemented.
Concepts necessary: classes classes, constructors/destructors, inheritance and polymorphism.
These concepts are explained in courses 16, 17, 18, 19 & 20.Expected duration of coding2 weeks of supervised practical work (from Tuesday of week 8 inclusive, to Tuesday of week 10 exclusive, according to the numbering of the course outline)
Click here to to access the statement for this part.
Step 4: Neural model of the scorpion
Concepts concepts: classes, constructors/destructors, inheritance and polymorphism
These concepts are explained in courses 16, 17, 18, 19, 20 & 21.Expected duration of coding2 weeks of supervised practical work (from Tuesday of week 10 inclusive to Tuesday of week 12 exclusive, according to the numbering of the course outline) course outline.
Click here to to access the statement for this part.
Step 5: Statistics
Concepts necessary: classes, constructors/destructors, inheritance and polymorphism
These concepts are explained in courses 16, 17, 18, 19, 20 & 21.Expected coding time1 week of supervised practical work (from Tuesday of week 12 inclusive to Tuesday of week 13 exclusive, according to the numbering of the course outline) course outline.
Click here to to access the statement for this part.
Step 6: Free extensions
Concepts concepts: classes, constructors/destructors, inheritance and polymorphism
These concepts are explained in courses 16, 17, 18, 19, 20 & 21.Expected coding time1 week of supervised practical work (from Tuesday of week 11 inclusive to Tuesday of week 13 exclusive, according to the numbering of the course outline) course outline.
Click here to to access the statement for this part.
A few references
Some common C++ style recommendations (style recommendations)
You you'll also find references on the C++ language here.

