ArticleDirectory
- 1. Import the soccer Module
- Ii. Module Introduction
- 3. Create team instances
- 5. Thanks
This SDK was compiled to help students who like python develop their own teams using python. This SDK is basically changed by referring to the C # SDK, except for some complex ryAlgorithmOther functions have been implemented. If you like it, you can improve it by yourself. I will keep updating this SDK. The following describes the basic usage.
1. Import the soccer Module
There is no need for too many import statements. It is easy and simple. You only need one Import Statement:
From Soccer Import *
Ii. Module Introduction
1. After importing soccer, we can use the following instance objects:
Field_settings # Stadium settings
Game_settings # Competition settings
Rule_settings # Rule settings
Server_settings # Server settings
Communicator # Communication object
2. The class object is as follows:
Vector2f # 2D coordinates
Gamestate # Competition status (score Information)
Clientinfo # Team Information (team name, author)
Command-related objects and constants are as follows:
Command # Command
Commandtype_catch = 'Catch' # Fl
Commandtype_dash = 'Dash' # Run
Commandtype_turn = 'Call' # Turning
Commandtype_stay = 'Stay' # Remain unchanged
Commandtype_kick = 'Kick' # Playing football
Commandtype_unknow = 'Unknow' # Unknown commands
All implemented classes are basically the same as the C # SDK, such as vector2f Operator overloading. The above columns mainly contain classes and objects, including anglehelper and rectangle.
3. Create team instances
The creation method is basically the same as that of C #.CodeThere should be no need to explain too much:
If _ Name __ = "_ Main __" :
"""
Entry point of the great team!
"""
Myteam = Teamnancy ( 'Nancyteam' , 'Coderzh' )
If Communicator . Connect ( Myteam . Info ):
Print 'Platform connected !!! '
While True :
"""
Start the game cycle
"""
Wmdata = Communicator . Getworldmodel () # Get the infomation from the server
If ( Wmdata = None ):
Print 'Game over! '
Exit ()
# Get the infomation of the game to my team
Myteam . Getworldmodel ( Wmdata )
# My team think for a while and send the commands to the server
Communicator . Send_commands ( Myteam . Think ())
Else :
Print 'Connect fail !!! '
Let's take a look at how to create a class for your ai team:
Class Teamnancy ( Object ):
Def _ Init __ ( Self , Teamname , Author ):
Self . Info = Clientinfo ( Teamname , Author )
Self . Wm = Worldmodel ()
Self . Cmds = [ Command () For I In Range ( 5 )]
Def Getworldmodel ( Self , Wmdata ):
Self . Wm = Wmdata
Def Think ( Self ):
For I In Range ( Rule_settings . Agentnum ):
Temppos = Self . Wm . Ball . Pos - Self . Wm . Myagents [ I ] . Pos
If Temppos . Getlength () < Rule_settings . Maxkickballdistance :
Self . Cmds [ I ] . Type = Commandtype_kick
Self . Cmds [ I ] . Param1 = 1.0
Self . Cmds [ I ] . Param2 = 0
Elif Math . FABS ( Temppos . Getdirection () - Self . Wm . Myagents [ I ] . Dir ) < 2 :
Self . Cmds [ I ] . Type = Commandtype_dash
Self . Cmds [ I ] . Param1 = Rule_settings . Maxdashvel
Else :
Self . Cmds [ I ] . Type = Commandtype_turn
Self . Cmds [ I ] . Param1 = Temppos . Getdirection ()
Return Self . Cmds ;
4. Download the SDK
Http://files.cnblogs.com/coderzh/SoccerSDK.rar
5. Thanks
I would like to thank Yi Jing Han for bringing us so much fun games, enriching our lives and bringing us a lot of fun. At the same time, I hope this Python version of SDK can help students, and also hope that the students will give valuable suggestions and constantly improve this SDK. Thank you !!