本文整理汇总了Python中gamestate.GameState.parseFlags方法的典型用法代码示例。如果您正苦于以下问题:Python GameState.parseFlags方法的具体用法?Python GameState.parseFlags怎么用?Python GameState.parseFlags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gamestate.GameState
的用法示例。
在下文中一共展示了GameState.parseFlags方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Agent
# 需要导入模块: from gamestate import GameState [as 别名]
# 或者: from gamestate.GameState import parseFlags [as 别名]
class Agent(object):
def __init__(self, name="Marty"):
self.name = name
self.gameState = None
def ingestState(self, data):
""" Ingests the given gamestate from the network.
"""
# ignorant agents might not do anything with the state
if not data:
return
args = struct.unpack('!ffffffB',data)
self.gameState = GameState(args[0],args[1],args[2],args[3],args[4],args[5])
self.gameState.parseFlags(args[6])
def chooseAction(self):
""" Chooses an action, based off of a given game state.
Returned is the bitwise or'ed set of actions.
"""
print "nothing"
pass
示例2: ingestState
# 需要导入模块: from gamestate import GameState [as 别名]
# 或者: from gamestate.GameState import parseFlags [as 别名]
def ingestState(self, data):
args = struct.unpack('!ffffffB',data)
gameState = GameState(args[0],args[1],args[2],args[3],args[4],args[5])
gameState.parseFlags(args[6])
p1damage = self.prevGamestate.p1Health - gameState.p1Health;
p2damage = self.prevGamestate.p2Health - gameState.p2Health;
p1win = gameState.p2Health ==0
p2win = gameState.p1Health ==0
if (p1win):
p2damage = 250
if (p2win):
p1damage = 250
p1damageval = p1damage/100
p2damageval = p2damage/100
reward = -0.01
if (p1damage and (p1damage>0)):#end of game, don't count negative
if (self.p1):
reward -= p1damageval
# self.updateQForStateAction(self.prevGamestate,gameState,self.prevAction,-1*p1damageval)
else:
reward += p1damageval
# self.updateQForStateAction(self.prevGamestate,gameState,self.prevAction,p1damageval)
self.epsilon -= 0.0002
if (p2damage and (p2damage>0)):
if (self.p1):
reward += p2damageval
#self.updateQForStateAction(self.prevGamestate,gameState,self.prevAction,p2damageval)
else:
reward -= p2damageval
#self.updateQForStateAction(self.prevGamestate,gameState,self.prevAction,-1*p2damageval)
self.epsilon -= 0.0002
# Penalize attacking
if (gameState.p1Attacking and self.p1) or \
gameState.p2Attacking and not self.p1:
reward -= 0.01
# Set temporal counter to sparsely track previous states
self.counter += 1
if self.counter % 50 == 0:
# Add state
self.prevStates.insert(0, gameState)
if len(self.prevStates) > 10:
# remove old
self.prevStates.pop()
r = reward
for elem in self.prevStates:
r *= (self.discount * self.discount)
self.updateQForStateAction(self.prevGamestate, elem, self.prevAction, r)
self.updateQForStateAction(self.prevGamestate, gameState, self.prevAction, reward)
self.prevGamestate = gameState
if (self.isTraining):
if (p1win):
self.prevGamestate = GameState(-4,0,100,4,0,100)
if (self.p1):
dumpWeightsToFile('geneticQtableFile.txt') #dump to mutual file
data = bytearray()
data.append(255)
print("sending ipc")
self.ipc_client.sendto(data, (HOST, self.bindport+10)) #let other player know file is ready
else:
data, addr = self.ipc_server.recvfrom(1)
print('retrieved ipc')
retrieveWeightsFromFile('geneticQtableFile.txt')
if (p2win):
self.prevGamestate = GameState(-4,0,100,4,0,100)
if (not self.p1):
dumpWeightsToFile('geneticQtableFile.txt') #dump to mutual file
data = bytearray()
data.append(255)
self.ipc_client.sendto(data, (HOST, self.bindport-10)) #let other player know file is ready
else:
data, addr = self.ipc_server.recvfrom(1)
print('got ipc')
retrieveWeightsFromFile('geneticQtableFile.txt')