Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Academic project: simulation of scorpion & mice  (Read 8191 times)

0 Members and 1 Guest are viewing this topic.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Academic project: simulation of scorpion & mice
« on: July 07, 2013, 03:07:00 pm »

Hi!

Today I'm happy to present an academic project we made at EPFL for the School of Life Sciences. In two words, it simulates a population of mice (the preys) and another one of scorpions (the predators) with pretty much a full life cycle: from born to death, with reproduction and predation.

A second part of the simulation consists in building a neuronal network, with sensors & inhibitors, to models the behaviour of a scorpion tracking its preys by sensing the ground's vibrations made by mice. That was the fun (understand: tricky :-) part of the project.

This project was then implemented during the spring semester by more than 180 first-year students in C++ using SFML for the rendering.

Unfortunately, I'm not allowed to distribute the source code. I can only give you a list of features present in this project.

 - The window is divided into two parts. The main one displays the real time simulation of mice and scorpion. We can zoom in / out and move the camera around. The second view can display different kind of statistics: students where asked to keep track of the number of mice, scorpion, food, and so on. For a bonus, they could add, for example, a chart representing the evolution of the different simulated populations.

 - The simulation was held in a toroidal world where animals can only see foods, mates and predators in their eye sight. If an animal sees nothing of interest it will randomly walk until it finds something to eat, mate or to run away from – or starve…

 - Both scorpions and mice have male and female individuals that can mate when they are close enough, not too much hungry, etc… Usually, mice create between 1 and 6 babies whereas scorpion have between 20 and 28 «things» (see gif below).

 - When a scorpion sees a mouse it will try to run toward it and eat it. But if a mouse see the scorpion first (e.g. the scorpion is not coming from behind) it will try to escape and run faster in the opposite direction.

 - Many parameters rule the simulation. We used a simple file format to store every settings in a config file that we can edit in real time during the simulation (modulo pressing `L` to reload the file). These settings include, for example, a debug-mode boolean, a time factor to slow down or speed up the simulation, paths to the different textures used for rendering, energy consumption factors, animals masses, view ranges, … and a lot more!

 - The build system is based on scons and the implementation takes advantage of some new features from C++11 like `auto`, range-based for loops or the random number generators to mention only those three. We didn't used templates or advanced C++(11) features like move semantics because the students are only beginning to code. Moreover, they are not software engineer but life scientist so we can't expect from them to code like pro after less than a year.

 - We provided the students with a few core functionalities like stubs for the core `Application` class that handles event management, updating the logics and drawing (they had to modify it to insert their own environment and all). We also give them a `Vec2d` class to do most of the mathematical operation you can expect from such type, with a nice conversion operator to `sf::Vector2f` to do the interface between their code and SFML API easily. We also gave them a texture manager so they could focus more on the simulation logics (and not on white square).

 - All entities are stored in a heterogenous collection. We used double dispatch to tell if a given entity should be attracted to, eat or feat another entity – so no type test or casting!

Now, enough with this blabla. Here are some screenshots:


A scorpion tracking a mouse:



Mice trying to run away from scorpions:



The birth of scorpions (beurk!):



A slice of simulation:



Generating entities:



A scorpion moved by a «random walk» algorithm until it sees its target:



Debug mode ON – view range, status, collision circle, … are drawn:



Zoom in:



The sensors and neuronal network of a scorpion:



A wave activating a sensor:



A scorpion aware of the mouse:



A peaceful world with only mice and salads!



Higher resolution images can be found at http://sdrv.ms/1aP3KeK



As I said, I cannot show you any piece of code. However, if you have a question on a particular point I probably can give you more-but-not-too-precise-details. ;-)


Btw, it's the first time we use SFML at EPFL for teaching (I kinda pushed toward it because before that we used an ugly, home made, library based on SDL and OpenGL). And next year we will also used SFML for another awesome project! :D

SFML / OS X developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Academic project: simulation of scorpion & mice
« Reply #1 on: July 08, 2013, 03:49:13 pm »
Really interesting, and it's great to see SFML being used at Swiss universities! :D

If I understand it correctly, you (and maybe others) built the fundament that can be used by the first-year students? Sounds tricky, and probably took a lot of time to prepare everything...
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Anteara

  • Newbie
  • *
  • Posts: 40
    • View Profile
    • Email
Re: Academic project: simulation of scorpion & mice
« Reply #2 on: July 08, 2013, 03:59:15 pm »
Looks nice.

It reminds me of my university that uses a game API called SwinGame. It's kind of annoying, since that too, is clunky and after the first semester has ended I've built better projects with SFML by teaching myself with online aids like tutorials etc.

Wish we incorporated SFML as well.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Academic project: simulation of scorpion & mice
« Reply #3 on: July 08, 2013, 07:19:00 pm »
Thanks.  :)

@Nexus, we were two on this project: the other assistant create the biological model of the neuronal network & sensors while I implemented it in C++. Took me between 80 and 100 hours to put everything together. But now that the system is mostly in place we can develop the next projects faster.

@Anteara, I do know that feeling. Fortunately, some teachers are really open minded and things can be changed for future generations.
SFML / OS X developer

ggarreau

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Re: Academic project: simulation of scorpion & mice
« Reply #4 on: October 04, 2013, 08:57:53 am »
Hello,

AS part of my phd i've been working on a neuron model of sand scorpion and i wanted to know if you could link me to any publications/works on the model you used.

regards,

Guillaume

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Academic project: simulation of scorpion & mice
« Reply #5 on: October 04, 2013, 11:23:36 am »
Hi Guillaume,

I replied to your email but got the following error: «unknown or illegal alias: <your email>». If you have another email, I can resend my response to you.
SFML / OS X developer