def read_and_apply_action()

in roboschool/multiplayer.py [0:0]


    def read_and_apply_action(self):
        """
        This functions blocks until client sends a command: step() or reset() or requests video image.
        It quits when user has finished communicating and now expects simulation to advance.
        """
        while 1:
            if self.passive:
                self.env.unwrapped.apply_action(np.zeros(shape=self.sh_act.shape))
                return
            check = self.sh_pipe_actready.readline()[:-1]

            if check=='a':
                #assert(not self.need_reset)
                self.env.unwrapped.apply_action(self.sh_act)
                self.need_response_tuple = True
                return

            elif check=='R':
                obs = self.env.reset()
                self.sh_obs[:] = obs
                os.write(self.sh_pipe_obsready, b'o\n')
                self.need_response_tuple = False # Already answered
                if self.need_reset:
                    self.done = False
                    self.passive = False
                    self.need_reset = False
                else:
                    self.done = True  # User has decided he wants to restart, make robot passive
                    self.passive = True
                    self.need_reset = False

            elif check=='G':
                rgb = self.env.render("rgb_array")
                assert rgb.shape==self.sh_rgb.shape
                self.sh_rgb[:] = rgb
                os.write(self.sh_pipe_obsready, b'i\n')
                self.need_response_tuple = False

            else:
                raise ValueError("multiplayer client %s sent here invalid string '%s'" % (self.prefix, check))