本文整理汇总了Python中Data.getBest方法的典型用法代码示例。如果您正苦于以下问题:Python Data.getBest方法的具体用法?Python Data.getBest怎么用?Python Data.getBest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Data
的用法示例。
在下文中一共展示了Data.getBest方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_Data
# 需要导入模块: import Data [as 别名]
# 或者: from Data import getBest [as 别名]
def test_Data(self):
gs = self.gs
t_s = time.time()
t_data_s = time.time()
data = Data(gs)
t_data_e = time.time()
# print data
t_parse_s = time.time()
data.parse(gs)
t_parse_e = time.time()
# print data
print "data diff: %d ms" % (int((t_data_e - t_data_s) * 1000))
print "pars diff: %d ms" % (int((t_parse_e - t_parse_s) * 1000))
bots = []
t_bots_s = time.time()
bots.append(NextBot(data, 30))
# bots.append(SendToNext(data, 5))
# bots.append(RndBot(data, 5))
# ots.append(RndBot(data, 7))
bots.append(RndBot(data, 30))
for bot in bots:
bot.calc()
t_bots_e = time.time()
print "bots diff: %d ms" % (int((t_bots_e - t_bots_s) * 1000))
for bot in bots:
bot.run()
t_e = time.time()
for bot in bots:
s1, s2, s3, r, a, n = bot.get()
print str(s1) + ", " + str(s2) + ", " + str(s3) + ", " + str(a) + ", " + str(n) + "\n"
print "-" * 80
bot = data.getBest(bots)
print bot.get()
bot.correction(data)
print "-" * 80
for i, c in enumerate(data.camps):
if c[C_OWNER] == 1:
print "id: ", i, " ", c[0:5]
print "-" * 80
for i, c in enumerate(bot.camps):
if c[C_OWNER] == 1:
print "id: ", i, " ", c[0:5]
print "all diff: %d ms" % (int((t_e - t_s) * 1000))
示例2: AfrankBot2
# 需要导入模块: import Data [as 别名]
# 或者: from Data import getBest [as 别名]
class AfrankBot2(IBot):
def __init__(self):
self.debug=True
self.data=None
if self.debug:
self.log=open('/tmp/bot.log', 'a')
else:
self.log=None
self.round=-1
def logme(self, msg):
if self.debug:
self.log.write(msg)
self.log.flush()
def doTurn(self, gamestate):
self.round=self.round+1
self.logme("start round %d\n"%self.round)
t1 = time.time()
# first step, init data
if self.data==None:
self.data = Data(gamestate)
self.data.parse(gamestate)
self.logme("data parsed\n")
# set alle bots
bots=[]
#bots.append(DoNothing(self.data, 0))
for x in [9,14,19,24,29]: #2,5,10,15,20,30, 50]:
bots.append(NextBot(self.data, x))
bots.append(RndBot(self.data, x))
bots.append(SendToNext(self.data, x))
bots.append(AttackNeutral(self.data, x))
self.logme("bots setted\n")
#self.logme("botslen: %d\n"%(len(bots)))
for bot in bots:
#self.logme(bot.getName()+"\n")
bot.calc()
t1a = time.time()
for bot in bots:
#print s
bot.run()
t1b = time.time()
self.logme("simulat ok, get best\n")
for bot in bots:
s1,s2,s3,r,a,n=bot.get()
self.logme(str(n)+": "+ str(s1)+", "+str(s2)+", "+str(s3)+", "+str(a)+"\n")
bot = self.data.getBest(bots)
if bot==None:
self.logme("##################################")
self.logme("bot was None !!!!!!!!!!!!")
self.logme("##################################")
bot=bots[0]
bot.correction(self.data)
armies = bot.get()[4]
self.logme("-----------------------------------------------------------------------\n")
self.logme("best: "+str(armies)+"\n")
t2=time.time() ####################
self.logme("send armies to gamestate\n")
for a in armies:
gamestate.issueOrder(gamestate.getCamp(a[A_SRC]), gamestate.getCamp(a[A_DST]), a[A_CNT])
t3=time.time()
d1=(t2-t1)*1000
d2=(t3-t2)*1000
dall=(t3-t1)*1000
self.logme(">>>>> t %d: %d ms %d ms [%d] ms<<<<<<\n"%(self.round, int(d1), int(d2), int(dall)))
def getName(self):
return "AfrankBot2"