本文整理汇总了Python中state.State.update方法的典型用法代码示例。如果您正苦于以下问题:Python State.update方法的具体用法?Python State.update怎么用?Python State.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类state.State
的用法示例。
在下文中一共展示了State.update方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Game
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import update [as 别名]
class Game():
def __init__(self, gru_file=None):
self.compiler = Compiler()
if gru_file:
self.stream = self.compiler.decompile(gru_file)
else:
self.stream = self.compiler.compile(None)
self.metadata = self.stream.metadata
self.flags = Flags(self.stream)
self.wheel = Wheel(config)
self.title = Title(config)
self.inventory = Inventory(self.stream, self.flags, config)
self.combiner = Combiner(self.stream, self.flags, self.inventory)
self.page = Page(config, self.flags, self.combiner, self.inventory)
self.state = State(self.stream, self.flags, self.inventory, self.wheel, self.combiner, self.title, self.page)
if self.metadata.has_key("start"):
start = self.metadata["start"]
self.state.update(start)
else:
self.state.update("start")
def draw(self, tick):
self.inventory.draw()
self.wheel.draw()
self.title.draw()
self.page.draw(tick)
示例2: update
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import update [as 别名]
def update(self):
self._sword.y_index = self._sword_top_index + self._current_choice
State.update(self)
for shape in self._shapes:
shape.update()
self._sprites.update()
return
示例3: update
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import update [as 别名]
def update(self):
State.update(self)
if self.child_state:
self.child_state.update()
self.dirty_list += self.child_state.dirty_list
self.child_state.dirty_list = []
if not self.refresh_screen:
self.refresh_screen = self.child_state.refresh_screen
self.child_state.refresh_screen = False
return
示例4: update
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import update [as 别名]
def update(self, dt):
State.update(self, dt)
#Updates the game objects
self.player.update(dt)
#self.invader.update(dt)
self.invader_manager.update(dt)
#treats projectiles hits
self._treat_invader_projectiles()
self._treat_player_projectiles()
示例5: update
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import update [as 别名]
def update(self):
State.update(self)
if self.child_state:
self.child_state.update()
self.dirty_list += self.child_state.dirty_list
self.child_state.dirty_list = []
if not self.refresh_screen:
self.refresh_screen = self.child_state.refresh_screen
self.child_state.refresh_screen = False
if self.old_child_state is None or self.old_child_state != self.child_state:
self.refresh_screen = True
self.old_child_state = self.child_state
return
示例6: update
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import update [as 别名]
def update(self, dt):
if self.game_started == True:
if self.players_list.__len__() > 0:
State.update(self, dt)
#Updates the game objects
for player in self.players_list:
player.update(dt)
#self.invader.update(dt)
self.invader_manager.update(dt)
self.check_if_Invaders_Changed_Direction()
#treats projectiles hits
self._treat_invader_projectiles()
self._treat_players_projectiles()
示例7: Hardware
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import update [as 别名]
hardware = Hardware("../test/live.txt")
# /dev/tty.HC-06-DevB
#
# hardware = Hardware(serial_port='/dev/rfcomm0', output_file='../test/live.txt')
# , testfile='../test/live.txt'
state = State(n_particles=150)
sumdeltas = 0
current_time = 0
start = time.time()
i = 0
for update in hardware.updates():
i += 1
start_time = time.time()
state.update(update)
stop_time = time.time()
current_time += update.timedelta
timedeltadelta = update.timedelta - (stop_time - start_time) * 1000
sumdeltas += timedeltadelta
if timedeltadelta < 0:
#print("Slower than updates: %f, current delay %f" % (timedeltadelta, sumdeltas))
None
else:
#print("Faster than updates: %f, current delay %f" % (timedeltadelta, sumdeltas))
None
if i % 250:
with open("gridworld.pkl", "wb") as f:
best_particle = state.best_particle()
示例8: __init__
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import update [as 别名]
class Component:
"""
Abstract class defining methods inherited by all CliMT components.
"""
def __init__(self, **kwargs):
# Initialize self.Fixed (subset of self.Prognostic which will NOT be time-marched)
if 'Fixed' in kwargs: self.Fixed = kwargs.pop('Fixed')
else: self.Fixed = []
# Initialize I/O
self.Io = IO(self, **kwargs)
# Get values from restart file, if available
if 'RestartFile' in kwargs:
ParamNames = Parameters().value.keys()
FieldNames = self.Required
kwargs = self.Io.readRestart(FieldNames, ParamNames, kwargs)
# Initialize scalar parameters
self.Params = Parameters(**kwargs)
# Frequency with which compute() will be executed
if 'UpdateFreq' in kwargs:
self.UpdateFreq = kwargs.pop('UpdateFreq')
else:
self.UpdateFreq = self.Params['dt']
# Initialize State
self.State = State(self, **kwargs)
self.Grid = self.State.Grid
# Dictionary to hold increments on prognos fields
self.Inc = {}
# Initialize diagnostics
self.compute(ForcedCompute=True)
# Create output file
self.Io.createOutputFile(self.State, self.Params.value)
# Write out initial state
if not self.Io.Appending: self.write()
# Initialize plotting facilities
self.Plot = Plot()
# Initialize runtime monitor
self.Monitor = Monitor(self,**kwargs)
# Notify user of unused input quantities
self._checkUnused(kwargs)
# Set some redundant attributes (mainly for backward compatibility)
self.nlon = self.Grid['nlon']
self.nlat = self.Grid['nlat']
self.nlev = self.Grid['nlev']
try: self.o3 = self.State['o3']
except: pass
def compute(self, ForcedCompute=False):
"""
Updates component's diagnostics and increments
"""
# See if it's time for an update; if not, skip rest
if not ForcedCompute:
freq = self.UpdateFreq
time = self.State.ElapsedTime
if int(time/freq) == int((time-self['dt'])/freq): return
# Set up union of State, Grid and Params
Input = {}
for dic in [self.State.Now, self.Grid.value, self.Params.value]: Input.update(dic)
Input['UpdateFreq'] = self.UpdateFreq
# For implicit time stepping, replace current time level with previous (old) time level
if self.SteppingScheme == 'implicit': Input.update(self.State.Old)
# For semimplicit time stepping, append previous (old) time level to Input dict
if self.SteppingScheme == 'semi-implicit':
for key in self.Prognostic: Input[key+'old'] = self.State.Old[key]
# List of arguments to be passed to extension
args = [ Input[key] for key in self.ToExtension ]
# Call extension and build dictionary of ouputs
OutputValues = self.driver(*args)
if len(self.FromExtension) == 1: Output = {self.FromExtension[0]: OutputValues}
else: Output = dict( zip(self.FromExtension, OutputValues ) )
# Extract increments from Output
for key in self.Prognostic:
self.Inc[key] = Output.pop(key+'inc')
# Remove increments of Fixed variables
for key in self.Fixed:
if key in self.Inc: self.Inc.pop(key)
if key in Output: Output.pop(key)
# Update State
#.........这里部分代码省略.........
示例9: Simulator
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import update [as 别名]
class Simulator(object):
def __init__(self ,progs, visualizer,gwidth = 90, glength = 120 , gfriction = 1):
self.cycle = Cycle()
self.ground = Ground(glength , gwidth ,gfriction )
self.players =[]
for i in range(2):
for j in range(5):
self.players.append(Player(self.ground, progs[i] , i , j , Vector( ((1.0*indexi[j]) * (gwidth / 2)) , (1.0*indexj[j]) * (glength / 2) * ((-1) ** (i)) ) ))
#print >>sys.stderr, 'PLAYER %d, %d: %f, %f'%(i, j, self.players[j].pos.x, self.players[j].pos.y)
#print >>sys.stderr, 'PLAYER %d, %d: %f, %f'%(i, j, indexi[j] * gwidth / 2, indexj[j] * glength / 2 * (-1) ** (i))
self.ball = Ball(self.ground)
self.state = State(self.players , self.ball)
self.referee = Referee(self.state)
self.visualizer = visualizer
def send_data(self):
for i in range(10):
self.visualizer.stdin.write(`int(self.state.players[i].pos.x)`+'\n')
self.visualizer.stdin.write(`int(self.state.players[i].pos.y)`+'\n')
#print >>sys.stderr, 'THIS IS RS, PLAYER %d: %d, %d'%(i, int(self.state.players[i].pos.x), int(self.state.players[i].pos.y))
self.visualizer.stdin.write(`int(self.state.ball.pos.x)`+'\n')
self.visualizer.stdin.write(`int(self.state.ball.pos.y)`+'\n')
self.visualizer.stdin.write(`self.state.game_state `+'\n')
#def player_move(self, i , coefficient=1.0/100):
# self.players[i].move(coefficient)
def ball_move(self , coefficient=1.0/100):
self.ball.move(coefficient)
width = self.ground.width
length = self.ground.length
while True:
x = self.ball.pos.x
y = self.ball.pos.y
if x <= width/2 and x >= -width/2 and y <= length/2 and y >= -length/2:
break
#print >>sys.stderr, 'BALL IS OUTSIDE GROUND, VELOCITY IS: %f, %f'%(self.ball.vel.x, self.ball.vel.y)
if x>(width/2) :
self.ball.vel.x= -self.ball.vel.x
self.ball.pos.x= width-x
#print >>sys.stderr, 'THE BALL WENT TOO RIGHT, NEW X: %f'%(self.ball.pos.x)
if x<-(width/2) :
self.ball.vel.x= -self.ball.vel.x
self.ball.pos.x= -width-x
#print >>sys.stderr, 'THE BALL WENT TOO LEFT, NEW X: %f'%(self.ball.pos.x)
if y>(length/2) :
self.state.update( self.referee.is_goal(self.ball , self.ground) )
self.ball.vel.y= -self.ball.vel.y
self.ball.pos.y= length-y
#print >>sys.stderr, 'THE BALL WENT TOO UP, NEW Y: %f'%(self.ball.pos.y)
if y<(-(length/2)) :
self.state.update( self.referee.is_goal(self.ball , self.ground) )
self.ball.pos.y= -length-y
self.ball.vel.y=-self.ball.vel.y
#print >>sys.stderr, 'THE BALL WENT TOO DOWN, NEW Y: %f'%(self.ball.pos.y)
# def check_pos(self , coefficient=1.0/100):
# a = range(10)
# random.shuffle(a)
# sizes = [i/20.0 for i in xrange(1, 11)]
# random.shuffle(sizes)
# for i in a:
# temp_pos = self.players[i].pos
# for j in range(10):
# if( ( self.players[j].is_overlap(sizes[i], sizes[j], temp_pos) ) and (j!=i)):
# self.players[i].move(-coefficient)
# break
def move(self):
# for j in xrange(100):
# for i in xrange(10):
# self.player_move(i)
# self.ball_move()
# self.check_pos()
#for t in xrange(steps_per_cycle):
coefficient = 1.0/config.steps_per_cycle
q = deque(self.players)
if self.state.kicked:
if self.ball.vel.len() < 4:
self.ball.vel = Vector(2*random.choice([-1, 1]), 2*random.choice([-1, 1]))
for t in xrange(config.steps_per_cycle):
self.ball_move(coefficient)
for p in self.players:
p.rsteps = config.steps_per_cycle
no_change = 0
#print >>sys.stderr, 'move called'
#player_size = random.choice([0.3, 0.4, 0.5])
while len(q):
c = q.popleft()
#print >>sys.stderr, 'moving %d, %d, %d'%(c.team, c.number, c.rsteps)
c.move(coefficient)
c.rsteps-=1
change = True
#.........这里部分代码省略.........
示例10: update
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import update [as 别名]
def update(self):
State.update(self)
for shape in self._shapes:
shape.update()
return