Group of classes to determine the players roles and what they need to do according to their roles and the game strategy.
Each player has a role and this depends on each player position. In the Agend2D code, using the basic formation 4-3-3, the roles are:
- 1 Goalie - Goalkeepr
- 2 CenterBack (left)
- 3 CenterBack (right)
- 4 SideBack (left)
- 5 SideBack (right)
- 6 DefensiveHalf
- 7 OffensiveHalf (left)
- 8 OffensiveHalf (right)
- 9 SideForward (left)
- 10 SideForward (right)
- 11 CenterForward
What do you need to implement is only the behavior of each role in a specific situation.
In the Agent2D, each role has only two methods: doKick() and doMove().
bool
RoleCenterBack::execute( PlayerAgent * agent )
{
bool kickable = agent->world().self().isKickable();
if ( agent->world().existKickableTeammate()
&& agent->world().teammatesFromBall().front()->distFromBall()
< agent->world().ball().distFromSelf() )
{
kickable = false;
}
if ( kickable )
{
doKick( agent );
}
else
{
doMove( agent );
}
return true;
}
The method above checks if the player with the ball possession can kick it to the goal and if the teammate distance to the ball is smaller than the player distance. If these two conditions are met, this means that the player can move with the ball. Otherwise, the player needs to pass the ball to the teammate.
Suppose that you want to perform a through pass. To do that, there is the Bhv_ThroughPassKick class which has the through pass implementation. We also want to perform this pass only with midfielder players (role: OffensiveHalf). Then, we need to go to the doKick method in the RoleOffensiveHalf class and check in which BallArea the player can execute this action.
Remember that, before you implement the behavior, you need to understand how the Strategy class works.
For example:
//[...]
switch ( Strategy::get_ball_area( agent->world().ball().pos() ) ) {
case Strategy::BA_OffMidField:
if(Bhv_ThroughPassKick().execute(agent))
break;
// other actions
break;
//[...] case n:
}
The player will only execut the through pass if the ball is in the offensive midfield (BA_OffMidField) and if the Bhv_ThroughPassKick's execute method returns true. That is, if the player can really execute this action. If the ball is in the BA_OffMidField area but the player has no condition of executing the pass through, then another action will be executed.