APICe » Courses » Autonomous Systems » 2014/2015 » Projects » MAS Hunting

MAS Hunting


  • Francesco Degli Angeli


In the following report will be presented the process development of the game MAS Hunting for the course of Autonomous Systems.

The game is a simulation of a hunt in a forest that will be recreated through a natural-inspired MAS composed of several animal-agents and a hunter-agent. So the relevant aspects are: the autonomy of components, the self-organisation, the ability of evolution of the agent in the environment and the non linear dynamics.


MAS Hunting is inspired by the predator–prey model that wants to study the dynamics of two rival species. At the base of the model is the simple concept that to survive the predator has to eat the prey. So the transfer of energy represents the interaction between the two populations and the system may evolve either to overpopulation, extinction or periodical evolution.

These dynamics have been encoded for the first time in the Lotka-Volterra equation ( http://en.wikipedia.org/wiki/Lotka%E2%80%93Volterra_equation ).

The Game

MAS Hunting is a single-player game. The player can control a hunter in a forest where there are also prey and predators.

The goal of the game is prevent the extinction of the prey and survive for a time limit by killing the hungry predators. Let's move on to describe the main aspects of the game.

First of all the forest (environment) is a two-dimensional grid cells and the movements (and trajectory of the shots of the hunter) can be diagonal, vertical or horizontal. An animal, prey or predator, has a vital energy and can perform one of this three actions: move, eat, reproduce. Each movement costs energy to the animal as long as it becomes hungry and needs to feed.

The prey move until they run out of energy and at that point they stop in a cell to eat grass as long as they are filled. The reproduction happens if two prey are in the same cell and are not hungry; it costs half energy at the parents. A prey dies if it's eaten by a hungry predator.

The predators move randomly until they become hungry and dangerous. When a predator is hungry and is about to move, it checks if there is a prey in the eight surrounding cells and move to it. In fact the hungry predators can only eat a prey that is in their own cell. Attention because if the hungry predators do not find a prey can also bite the hunter. The reproduction of predators has the same dynamics of the prey. At last a predator dies if it runs out of vital energy or if it's hit by an hunter's bullet.

The hunter has three lives and can move, shoot to kill the hungry predators and have to load the rifle once the cartridges are over. If he's bitten three times by a hungry predator, the hunter dies and the game is over.

At the end of the game, if the hunter and at least a prey are alive, points are awarded as follows: three points for every hungry predator killed, five points for each prey remained alive and ten points for each hunter's life remained.


Design and build a software prototype of the game MAS Hunting described in the previous section.



FORESTEnvironment of the system modelled as a two-dimensional grid cells in which the other entities are situated
PREYAutonomous and active entity that moves, eats and reproduces
PREDATORAutonomous and active entity that moves, eats the prey (or bites the hunter) and reproduces
HUNTERAutonomous (or controlled by the player) and active entity that can moves and shoot bullets
BULLETAutonomous and active entity created by the hunter who can kill the hungry predators

At this stage, we need to choose a modelling technique for the prototype of this game and the most suitable is the ABM (Agent-Based Model): it captures the emergent phenomena, provides a natural description of the system, makes the model seem closer to reality and is flexible (agents can be erased or new agents can enter in the scenario).

In this model the system is described as a collection of entities (called Agents) capable of making their own decisions. Each agent analyses the surrounding environment, its internal state and makes actions based to a set of rules to satisfy its goals. Now through a top-down approach we define the entities of the system as Agent and how they interact each other in a MAS (Multi-Agent System).

The modelling of the Agents has been addressed in three major stages:

  1. Modelling in writing of the Agents, focusing on recognition of fundamental behaviours
  2. Creation of statechart
  3. Construction of the agent using a software program
PREYMove randomly in the Forest.
Check to see if you’re out of energy and become hungry (you must eat grass).
Check to see if you should reproduce (do you have enough energy to have an offspring).
PREDATORMove randomly in the Forest.
Check to see if you become hungry (you must find and eat a prey or bit the hunter).
Check to see if you should reproduce (do you have enough energy to have an offspring).
Check to see if you’re out of energy (die).
HUNTERMove in the Forest trying to stay away from predators.
Check to see if there is a hungry predator and shoots to the nearest.
Check to see if the cartridges are over and load the rifle.
BULLETMove along the trajectory of the shot in the Forest.
Check to see if there is a hungry predator to hit and kill him (then die).
Check to see if you’re out of energy (die).

Interaction between agents

The following UML Sequence Diagram (with some abuse of notation) provides a simplification of the interactions between agents: agentinteraction.png

Interaction with the Environment

PREYCheck if there is another prey in the same cell for reproduction. (not hungry)
PREDATORCheck if there is another predator in the same cell for reproduction. (not hungry)
Check if there are prey or the hunter in the eight surrounding cells to attack. (hungry)
Check if there is a prey in the same cell to eat. (hungry)
Check if there is the hunter in the same cell to bit. (hungry)
HUNTERCheck if there are predators in the eight surrounding cells to get away.
Check if there is a hungry predator to shoot or if there are more to choose the nearest.
BULLETCheck if there is a hungry predator in the four surrounding cells to kill.

Prey Agent and Predator Agent Statecharts

preyagent.png predatoragent.png

Hunter Agent and Bullet Agent Statecharts


Abstraction gap

In this part we want to fill up the gap between the model and the technology implementation.

We have to choose an agent-based tool-kit that allows us to have:

  • a flexible environment to dynamically add (reproduction prey and predators, bullet's hunter) and remove agents (prey eaten by the predator, predator hit by a bullet)
  • possibly based on grid environment in which the agent can move and interact
  • not extremely complex because we want to quickly build a prototype
For the reasons listed above our choice fell on NetLogo.

NetLogo is a programmable modelling grid environment for simulating natural and social phenomena. It is particularly well suited for modelling complex systems developing over time. Modelers can give instructions to hundreds or thousands of Agents all operating independently; in fact the behaviour of a class of Agents is determined by a set of rules. This makes it possible to explore the connection between the micro-level behaviour of individuals and the macro-level patterns that emerge from their interaction.


For implementing a model in NetLogo we have to work on three tabs:

  • Interface: The Interface is the main tab where you interact with your model and see your agents behaviour and visualize data. It can contain buttons, slider bars, switches, monitor boxes, and plots in addition to the environment the agents live in (the larger black window).
  • Info: The Info tab simply contains textual information for the user on how to best understand and use the model.
  • Code: The Code tab is a textual environment that contains the code that defines the rules which determine the behavior and attributes of the agents in the model.
First in the settings of the model we set up the environment as a two-dimensional grid of 15 x 15 cells that will represent the Forest.

Now let's move to our agents. In NetLogo there are two types of agents: the mobile agents called turtles and the stationary/background agents known as patches. Since we have four types of mobile agents we use the breeds keyword to identify the breeds of turtles in the model and we also specify attributes associated through the use of breed-name -own declaration:

breed [prey a-prey]                     
breed [predators predator]
breed[hunters hunter]
breed[bullets bullet]
prey-own [energy hungry eat_time]        
predators-own[energy hungry]            
hunters-own[target vision cartridges charge_time ready_to_shoot]

  • prey have a vital energy, a variable to indicate if they are hungry and a variable that indicates the time the time taken to eat grass (eat_time).
  • predators have a vital energy and a variable to indicate if they are hungry (red color).
  • the hunter has: a variable that indicates the nearest hungry predator to shoot (target); a variable that indicates the the number of patches in which the hunter can see a hungry predator (vision);a variable that indicates the number of shots remained (cartridges); a variable that indicates the time taken to load the rifle (charge_time); a variable that indicates if the hunter can shoot or not (ready_to_shoot).
  • The bullets have a a variable that indicates the maximum range of the shoot (energy).
The complete implementation of the behavior of the agents is commented in the Code tab of the model.


How to Run

MAS Hunting is downloadable from the Attachments section (MASHunting.nlogo).

To play the game you have to open the model with NetLogo 5.1.0. The commands are explained in the Info tab (section HOW TO USE IT).