xd
This commit is contained in:
parent
66fe83073f
commit
6a36cc2dd0
8
env.py
Normal file → Executable file
8
env.py
Normal file → Executable 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
8
tractor.py
Normal file → Executable 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)
|
||||
@ -214,7 +214,7 @@ class Tractor(TreeClass):
|
||||
parsed_data = data.decode().split()
|
||||
time.sleep(self.sleep_time)
|
||||
writer.close()
|
||||
return {"ttl": int(parsed_data[0]), "is_alive": int(parsed_data[1]), "hydration": int(parsed_data[2]), "soil_level": int(parsed_data[3]),
|
||||
return {"ttl": int(parsed_data[0]), "is_alive": (parsed_data[1] == "True")? True, "hydration": int(parsed_data[2]), "soil_level": int(parsed_data[3]),
|
||||
"ready": int(parsed_data[4])}
|
||||
|
||||
async def service(self):
|
||||
|
Loading…
Reference in New Issue
Block a user