Simple implementation of the overall strategy for simulating football teams

Source: Internet
Author: User

In the previous article, we have achieved the fastest ball capture based on the CSHARP team template. In this articleArticleWe will take this teamCodeAnd add some simple policies to them to make them a more complete example.

 

First, we need to implement a universal playing function. Through this function, we can combine the team's leading ball, passing ball, and shooting strategy. Here, I have defined a function to play football at a specified position within a specified cycle.

 

The principle of the function is as follows:

      1. Determine the speed at which a football player should be able to exercise at the specified position within the specified cycle.
      2. Obtain the two parameter values of the kick command, so that the ball can have the speed obtained in the previous step.
      3. After finding the two parameters of the kick command, let's determine whether they comply with our platform's restrictions:
      4. If not, it means that the football cannot reach the specified position within the specified period X. Let X + 1 repeat Step 1. If x> 100, the result cannot be returned.
      5. If yes, a kick command has been found to kick the ball to the specified position within x cycle.

The actual implementation in the code is in demoteamcsharp. Agent. kick2point.

 

With this function, I will introduce two simple strategies:

Pass policy:

      1. If you are a goalkeeper (Player 1), randomly select a player from PLAYER 2 to Player 5, and then execute the command to bring the ball to the position of the selected player.
      2. If you are not a goalkeeper, this randomly selects a player (not yourself) from PLAYER 2 to Player 5 and then executes the command to bring the ball to the position of the selected player.

Shot policy:

Test the marked red points separately. If a player can kick the ball to that point within 12 cycles, the point is the point where the shot can be successful.

Code implementation:

 
// List the shooting points that can be scored
For(IntI = 1; I <fieldsettings. instance. fielddoory2-fieldsettings. instance. fielddoory1; I ++)
 
{
Vector2f shootpoint =NewVector2f (fieldsettings. instance. fieldlength, I + fieldsettings. instance. fielddoory1 );
 
 
 
// Determine whether a goal can be scored.
Kick2pointresult res = agent. kick2point (WM. Ball, shootpoint, 1 );
 
If(Res. Success & res. needcycle <12)
 
{
// Fine the shoot point.
 
ReturnShootpoint;
 
}

}

 

Of course, it is not possible to pass a pass or take a shot, and our players still need to run a position. Otherwise, they will always be silly to stand in a place and won't be moved ;(

Next, I will introduce two simple running places:

Attack position:

We use the fixed-point running method:

When the goalkeeper takes the ball, the positions of the remaining four players are fixed and they will respectively run to the positions specified beforehand:

Not when the goalkeeper takes the ball, the players who take the ball decide whether to pass the ball or take a shot. The players who do not take the ball will run to the specified position beforehand:

Defensive position:

The principle of implementing the defensive position is to let players from 2 to 5 run to the positions of the corresponding number Team of the opponent. For example, if we defend the opponent on the 2nd and the opponent on the 3rd, we guard the opponent on the 3rd and so on.

 

Finally, based on the above four strategies, we have achieved an overall team decision-making process:

 
Interceptstruct = predictor. predictfastestinterceptball (_ WM );
 
 
If(Interceptstruct. Own)// We are under attack
 
{
If(Predictor. predictagentcankickball (_ WM. ownagents [interceptstruct. Num], _ WM. Ball. Pos ))// Ball control
 
{
 
Vector2f shootpoint = _ coach. getshootpoint (_ WM, interceptstruct. Num );
If(Shootpoint! = Vector2f. notexist)// Shot
 
{
_ Commands [interceptstruct. Num] = _ WM. ownagents [interceptstruct. Num]. kick2point (_ WM. Ball, shootpoint, 1). kickcommand;
 
}
 
Else// Pass
{
 
Vector2f passpoint = _ coach. getpasspoint (_ WM, interceptstruct. Num );
 
_ Commands [interceptstruct. Num] = _ WM. ownagents [interceptstruct. Num]. kick2point (_ WM. Ball, passpoint, 3). kickcommand;
}
 
}
 
Else// Get the ball
{
 
_ Commands [interceptstruct. Num] = _ WM. ownagents [interceptstruct. Num]. dash2point (interceptstruct. ballpos,True);
 
}
 
 
// Non-ball players conduct attacking and running positions
 
For(IntNum = 1; num <_ WM. ownagents. length; num ++)
{
 
If(Num! = Interceptstruct. Num)
 
{
_ Commands [num] = _ WM. ownagents [num]. dash2point (_ coach. getattackpos (_ WM, num ),False);
 
}
 
}
}
 
Else// We are in the defensive status
 
{
For(IntNum = 1; num <_ WM. ownagents. length; num ++)
 
{
_ Commands [num] = _ WM. ownagents [num]. dash2point (_ coach. getdefencepos (_ WM, num ),False);
 
}
 
}

 

You can view the implementation results and code by downloading the code of the CSHARP sample team.

 

Next, I will release an updated blog park simulation football competition platform, and publish the source code of the platform physicalmodel. dll, engine. dll and utility. dll.

 

Blog park simulation football exchange team

Download related resources

Related Articles

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.