Blog park simulation football competition platform Python SDK

Source: Internet
Author: User
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 !!

Related Article

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.