Beispiel #1
0
    def populate(self,
                 individual: Individual,
                 x_coord: int = 0,
                 y_coord: int = 0) -> None:
        """ Populate the world with an individual.

        Args:
            individual (Individual) : Individual of the world. Either a zombie or victim.
            x_coord    (int)        : The position, x coordinate, of the individual
            y_coord    (int)        : The position, y coordinate, of the individual
        """

        # Save coordinates
        individual.x_coord = x_coord
        individual.y_coord = y_coord

        # Add to population
        self.population.append(individual)

        # Get the population index of this individual
        population_index = len(self.population) - 1

        # Place the individual on the map
        self.map[x_coord][y_coord] = population_index

        # Add zombie to the queue to action
        if (individual.is_zombie):
            self.__enqueue(individual)
Beispiel #2
0
    def __move(self, individual: Individual, direction: str) -> None:
        """ Move the individual around the map.

        This moves the individual according to the direction given.
        Zombie can move from one edge through the edge.

        Args:
            individual (Individual) : Individual of the world
            direction  (str)        : Direction for individual to move
        """

        # Make sure to lowercase
        direction = direction.lower()

        # Going Up
        if (direction == 'u'):
            if (individual.y_coord == 0):
                if (individual.is_zombie):
                    individual.y_coord = self.N - 1
            else:
                individual.y_coord -= 1

        # Going Down
        if (direction == 'd'):
            if (individual.y_coord == self.N - 1):
                if (individual.is_zombie):
                    individual.y_coord = 0
            else:
                individual.y_coord += 1

        # Going Left
        if (direction == 'l'):
            if (individual.x_coord == 0):
                if (individual.is_zombie):
                    individual.x_coord = self.N - 1
            else:
                individual.x_coord -= 1

        # Going Right
        if (direction == 'r'):
            if (individual.x_coord == self.N - 1):
                if (individual.is_zombie):
                    individual.x_coord = 0
            else:
                individual.x_coord += 1