Thanks for all the fish!

Thanks everyone for your great suggestions on my algorithm bleg.

Here is what I wound up doing (self.empties is set up in the classes __init__()):

    def position_agent(self, agent, x=RANDOM, y=RANDOM):
        """
        Position an agent on the grid.
        If x or y are positive, they are used, but if RANDOM,
        we get a random position.
        Ensure this random position is not occupied (in Grid).
        """
        if x == RANDOM or y == RANDOM:
            if self.exists_empty_cells():
                coords = random.choice(self.empties)
                x = coords[0]
                y = coords[1]
                self.empties.remove(coords)
            else:
                logging.error("Grid full; "
                              + agent.name + " not added.")
                return

        self.grid[y][x] = agent
        agent.pos = [x, y]


Comments

Popular posts from this blog

Libertarians, My Libertarians!

"Pre-Galilean" Foolishness