示例#1
0
    def message(self, msg):
        if msg == "what is your name?":
            return "my name is skeleton_environment, Python edition!"
        else:
            return "I don't know how to respond to your message"

    # noinspection PyMethodMayBeStatic
    def _check_terminal(self, action):
        if action.doubleArray == [-2.0] or action.doubleArray == MDPAction.description["kick"]["value"]:
            return True
        return False

    def _calculate_reward(self, action):
        reward = -1.0
        if action.doubleArray == MDPAction.description["kick"]["value"]:
            result = self._client.query("check goal")
            if result == "success":
                reward = 20
            elif result == "failure":
                reward = -2
            else:
                raise ValueError("Unknown result from server")
        elif action.doubleArray == [-2.0]:
            reward = -20

        return reward


if __name__ == "__main__":
    loader.load_environment(PenaltyKickEnvironment())
示例#2
0
        if self._client is not None:
            self._client.reset()

    def start(self):
        return Observation()

    def step(self, action):
        return_ro = Reward_observation_terminal()
        return_ro.r = -1.0
        return_ro.o = Observation()
        if len(action.doubleArray) == 0:
            return_ro.terminal = True
        else:
            return_ro.terminal = False

        return return_ro

    def cleanup(self):
        if self._client is not None:
            self._client.close()

    def message(self, msg):
        if msg == "what is your name?":
            return "my name is skeleton_environment, Python edition!"
        else:
            return "I don't know how to respond to your message"


if __name__ == "__main__":
    loader.load_environment(BodyMotionEnvironment())
    def print_state(self):
        num_rows = len(self.map)
        num_cols = len(self.map[0])
        print "Agent is at: " + str(self.agent_row) + "," + str(self.agent_col)
        print "Columns:0-10                10-17"
        print "Col    ",
        for col in range(0, num_cols):
            print col % 10,

        for row in range(0, num_rows):
            print
            print "Row: " + str(row) + " ",
            for col in range(0, num_cols):
                if self.agent_row == row and self.agent_col == col:
                    print "A",
                else:
                    if self.map[row][col] == self.WORLD_GOAL:
                        print "G",
                    if self.map[row][col] == self.WORLD_MINE:
                        print "M",
                    if self.map[row][col] == self.WORLD_OBSTACLE:
                        print "*",
                    if self.map[row][col] == self.WORLD_FREE:
                        print " ",
        print


if __name__ == "__main__":
    environment_loader.load_environment(MinesEnvironment())
示例#4
0
        self._sensors[1] = self._sensors[1].clip(min=self._limits[1, 0], max=self._limits[1, 1])
        self._sensors[0] += self._dt * self._sensors[1]
        self._sensors[0] = self._sensors[0].clip(min=self._limits[0, 0], max=self._limits[0, 1])
        if self._sensors[0] == self._limits[0, 0] and self._sensors[1] < 0.0:
            self._sensors[1] = 0.0

    def _is_terminal(self):
        return self._sensors[0] >= self._goal_pos

    def _render(self, pos):
        if self._visualize:
            if self._fig is None or not plt.fignum_exists(self._fig.number):
                self._fig = plt.figure()
                plt.rcParams['legend.fontsize'] = 10
                self._ax = self._fig.add_subplot(1, 1, 1)
                self._fig.show()

            self._ax.cla()
            self._ax.plot(self._t, np.sin(3 * self._t))

            car = plt.Circle((pos, np.sin(3 * pos)), radius=0.02, fc='r')
            self._ax.add_artist(car)

            self._ax.set_ylim(-1.05, 1.05)

            self._fig.canvas.draw()


if __name__ == "__main__":
    env_loader.load_environment(MountainCar())