nowe2
This commit is contained in:
commit
ce28016282
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):
|
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
6
tractor.py
Normal file → Executable 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)
|
||||||
|
Loading…
Reference in New Issue
Block a user