本文整理汇总了Python中emulator.Emulator.getResults方法的典型用法代码示例。如果您正苦于以下问题:Python Emulator.getResults方法的具体用法?Python Emulator.getResults怎么用?Python Emulator.getResults使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类emulator.Emulator
的用法示例。
在下文中一共展示了Emulator.getResults方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Lifter2
# 需要导入模块: from emulator import Emulator [as 别名]
# 或者: from emulator.Emulator import getResults [as 别名]
class Lifter2():
# TODO: SIGINT handler
def __init__(self,map_file):
self.emu = Emulator(open(map_file, 'r'), '')
self.emu.suppress_prints = True
self.MAX_DEPTH = self.emu.command_limit
self.MAX_LEAVES = 10000000
self.MAX_SCORE = 75.0*self.emu.total_lambdas
print 'MAX DEPTH: ' + str(self.MAX_DEPTH)
print 'MAX LEAVES: ' + str(self.MAX_LEAVES)
print 'MAX SCORE: ' + str(self.MAX_SCORE)
self.best_score = 0.0
self.best_seed = -1
self.best_path = ''
def simSAMC(self,seed):
random.seed = seed
leafs = deque()
node0 = NState(0.0,0,'')
leafs.append(node0)
# use SA to expand branch
while ((len(leafs) > 0) &
(len(leafs) <= self.MAX_LEAVES)):
# pick the node
node = leafs.popleft()
#kT = 1 - node.depth/self.MAX_DEPTH # temprature
#kT = self.MAX_DEPTH - node.depth
kT = (self.MAX_DEPTH - node.depth) * self.MAX_SCORE
if (kT <= 0):
print 'touch bottom: ' + node.cmds
break
# with prob e(score/T) to expand
#energy = 1 - node.score/self.MAX_SCORE
energy = self.MAX_SCORE - node.score
if (random.random() < \
math.exp(-energy/kT)):
#print "to expand: " + \
# node.cmds + \
# '[depth: '+ str(node.depth) + \
# ' score: ' + str(node.score) + \
# ' proba: ' + str(math.exp(-energy/kT)) + ']'
for cmd in VALID_COMMANDS:
if cmd != COMMAND_SHAVE:
cmds = node.cmds + cmd
#print cmds
isdead, isquit, score = \
self.emu.getResults(cmds)
#print isdead
#print isquit
#print score
if not isdead:
if not isquit:
# use MC to cut branch
denergy = \
(score - node.score)
if ((denergy > 0) | \
(random.random() < \
math.exp(denergy/kT))):
#print '\taccept ' + cmd + ' with '\
# + 'proba: ' + \
# str(math.exp(denergy/kT))
newnode = NState(score, \
node.depth+1, \
cmds)
leafs.append(newnode)
else: # end of game
if (self.best_score < score):
self.best_score = score
print cmds + ': ' + str(score)
# ("DDDLLUURDLDL")
def startExplore(self):
# simulate a bunche of rand seeds
random.seed = 100
idx = 0
while 1:
seed = random.randint(1,10000)
print 'SEED: ' + str(seed)
self.simSAMC(seed)
idx = idx + 1
if (idx > 100): break
def endExplore(self):
# produce final results on SIGINT
print "TODO"