python模拟足球射门_博客园仿真足球竞赛平台Python版SDK

为了方便喜欢Python的同学能使用Python开发自己的球队,所以编写了此SDK。这个SDK基本上是参照C#版SDK改过来的,除了一些复杂的几何算法没有实现外,其他功能都已实现。喜欢的朋友可以自己下了慢慢改善,我也会不断更新这个SDK。下面介绍一下基本的使用吧。

一、导入soccer模块

不需要过多的import导入语句,轻轻松松,简简单单,只需要一句导入语句:

from soccer import *

二、模块介绍

1. 导入soccer后,我们可以使用如下的一些实例对象:

field_settings#球场设置信息

game_settings#比赛设置信息

rule_settings#规则设置信息

server_settings#服务器设置信息

communicator#通信对象

2. 类对象如下:

Vector2f#二维坐标

GameState#比赛状态(比分信息)

ClientInfo#球队信息(球队名,作者)

命令相关的对象及常量如下:

Command#命令

CommandType_Catch = 'Catch'#扑球

CommandType_Dash = 'Dash'#跑

CommandType_Turn = 'Turn'#转身

CommandType_Stay ='Stay'#原地不动

CommandType_Kick = 'Kick'#踢球

CommandType_Unknow = 'Unknow'#未知命令

所有实现了的类和C#版SDK基本一致,比如Vector2f的操作符重载等。上面列的是主要的一些类和对象,除此之外还包括比如一些角度计算的模块(anglehelper),矩形对象(rectangle) 等。

三、创建球队实例

创建方法和C#版本基本一样,下面的代码应该不需要过多解释:

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[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;

四、下载SDK

五、感谢

感谢 逖靖寒 同学给我们带来了那么好玩的游戏,丰富了我们的生活,带来了很多乐趣。同时希望此Python版SDK能给同学们带来一些帮助,也希望同学们提出宝贵意见,不断的完善这个SDK。谢谢!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值