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!!!'
再来看看如何创建自己的AI球队的类:
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.pos
if temppos.getlength() < rule_settings.MaxKickBallDistance:
self.cmds.type = CommandType_Kick
self.cmds.param1 = 1.0
self.cmds.param2 = 0
elif math.fabs(temppos.getdirection() - self.wm.MyAgents.dir) < 2:
self.cmds.type = CommandType_Dash
self.cmds.param1 = rule_settings.MaxDashVel
else:
self.cmds.type = CommandType_Turn
self.cmds.param1 = temppos.getdirection()
return self.cmds; 四、下载SDK
http://files.iyunv.com/coderzh/SoccerSDK.rar 五、感谢
感谢 逖靖寒 同学给我们带来了那么好玩的游戏,丰富了我们的生活,带来了很多乐趣。同时希望此Python版SDK能给同学们带来一些帮助,也希望同学们提出宝贵意见,不断的完善这个SDK。谢谢!!