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]
                logging.error("Grid full; "
                              + + " not added.")

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

No comments:

Post a Comment