def score_fitness(self, outer):
        """
        Give a fitness score for the Chromosome

        Parameters
        ----------
        outer : GA_Agent

        Returns
        -------
        integer
            Fitness score for the Chromosome.

        """
        env = outer.init_env_state()
        how_far = 0
        for move in self.moves:
            direction = move[0]
            xv, yv = self.get_move(direction)
            env = asteroids_exp.move(env, xv, yv, move[1], outer.window_width, outer.window_height, outer.args, lambda x: asteroids_exp.render(outer.view, x))
            if env.goal == asteroids_exp.Goal.FAIL:
                #print("fail")
                return how_far #env.ship.fuel + 
            elif env.ship.x > outer.window_width and env.goal == asteroids_exp.Goal.SUCCESS:
                return  outer.window_width+1001 + env.ship.fuel*100 
            else:
                #print("ok")
                how_far = env.ship.x
            #print(env.ship.fuel)
        return how_far*10 + env.ship.fuel*10
 def act(self, state, direction, time):
     #pdb.set_trace()
     xv, yv = self.get_move(direction)
     state = asteroids_exp.move(
         state, xv, yv, time, self.window_width, self.window_height,
         self.args, lambda x: asteroids_exp.render(self.view, x))
     return state
        def act(self, outer):
            """
            Determine the states performance score by stepping through each move
            in the state.

            Parameters
            ----------
            outer : SA_Agent
                The simulated annealing agent the node is inside of.

            Returns
            -------
            integer
                Numerical value for a performance measure. Higher is better.

            """
            outer.init_env_state()
            how_far = 0
            for move in self.state:
                direction = move[0]
                xv, yv = self.get_move(direction)
                outer.env_state = asteroids_exp.move(outer.env_state, xv, yv, move[1], outer.window_width, outer.window_height, outer.args, lambda x: asteroids_exp.render(outer.view, x))
                if outer.env_state.goal == asteroids_exp.Goal.FAIL:
                    return how_far
                elif outer.env_state.goal == asteroids_exp.Goal.SUCCESS:
                    return outer.window_width + outer.env_state.ship.fuel - len(self.state) + 10001
                else:
                    how_far = outer.env_state.ship.x
            return how_far + outer.env_state.ship.fuel - len(self.state)
Esempio n. 4
0
 def __init__(self, initialState, moves):
     self.listMoves = moves
     state = initialState
     for move in moves:
         state = asteroids_exp.move(state, SA_Agent.MOVES[move[0]][0],
                                    SA_Agent.MOVES[move[0]][1], move[1],
                                    SA_Agent.window_width,
                                    SA_Agent.window_height, FARG, None)
     self.fuel = state.ship.fuel
     self.collisions = state.num_collisions
    def check_sol(self):
        """
        Goes through the solution state for this agent and checks to see if it is a failure
        or a success

        Returns
        -------
        None.

        """
        self.init_env_state()
        for move in self.solution:
            direction = move[0]
            xv, yv = asteroids_exp.MOVES[direction]
            self.env_state = asteroids_exp.move(self.env_state, xv, yv, move[1], self.window_width, self.window_height, self.args, lambda x: asteroids_exp.render(self.view, x))
            if self.env_state.goal == asteroids_exp.Goal.FAIL:
                print("failure")
                return
            if self.env_state.goal == asteroids_exp.Goal.SUCCESS:
                print("success")
                return