12.4 Assigning Different Tasks (UNUM)

For the previous examples we did not differentiate between the individual agents. This meant that since each agent(individual robots) is running the same code they will exhibit the same behaviour. We saw this as both agents would run towards the ball disregarding the other. Now in any team sport coordination and teamwork is critical therefore this behaviour is less than ideal. In this example we will demonstrate how different orders can be assigned to each agent based on their unique identifier, which is their uNum. This is unique identifier that can be used to issue unique tasks through the use of humble if statement. uNum is defined in worldmodel.h, which stores all the information pertaining the current state of the game and all the agents in it. We use the prebuilt method getUNum() which is also defined in worldmodel.h to get the current agents uNum. By current agent we are referring to the actual agent who is executing this code. So since each agent executes a copy of the same code each agent will return their own uNum to themselves. Therefore to get the player-number we use the following statement:

int _playerNumber = worldModel->getUNum(); // returns this agents player number

Since getUNum() is a member method of worldmodel.h we need to instantiate a WorldModel object, thankfully this is already done for use and it is called worldModel. Therefore to call the getUNum() from inside selectSkill() we use worldModel->getUNum(). We then assign it to a local variable of type int called _playerNumber


With the _playerNumber we can now use an if statement to specify seperate task for the player with uNum equal to 1 and all the other players will just stand still. This is achieved will the following code:

if(_playerNumber ==1){
        return kickBall(KICK_FORWARD, VecPosition(HALF_FIELD_X, 0, 0)); // Basic kick
    }
    else{
        return(SKILL_STAND);
    }

Here if(_playerNumber ==1) then the agent will kick the ball to the opponents goal as previously described. Otherwise, the agent will simply stand still and this is achieved by returning SKILL_STAND which is of type SkillType. This is a special predefined Skill which when returned tells the agent to stand in place.


Now when we make our project and execute the code for two or more agents the behaviour demostrated will be where 1 agent goes for the ball and all others remain inplace.


This serves a very simplistic demonstration on how different tasks can be given to different agents. Another approach could be add an additional variable which indicates a “playertype”. For example Defenders, Forwards or MidFielders. However, this requires additional implementation and initialisation of the world model.