This commit is contained in:
Paulina J 2019-06-03 13:40:22 +02:00
commit ce28016282
2 changed files with 8 additions and 8 deletions

8
env.py Normal file → Executable file
View File

@ -109,7 +109,7 @@ def look_at_plats(field, location):
def send_stats(field, location):
x = location[0]
y = location[1]
stats = field[x][y]
stats = field[x][y].get_stats()
str_stats = str(stats["ttl"]) + " " + str(stats["is_alive"]) + " " + str(stats["hydration"]) + " " \
+ str(stats["soil_level"]) + " " + str(stats["ready"]) + "\n"
return str_stats
@ -141,9 +141,9 @@ if __name__ == "__main__":
for i in plants:
plants_str += (" " + str(i[0]) + " " + str(i[1]))
writer.write((plants_str + "\n").encode())
elif message[0] == "get_stats":
x = message[1]
y = message[2]
elif message[0] == "stats":
x = int(message[1])
y = int(message[2])
stats = send_stats(field, (x, y)).encode()
writer.write(stats)

8
tractor.py Normal file → Executable file
View File

@ -40,10 +40,10 @@ class Tractor(TreeClass):
reader, writer = await asyncio.open_connection('127.0.0.1', 8887)
writer.write(("look_at_plants " + str(location[0]) + " " + str(location[1]) + "\n").encode())
xd = await reader.readline()
xd = xd.split()
l = len(xd)
xd = xd.decode().split()
ln = int(len(xd) /2)
xd2 = []
for i in range(l):
for i in range(ln):
xd2.append((int(xd[2*i]), int(xd[2*i+1])))
time.sleep(self.sleep_time)
@ -224,7 +224,7 @@ class Tractor(TreeClass):
ready = int(parsed_data[4])
# return {"ttl": int(parsed_data[0]), "is_alive": ((parsed_data[1]=="True")?True:False), "hydration": int(parsed_data[2]), "soil_level": int(parsed_data[3]), "ready": int(parsed_data[4])}
return ({"ttl": ttl,"is_alive": is_alive,"hydration": hydration,"soil_level": soil_level,"ready": ready})
async def service(self):
plant_location = await self.look_at_plants(self.current_location)
for i in plant_location: