def action(self): Plant.action(self) d = [[1, 0], [-1, 0], [0, 1], [0, -1]] for i in range(0, 4): temp = Point(self.position.x + d[i][0], self.position.y + d[i][1]) self.wrapPosition(temp) if self.world.getOrganism(temp) is not None: if isinstance(self.world.getOrganism(temp), Animal): name = self.world.getOrganism(temp).species if self.world.getOrganism(temp).die(self): self.world.addToLog(name + " has been burned by hogweed!")
def run(self): garden = Garden() workbook = load_workbook("Garden.xlsx") sheet = workbook.active plant_current_name = None plant_current_array = [] for row in range(sheet.min_row + 1, sheet.max_row): plant_name = sheet.cell(row, 1).value.lower() plant_next_to_value = sheet.cell(row, 3).value.lower() plant_next_to_name = sheet.cell(row, 2).value.lower() if plant_current_name is None: plant_current_name = plant_name if plant_current_name != plant_name: garden.add_plant(Plant(plant_current_name, plant_current_array)) plant_current_name = plant_name plant_current_array = [] if plant_next_to_value == "yes" or (plant_next_to_value == "maybe" and include_maybe): plant_current_array.append(plant_next_to_name) garden.set_plants_next_to_object() return garden
def __init__(self): self.state = 0 # We have a plant: self.plant = Plant(strain="Tomato", ph=7) # Mixer to mix the components self.mixer = Mixer(step_pin=8, direction_pin=9, enable_pin=10) # PH measurements: self.ph = PHMeter(pin=1) # The main tank pumps: self.main_container_pump_in = Pump("Main container pump (in)", pin=4) self.main_container_pump_out = Pump("Main container pump (out)", pin=5) self.water_level = WaterLevel(pin=0) # The tanks with the components: self.main_tank = Tank(max_level=0.9, water_level_sensor=self.water_level, pump_in=self.main_container_pump_in, pump_out=self.main_container_pump_out, ph=self.ph, mixer=self.mixer) # 4 Pumps for each of the containers: self.water_pump = Pump("Water pump", pin=0) self.acid_pump = Pump("Acid pump", pin=1) self.alkali_pump = Pump("Alkali pump", pin=2) self.fertilizer_pump = Pump("Fertilizer pump", pin=3) return
def respond_health(plant : Plant): response_msg = "" plant.sense_condition() need_water = plant.needWater() need_light = plant.needLuminesity() if need_water: response_msg += "水が欲しいよ!" if need_light: response_msg += "光が欲しいよ" if not need_light and not need_water: response_msg += "元気だよ!" if np.random.randint(0, 10) < 2: response_msg += "\nいつもありがとう(^^)" return response_msg
def draw(this): this.screen.fill((0, 0, 0)) for y in range(len(this.entities)): for x in range(len(this.entities[y])): if this.entities[y][x] is not None: pygame.draw.rect( this.screen, this.entities[y][x].getColor(), pygame.Rect(x * CellDist, y * CellDist, CellSize, CellSize)) text = World.font.render(this.entities[y][x].DisplayChar, True, (0, 0, 0)) this.screen.blit( text, (x * CellDist + CellDist / 2 - text.get_width(), y * CellDist + CellDist / 2 - text.get_height() / 2)) else: pygame.draw.rect( this.screen, (40, 40, 40), pygame.Rect(x * CellDist, y * CellDist, CellSize, CellSize)) animalClasses = Animal.__subclasses__() plantClasses = Plant.__subclasses__() for i in range(len(animalClasses)): aClass = animalClasses[i] pygame.draw.rect( this.screen, aClass(this).getColor(), pygame.Rect(i * CellDist, (this.size.y + 1) * CellDist, CellSize, CellSize)) text = World.font.render(aClass(this).DisplayChar, True, (0, 0, 0)) this.screen.blit(text, (i * CellDist + CellDist / 2 - text.get_width(), (this.size.y + 1) * CellDist + CellDist / 2 - text.get_height() / 2)) plStIdx = len(animalClasses) for i in range(plStIdx, plStIdx + len(plantClasses)): aClass = plantClasses[i - plStIdx] pygame.draw.rect( this.screen, aClass(this).getColor(), pygame.Rect(i * CellDist, (this.size.y + 1) * CellDist, CellSize, CellSize)) text = World.font.render(aClass(this).DisplayChar, True, (0, 0, 0)) this.screen.blit(text, (i * CellDist + CellDist / 2 - text.get_width(), (this.size.y + 1) * CellDist + CellDist / 2 - text.get_height() / 2)) for i in range(len(this.comments)): text = World.font.render(this.comments[i] + ".", True, (255, 255, 255)) this.screen.blit(text, ((this.size.x + 1) * CellDist, i * 10)) pygame.display.flip()
def Collision(self, o): if not isinstance(o, CyberSheep.CyberSheep): o.Kill(self.string) self.Kill(o.string) else: Plant.Collision(self, o) return False
def _loadPlantsData(self): """ Load the flower data file. This file holds the values for each supported flowers """ data = None with open('plantsData.json', 'r') as f: data = f.read() data = json.loads(data) if data is not None: for name, data in data.items(): self._plantsData[name] = Plant(name, data)
def input(this): for event in pygame.event.get(): if event.type == pygame.KEYDOWN: this.comments.clear() for eArr in this.entities: for ent in eArr: if isinstance(ent, Human): ent.onEvent(event) if event.type == pygame.QUIT: return True if event.type == pygame.KEYDOWN: if (event.key == pygame.K_z): this.save() elif (event.key == pygame.K_w): this.load() else: this.tick() if event.type == pygame.MOUSEBUTTONDOWN: mPos = Vec2(event.pos[0], event.pos[1]) animalClasses = Animal.__subclasses__() plantClasses = Plant.__subclasses__() for i in range(len(animalClasses)): if pygame.Rect(i * CellDist, (this.size.y + 1) * CellDist, CellSize, CellSize).collidepoint(mPos.x, mPos.y): this.chosenClass = animalClasses[i] return False plStIdx = len(animalClasses) for i in range(plStIdx, plStIdx + len(plantClasses)): if pygame.Rect(i * CellDist, (this.size.y + 1) * CellDist, CellSize, CellSize).collidepoint(mPos.x, mPos.y): this.chosenClass = plantClasses[i - plStIdx] return False for i in range(this.size.y): for j in range(this.size.x): idx = Vec2(j, i) if pygame.Rect(j * CellDist, i * CellDist, CellSize, CellSize).collidepoint(mPos.x, mPos.y): this.killEntity(idx) this.spawnEntity(idx, this.chosenClass) return False
def __create_plant(self, json_object): kls = ExampleResponce center = ExampleResponce() ex = center.examples ex["調子はどう?"] = kls.respond_health ex["水はいる?"] = kls.respond_water_demand ex["日当たりはどう?"] = kls.respond_light_demand ex["気温はどう?"] = kls.respond_temperture res = Plant(json_object["name"], json_object["display_name"], SensorBuffer(), ex, json_object["water_threshold"], json_object["luminosity_threshold"], json_object["temperture_min_relax"], json_object["temperture_max_relax"]) return res
def on_init(self): pygame.init() self._display_surf = pygame.display.set_mode( self.size, pygame.HWSURFACE | pygame.DOUBLEBUF) self._running = True for i in range(0, 10): plants.append( Plant(random.randint(100, 1500), random.randint(100, 800), plantImage, random.randint(200, 300), self)) for i in range(0, 2): rabbits.append( Rabbit(random.randint(100, 1500), random.randint(100, 800), rabbitImage, 0.25, self)) gameObjects.extend(rabbits) gameObjects.extend(plants)
def set_plants(): sparql.setQuery("""SELECT DISTINCT ?tag""" + so.concat_string_types()) sparql.setReturnFormat(JSON) results = sparql.query() for result in results: result_string = str(result) start_position = result_string.find("resource/") end_position = result_string.find("\" }") if start_position != -1 and result_string.find("escribed") is -1 and result_string.find( '&') is -1 and result_string[start_position + 9: end_position].find('\\') is -1 \ and result_string[start_position + 9: end_position].find('Of') is -1 \ and result_string[start_position + 9: end_position].find(',') is -1 \ and result_string[start_position + 9: end_position].find('As') is -1 \ and result_string[start_position + 9: end_position].find('Wikicat') is -1 \ and result_string[start_position + 9: end_position].find('.') is -1 \ and result_string[start_position + 9: end_position].find('(') is -1: result = result_string[start_position + 9:end_position] plant_list.append(Plant(result))
def __init__(self, world, position): Plant.__init__(self, world, position, 99)
def __init__(self, a=0, w=None): if w == None: Plant.__init__(self, 10, 0, None, 0.01, 'H') else: Plant.__init__(self, 10, a, w, 0.01, 'H')
import cmd import sys import os farm_width = 9 farm_height = 4 class User: def __init__(self): self.inventory = [] self.energy = 100 farmer = User() plants = { 'BLUEBERRY' : Plant(3, 'b', 'B'), 'STRAWBERRY' : Plant(6, 's', 'S') } ''' commands = { '' } ''' def make_title(): print(" _ _ _ _ _ ") print("| | | | ___ | | ___ ___ ._ _ _ ___ _| |_ ___ ") print("| | | |/ ._>| |/ | '/ . \| ' ' |/ ._> | | / . \ ") print("|__/_/ \___.|_|\_|_.\___/|_|_|_|\___. |_| \___/ ") print(" ______ _____ __ __ ______ _____ _____ _ _ _ ")
def Action(self): self.world.MassRemoveFromWorld(self.string, self.location,\ lambda o : False if isinstance(o, Plant) or isinstance(o, CyberSheep.CyberSheep) else True) Plant.Action(self)
def __init__(self, a=0, w=None): if w == None: Plant.__init__(self, 99, 0, None, 0.03, 'B') else: Plant.__init__(self, 99, a, w, 0.03, 'B')
# Define the existing pot pot1 = Pot(Pot.DEFAULT_POSITION_1, Pot.DEFAULT_PATH_1) pot1.records.loadFromFile(pot1.pathToFile) pot2 = Pot(Pot.DEFAULT_POSITION_2, Pot.DEFAULT_PATH_2) pot2.records.loadFromFile(pot2.pathToFile) pot3 = Pot(Pot.DEFAULT_POSITION_3, Pot.DEFAULT_PATH_3) pot3.records.loadFromFile(pot3.pathToFile) pot4 = Pot(Pot.DEFAULT_POSITION_4, Pot.DEFAULT_PATH_4) pot4.records.loadFromFile(pot4.pathToFile) # Put them in a list listPot = [pot1, pot2, pot3, pot4] # Define Plants a = PlantsDict() plant1 = Plant('Pervenche Major', 20.0, 90, 70) plant2 = Plant('Sedum Rupestre', 20.0, 40, 70) plant3 = Plant('Sedum Acre', 20.0, 40, 70) plant4 = Plant('Oeillet Mignardise', 20.0, 65, 70) plant5 = Plant('Menthe Commune', 20.0, 70, 70) a.addPlant(plant1) a.addPlant(plant2) a.addPlant(plant3) a.addPlant(plant4) a.saveInFile() # Define the threads controlThread = ControlThread(lock, listPot) # Start the control thread
def __init__(self, a = 0, w = None): if w == None: Plant.__init__(self, 0, 0, None, 0.05, 'D') else: Plant.__init__(self, 0, a, w, 0.05, 'D')
def LoadDataFile(self, fileName): tree = ElementTree.parse(open(fileName)) root = tree.getroot() # World Map Constants worldMap = root.find("./LAND_BOUNDS") self.WorldWidth = float(worldMap.find("WIDTH").text) self.WorldHeight = float(worldMap.find("HEIGHT").text) # Plants plants = root.find("./PLANTS") self.InitialPlantCount = int(plants.find("INITIAL_PLANT_COUNT").text) self.PlantGrowthRate = float(plants.find("GROWTH_RATE").text) self.MaxPlantSize = int(plants.find("MAX_SIZE").text) self.MaxSeedCastDistance = int( plants.find("MAX_SEED_CAST_DISTANCE").text) self.MaxSeedNumber = int(plants.find("MAX_SEED_NUMBER").text) self.SeedViabilityPercentage = float( plants.find("SEED_VIABILITY").text) self.InitialPlantList = [] for plant in plants.findall("PLANT"): self.InitialPlantList.append( Plant(int(plant.find("X_POS").text), int(plant.find("Y_POS").text), int(plant.find("P_DIAMETER").text))) # Grazers grazers = root.find("./GRAZERS") self.InitialGrazerCount = int( grazers.find("INITIAL_GRAZER_COUNT").text) self.GrazerEnergyInputRate = int(grazers.find("G_ENERGY_INPUT").text) self.GrazerEnergyOutputRate = int(grazers.find("G_ENERGY_OUTPUT").text) self.GrazerEnergyToReproduce = int( grazers.find("G_ENERGY_TO_REPRODUCE").text) self.GrazerMaxSpeedTime = float(grazers.find("G_MAINTAIN_SPEED").text) self.GrazerMaxSpeed = float(grazers.find("G_MAX_SPEED").text) self.InitialGrazerList = [] for grazer in grazers.findall("GRAZER"): self.InitialGrazerList.append( Grazer(int(grazer.find("X_POS").text), int(grazer.find("Y_POS").text), int(grazer.find("G_ENERGY_LEVEL").text))) # Predators predators = root.find("./PREDATORS") self.InitialPredatorCount = int( predators.find("INITIAL_PREDATOR_COUNT").text) self.PredatorMaxSpeedHOD = float(predators.find("MAX_SPEED_HOD").text) self.PredatorMaxSpeedHED = float(predators.find("MAX_SPEED_HED").text) self.PredatorMaxSpeedHOR = float(predators.find("MAX_SPEED_HOR").text) self.PredatorMaxSpeedTime = float( predators.find("P_MAINTAIN_SPEED").text) self.PredatorEnergyOutputRate = int( predators.find("P_ENERGY_OUTPUT").text) self.PredatorEnergyToReproduce = int( predators.find("P_ENERGY_TO_REPRODUCE").text) self.PredatorMaxOffspring = int(predators.find("P_MAX_OFFSPRING").text) self.PredatorGestationPeriodDays = float( predators.find("P_GESTATION").text) self.PredatorOffspringEnergyLevel = int( predators.find("P_OFFSPRING_ENERGY").text) self.InitialPredatorList = [] prID = 0 for predator in predators.findall("PREDATOR"): genotype = predator.find("GENOTYPE").text genotype = re.sub(r"[\n\t]*", "", genotype).split() self.InitialPredatorList.append( Predator(int(predator.find("X_POS").text), int(predator.find("Y_POS").text), int(predator.find("P_ENERGY_LEVEL").text), genotype, prID)) prID += 1 # Obstacles obstacles = root.find("./OBSTACLES") self.InitialObstacleCount = int( obstacles.find("INITIAL_OBSTACLE_COUNT").text) self.InitialObstacleList = [] for obstacle in obstacles.findall("OBSTACLE"): self.InitialObstacleList.append( Obstacle(int(obstacle.find("X_POS").text), int(obstacle.find("Y_POS").text), int(obstacle.find("O_DIAMETER").text), int(obstacle.find("O_HEIGHT").text)))
tasks = { "TILL" : 2, "PLANT" : 3, "WATER" : 2, "HARVEST" : 1 } harvest = { 'BLUEBERRIES' : Food("BLUEBERRIES", 50, 15), 'STRAWBERRIES' : Food("STRAWBERRIES", 25, 10), 'RASPBERRIES' : Food("RASPBERRIES", 10, 8), 'CORN' : Food("CORN", 35, 20) } plants = { 'BLUEBERRY' : Plant('BLUEBERRY', ['b', 'B'], 8, harvest['BLUEBERRIES']), 'STRAWBERRY' : Plant('STRAWBERRY', ['s', 'S'], 5, harvest['STRAWBERRIES']), 'RASPBERRY' : Plant('RASPBERRY', ['r', 'R'], 3, harvest['RASPBERRIES']), 'CORN' : Plant('CORN', ['c', 'C'], 6, harvest['CORN']) } items = { 'seeds' : { 'BLUEBERRY SEED' : Seed("BLUEBERRY SEED", 10, plants['BLUEBERRY']), 'STRAWBERRY SEED' : Seed("STRAWBERRY SEED", 5, plants['STRAWBERRY']), 'RASPBERRY SEED' : Seed("RASPBERRY SEED", 3, plants['RASPBERRY']), 'CORN SEED' : Seed("CORN SEED", 7, plants['CORN']), }, 'food' : { 'BLUEBERRIES' : Food("BLUEBERRIES", 50, 15),
def Collision(self, o): o.buff(3) Plant.Collision(self, o) return False
@classmethod def garden_soil(cls, amount): cls.soil_level -= int(amount) print(f"My new soil level is {cls.soil_level}") def add_tree(self, name, gender, species, height): new_tree = Tree(name, gender, species, height) self.plants.append(new_tree) def plant_kingdom(self): kingdom = ["Mosses/Liverworts", "Ferns", "Gymnosperms", "Angiosperms"] # maybe add Soil_type p_k = random.choice(kingdom) print(p_k) def is_healthy(self): print("This tree is wilting it's leaves... 🍃🍂") # instances brian = Garden("ars", "male") brian.garden_soil(20) brian.add_tree("ars", "male", " oak", 700) brian.plant_kingdom() brian.is_healthy() shawn = Plant("jo", "90in") shawn.leaf() shawn.color()
def addPlant(self,ID,sourcingCost,leadTime): self.plants[ID] = Plant(sourcingCost,leadTime)
from Plant import Plant p1 = Plant("tomatoes", "Summer", 15, 7) p2 = Plant("cactus", "summer", 27, 8) Plants = [p1, p2] print(p2.average(Plants))
def __init__(self): for i in range(0, 4): self.__alistPlant.append(Plant(i, "empty"))
def Action(self): for i in range(0, 3): Plant.Action(self)
def action(self): Plant.action(self) Plant.action(self) self.age -= 1 Plant.action(self) self.age -= 1
for p in range(0, 1): x = 0 y = 0 while any(isinstance(o, WorldObj) for o in World[x][y]): x = random.randint(0, WorldSize - 1) y = random.randint(0, WorldSize - 1) World[x][y].append(Person(x, y)) for p in range(0, 1): x = 0 y = 0 while any(isinstance(o, WorldObj) for o in World[x][y]): x = random.randint(0, WorldSize - 1) y = random.randint(0, WorldSize - 1) World[x][y].append(Plant(x, y)) def draw(screen): cursorX = 0 cursorY = 0 paused = False while True: screen.clear() for x in range(0, WorldSize - 1): for y in range(0, WorldSize - 1): for o in World[x][y]: if not paused: o.Act() screen.print_at('X', cursorX, cursorY, colour=2, bg=0)
from Batch import Batch from Buffer import Buffer from Task import Task from Machine import Machine from Plant import Plant from Printer import Printer from Event import Event from Schedule import Schedule from Simulator import Simulator from Optimizer import Optimizer import math import sys """ Testing Task 1 """ waferprod = Plant("Waferprod") machine1 = waferprod.newMachine("machine1") machine2 = waferprod.newMachine("machine2") machine3 = waferprod.newMachine("machine3") start = waferprod.newEvent("Start") task1 = waferprod.newTask("Task1", 0.5, machine1) task2 = waferprod.newTask("Task2", 3.5, machine2) task3 = waferprod.newTask("Task3", 1.2, machine1) task4 = waferprod.newTask("Task4", 3, machine3) task5 = waferprod.newTask("Task5", 0.8, machine2) task6 = waferprod.newTask("Task6", 0.5, machine1) task7 = waferprod.newTask("Task7", 1, machine2) task8 = waferprod.newTask("Task8", 1.9, machine3) task9 = waferprod.newTask("Task9", 0.3, machine1)