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

6
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) reader, writer = await asyncio.open_connection('127.0.0.1', 8887)
writer.write(("look_at_plants " + str(location[0]) + " " + str(location[1]) + "\n").encode()) writer.write(("look_at_plants " + str(location[0]) + " " + str(location[1]) + "\n").encode())
xd = await reader.readline() xd = await reader.readline()
xd = xd.split() xd = xd.decode().split()
l = len(xd) ln = int(len(xd) /2)
xd2 = [] xd2 = []
for i in range(l): for i in range(ln):
xd2.append((int(xd[2*i]), int(xd[2*i+1]))) xd2.append((int(xd[2*i]), int(xd[2*i+1])))
time.sleep(self.sleep_time) time.sleep(self.sleep_time)