def execute(self, grades, moduleDict, solutionDict):
        if not hasattr(moduleDict['analysis'], self.parameterFn):
            self.addMessage(
                'Method not implemented: analysis.%s' %
                (self.parameterFn,))
            return self.testFail(grades)

        result = getattr(moduleDict['analysis'], self.parameterFn)()

        if isinstance(result, str) and result.lower()[0:3] == "not":
            self.addMessage('Actually, it is possible!')
            return self.testFail(grades)

        if self.question2:
            livingReward = None
            try:
                discount, noise = result
                discount = float(discount)
                noise = float(noise)
            except:
                self.addMessage(
                    'Did not return a (discount, noise) pair; instead analysis.%s returned: %s' %
                    (self.parameterFn, result))
                return self.testFail(grades)
            if discount != 0.9 and noise != 0.2:
                self.addMessage(
                    'Must change either the discount or the noise, not both. Returned (discount, noise) = %s' %
                    (result,))
                return self.testFail(grades)
        else:
            try:
                discount, noise, livingReward = result
                discount = float(discount)
                noise = float(noise)
                livingReward = float(livingReward)
            except:
                self.addMessage(
                    'Did not return a (discount, noise, living reward) triple; instead analysis.%s returned: %s' %
                    (self.parameterFn, result))
                return self.testFail(grades)

        self.grid.setNoise(noise)
        if livingReward is not None:
            self.grid.setLivingReward(livingReward)

        start = self.grid.getStartState()
        policy = computePolicy(moduleDict, self.grid, discount)

        # check policy
        actionMap = {
            'N': 'north',
            'E': 'east',
            'S': 'south',
            'W': 'west',
            'X': 'exit'}
        width, height = self.policy.width, self.policy.height
        policyPassed = True
        for x in range(width):
            for y in range(height):
                if self.policy[x][y] in actionMap and policy[(x, y)] != actionMap[self.policy[x][y]]:
                    differPoint = (x, y)
                    policyPassed = False

        if not policyPassed:
            self.addMessage('Policy not correct.')
            self.addMessage(
                '    Student policy at %s: %s' %
                (differPoint, policy[differPoint]))
            self.addMessage(
                '    Correct policy at %s: %s' %
                (differPoint, actionMap[self.policy[differPoint[0]][differPoint[1]]]))
            self.addMessage('    Student policy:')
            self.printPolicy(policy, False)
            self.addMessage(
                "        Legend:  N,S,E,W at states which move north etc, X at states which exit,")
            self.addMessage(
                "                 . at states where the policy is not defined (e.g. walls)")
            self.addMessage('    Correct policy specification:')
            self.printPolicy(self.policy, True)
            self.addMessage(
                "        Legend:  N,S,E,W for states in which the student policy must move north etc,")
            self.addMessage(
                "                 _ for states where it doesn't matter what the student policy does.")
            self.printGridworld()
            return self.testFail(grades)

        # check path
        path = followPath(policy, self.grid.getStartState())

        if self.pathVisits is not None and self.pathVisits not in path:
            self.addMessage(
                'Policy does not visit state %s when moving without noise.' %
                (self.pathVisits,))
            self.addMessage('    States visited: %s' % (path,))
            self.addMessage('    Student policy:')
            self.printPolicy(policy, False)
            self.addMessage(
                "        Legend:  N,S,E,W at states which move north etc, X at states which exit,")
            self.addMessage(
                "                 . at states where policy not defined")
            self.printGridworld()
            return self.testFail(grades)

        if self.pathNotVisits is not None and self.pathNotVisits in path:
            self.addMessage(
                'Policy visits state %s when moving without noise.' %
                (self.pathNotVisits,))
            self.addMessage('    States visited: %s' % (path,))
            self.addMessage('    Student policy:')
            self.printPolicy(policy, False)
            self.addMessage(
                "        Legend:  N,S,E,W at states which move north etc, X at states which exit,")
            self.addMessage(
                "                 . at states where policy not defined")
            self.printGridworld()
            return self.testFail(grades)

        return self.testPass(grades)
dataset/ETHPy150Open rlpy/rlpy/rlpy/Domains/PacmanPackage/reinforcementTestClasses.py/GridPolicyTest.execute/original