hydration

This commit is contained in:
Pikusia 2019-05-31 16:08:28 +02:00
parent 892c084bc1
commit f2468f7555
2 changed files with 16 additions and 4 deletions

View File

@ -9,6 +9,6 @@ class Tomato(Plant):
desoil_ratio = 0.8
max_soil_lvl = 40
optimal_soil_ratio = 2
max_hydration_lvl = 40
max_hydration_lvl = 100
optimal_hydration_ratio = 2
ready = 10

View File

@ -2,6 +2,8 @@
import asyncio
import time
from Graph import Graph
from Cucumber import Cucumber
from Tomato import Tomato
class Tractor:
sleep_time = 0.1
@ -26,7 +28,7 @@ class Tractor:
time.sleep(self.sleep_time)
writer.close()
async def look_at_plants(self):
async def look_at_plants(self, direction):
reader, writer = await asyncio.open_connection('127.0.0.1', 8888)
writer.write(("rotate " + direction + "\n").encode())
await reader.readline()
@ -187,6 +189,16 @@ class Tractor:
await self.move_tractor(start_position)
def hydration(self, plant):
if type(plant) == Tomato:
if plant.hydration < 50:
plant.increase_hydration(plant.max_hydration_lvl - plant.hydration)
elif type(plant) == Cucumber:
if plant.hydration < 40:
plant.increase_hydration(plant.max_hydration_lvl - plant.hydration)
async def service(self):
"tutaj trzeba zapytac env z jakimi roslinami sie styka traktor i je obsłuzyc"
pass
@ -198,8 +210,8 @@ class Tractor:
parsed_data = data.decode().split()
time.sleep(self.sleep_time)
writer.close()
return {"ttl": parsed_data[0], "is_alive": parsed_data[1], "hydration": parsed_data[2], "soil_level": parsed_data[3],
"ready": parsed_data[4]}
return {"ttl": int(parsed_data[0]), "is_alive": int(parsed_data[1]), "hydration": int(parsed_data[2]), "soil_level": int(parsed_data[3]),
"ready": int(parsed_data[4])}
if __name__ == "__main__":