Exemple #1
0
    def random_card(self):
        """ Returns a card uniformly at random.

            (Called `randomCard` in the C++ version.)
        """

        return util.choice([oJack, oQueen, oKing])
Exemple #2
0
    def perform_action(self, action):
        """ Receives the agent's action and calculates the new environment percept.
            (Called `performAction` in the C++ version.)
        """

        assert self.is_valid_action(action)

        # Save the action.
        self.action = action

        # Opponent plays rock if it won the last round by playing rock, otherwise
        # it plays randomly.
        if (self.observation == aRock) and (self.reward == rLose):
            self.observation = aRock
        else:
            self.observation = util.choice(self.valid_actions)
        # end if

        # Determine reward.
        if action == self.observation:
            # If both the agent and the opponent made the same move, it's a draw.
            self.reward = rDraw
        elif action == aRock:
            # If the opponent made a scissors move, then the agent wins if they played rock.
            self.reward = rWin if self.observation == oScissors else rLose
        elif action == aScissors:
            # If the opponent made a paper move, then the agent wins if they played scissors.
            self.reward = rWin if self.observation == oPaper else rLose
        elif action == aPaper:
            # If the opponent made a rock move, then the agent wins if they played paper.
            self.reward = rWin if self.observation == oRock else rLose
        # end if

        # Return the resulting observation and reward.
        return (self.observation, self.reward)
Exemple #3
0
    def random_card(self):
        """ Returns a card uniformly at random.

            (Called `randomCard` in the C++ version.)
        """

        return util.choice([oJack, oQueen, oKing])
    def perform_action(self, action):
        """ Receives the agent's action and calculates the new environment percept.
            (Called `performAction` in the C++ version.)
        """

        assert self.is_valid_action(action)

        # Save the action.  
        self.action = action

        # Opponent plays rock if it won the last round by playing rock, otherwise
        # it plays randomly.
        if (self.observation == aRock) and (self.reward == rLose):
            self.observation = aRock
        else:
            self.observation = util.choice(self.valid_actions)
        # end if

        # Determine reward.
        if action == self.observation:
            # If both the agent and the opponent made the same move, it's a draw.
            self.reward = rDraw
        elif action == aRock:
            # If the opponent made a scissors move, then the agent wins if they played rock.
            self.reward = rWin if self.observation == oScissors else rLose
        elif action == aScissors:
            # If the opponent made a paper move, then the agent wins if they played scissors.
            self.reward = rWin if self.observation == oPaper else rLose
        elif action == aPaper:
            # If the opponent made a rock move, then the agent wins if they played paper.
            self.reward = rWin if self.observation == oRock else rLose
        # end if

        # Return the resulting observation and reward.
        return (self.observation, self.reward)
Exemple #5
0
    def teleport_agent(self):
        """ Randomly places the agent at any `cTeleportTo` location.

           (Called `teleportAgent` in the C++ version.)
        """

        self.teleported = True

        # This is altered from the C++ version to be far more efficient.
        # (e.g. instead of random search of the maze, use a random choice
        #  over a pre-computed list of possible destinations.)
        self.row, self.col = util.choice(self.teleport_to_locations)
Exemple #6
0
    def teleport_agent(self):
        """ Randomly places the agent at any `cTeleportTo` location.

           (Called `teleportAgent` in the C++ version.)
        """

        self.teleported = True

        # This is altered from the C++ version to be far more efficient.
        # (e.g. instead of random search of the maze, use a random choice
        #  over a pre-computed list of possible destinations.)
        self.row, self.col = util.choice(self.teleport_to_locations)

    # end def


# end class
Exemple #7
0
    def generate_random_action(self):
        """ Returns an action generated uniformly at random.
            (Called `genRandomAction` in the C++ version.)
        """

        return util.choice(self.environment.valid_actions)
Exemple #8
0
    def generate_random_action(self):
        """ Returns an action generated uniformly at random.
        """

        return util.choice(self.environment.valid_actions)
Exemple #9
0
    def generate_random_action(self):
        """ Returns an action generated uniformly at random.
        """

        return util.choice(self.generate_all_actions())
Exemple #10
0
    def generate_random_action(self):
        """ Returns an action generated uniformly at random.
            (Called `genRandomAction` in the C++ version.)
        """

        return util.choice(self.environment.valid_actions)