import utils def plant_pumpkin(width, height): utils.plant_grid(width, height, [Entities.Pumpkin], 0.75, True) def plant_carrots(width, height): utils.plant_grid(width, height, [Entities.Carrot], 0.75, True) def plant_alternating(width, height, plantWith): utils.plant_grid(width, height, plantWith, 0.75, False) # verify_pumpkin will verify that a pumpkin is planted in all tiles of a quadrant, and it will check that # the pumpkin isn't dead. if it's dead it will replant it. Returns whether any dead pumpkins were found. def verify_pumpkin(width, height): result = False others = {East:West, West:East} sideDir = East for row in range(height): for col in range(width): if get_entity_type() == Entities.Dead_Pumpkin: # ~20% of pumpkins die, we just replant plant(Entities.Pumpkin) result = True # if it's not the last pass, then move if col < width - 1: move(sideDir) if row < height - 1: sideDir = others[sideDir] move(North) return result #reset_pos() while True: worldSize = get_world_size() utils.move_to(0, 0) plant_pumpkin(worldSize / 2, worldSize / 2) utils.move_to(0, 0) while verify_pumpkin(worldSize / 2, worldSize / 2): utils.move_to(0, 0) utils.move_to(worldSize / 2, 0) plant_carrots(worldSize / 2, worldSize / 2) utils.move_to(0, worldSize / 2) plant_alternating(worldSize / 2, worldSize / 2, [ Entities.Tree, Entities.Bush ]) utils.move_to(worldSize / 2, worldSize / 2) # the top right quadrant is 50% of the time pumpkin, 50% of the time carrots if random() < 0.5: plant_carrots(worldSize / 2, worldSize / 2) else: plant_pumpkin(worldSize / 2, worldSize / 2) utils.move_to(worldSize / 2, worldSize / 2) while verify_pumpkin(worldSize / 2, worldSize / 2): utils.move_to(worldSize / 2, worldSize / 2)