def run(self): """ start the simulation """ dt=self.dt clock = gui.clock() frameRate=1.0/dt/self.slowMotionFactor self.tick_count=0 self.world.start() # the event loop also loops the animation code while True: self.frameskipcount -= 1 self.tick_count += 1 display= self.frameskipcount == 0 and self.frameskipfactor != 0 if display: clock.tick(frameRate) self.frameskipcount=self.frameskipfactor if display or (self.tick_count%100)==0: gui.grab_events() if self.admin != None: self.admin.process(self) if gui.check_for_quit(): break self.ticks += 1 self.world.step() if display: self.screen.fill((0,0,0)) if self.painter != None: if self.painter.preDraw != None: self.painter.preDraw(self.screen) self.world.draw(self.screen) if self.painter != None: if self.painter.postDraw != None: self.painter.postDraw(self.screen) gui.blit(self.screen)
def run(self): """ start the simulation """ dt = self.world.dt clock = gui.clock() frameRate = 1.0 / dt / self.slowMotionFactor self.tick_count = 0 self.world.start() # the event loop also loops the animation code while True: self.frameskipcount -= 1 self.tick_count += 1 display = self.frameskipcount == 0 and self.frameskipfactor != 0 if display: clock.tick(frameRate) self.frameskipcount = self.frameskipfactor if display or (self.tick_count % 100) == 0: gui.grab_events() if self.admin != None: self.admin.process(self) if gui.check_for_quit(): break self.ticks += 1 self.world.step() if display: self.screen.fill((0, 0, 0)) if self.painter != None: if self.painter.preDraw != None: self.painter.preDraw(self.screen) self.world.draw(self.screen) if self.painter != None: if self.painter.postDraw != None: self.painter.postDraw(self.screen) gui.blit(self.screen)
frameRate = 10 # slow down to 10 steps per second. screen = gui.init_surface((800, 200), " CART + IP demo") force_scale = 10.0 sizes = [2, 1] net = brain.loadBrain() INIT_ANG = 0.3 cart.setAngle(math.pi + INIT_ANG) while not gui.check_for_quit(): # loop until user hits escape # Test for falling over # if fallen then reset with a random angle input = copy.deepcopy(cart.getState()) input[0] = input[0] - math.pi out = net.ffwd(input) force = (out[0] - 0.5) * force_scale # step the car for a single GUI frame cart.step(force, dt) # draw the cart and display info draw(screen, cart, force)
force_scale=10.0 sizes=[4,1] net=None TOTAL_TIME_MAX=10000 guess=pool.create() net=brain.FeedForwardBrain(weight=guess) # set the initial angle cart.setAngle(math.pi+plug.INIT_ANG) time=0.0 tot_time=0.0 while not gui.check_for_quit(): # loop until user hits escape # Test for falling over # if fallen then reset with a random angle fit =plug.reap(cart) if fit != None : pool.add(guess,fit) print pool if fit > plug.GOAL or tot_time > TOTAL_TIME_MAX: print " SUCCESS ---------------------------------------------------------------------- " brain.saveBrain(net) break cart.setAngle(math.pi+plug.INIT_ANG)
def check_for_quit(self): """ See if the user has closed the window. """ return gui.check_for_quit()
def check_for_quit(self): """ See if the user has closed the window. """ return gui.check_for_quit()