Env - > look_at_plants
This commit is contained in:
parent
29632d3693
commit
875d3e4473
94
env.py
94
env.py
@ -93,52 +93,52 @@ def try_move(field, tractor):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def look_at_plats(field, location):
|
def look_at_plats(field, location):
|
||||||
wsp = []
|
wsp = [(location[0] + 1, location[1]), (location[0] - 1, location[1]), (location[0], location[1] - 1), (location[0], location[1] + 1)]
|
||||||
|
|
||||||
|
return wsp
|
||||||
|
|
||||||
|
# if __name__ == "__main__":
|
||||||
|
#
|
||||||
if __name__ == "__main__":
|
# field = initialize_field()
|
||||||
|
# tractor = Trac('N', (0,0))
|
||||||
field = initialize_field()
|
#
|
||||||
tractor = Trac('N', (0,0))
|
# async def handle_echo(reader, writer):
|
||||||
|
# data = await reader.readline()
|
||||||
async def handle_echo(reader, writer):
|
# message = data.decode().split()
|
||||||
data = await reader.readline()
|
#
|
||||||
message = data.decode().split()
|
# if message[0] == "rotate":
|
||||||
|
# tractor.set_rotation(message[1])
|
||||||
if message[0] == "rotate":
|
# writer.write("OK\n".encode())
|
||||||
tractor.set_rotation(message[1])
|
# elif message[0] == "try":
|
||||||
writer.write("OK\n".encode())
|
# if try_move(field, tractor):
|
||||||
elif message[0] == "try":
|
# writer.write("OK\n".encode())
|
||||||
if try_move(field, tractor):
|
# else:
|
||||||
writer.write("OK\n".encode())
|
# writer.write("FAIL\n".encode())
|
||||||
else:
|
# elif message[0] == "move":
|
||||||
writer.write("FAIL\n".encode())
|
# tractor.move()
|
||||||
elif message[0] == "move":
|
# writer.write(("OK\n").encode())
|
||||||
tractor.move()
|
# elif message[0] == "look":
|
||||||
writer.write(("OK\n").encode())
|
# tractor.move()
|
||||||
elif message[0] == "look":
|
# writer.write(("OK\n").encode())
|
||||||
tractor.move()
|
#
|
||||||
writer.write(("OK\n").encode())
|
#
|
||||||
|
# print_field(field, tractor)
|
||||||
|
# # print(tractor.get_position().get_x())
|
||||||
print_field(field, tractor)
|
# # print(tractor.get_position().get_y())
|
||||||
# print(tractor.get_position().get_x())
|
# # print(tractor.get_rotation())
|
||||||
# print(tractor.get_position().get_y())
|
# update_state(field)
|
||||||
# print(tractor.get_rotation())
|
# await writer.drain()
|
||||||
update_state(field)
|
#
|
||||||
await writer.drain()
|
# writer.close()
|
||||||
|
#
|
||||||
writer.close()
|
# async def main():
|
||||||
|
# server = await asyncio.start_server(
|
||||||
async def main():
|
# handle_echo, '127.0.0.1', 8888)
|
||||||
server = await asyncio.start_server(
|
#
|
||||||
handle_echo, '127.0.0.1', 8888)
|
# addr = server.sockets[0].getsockname()
|
||||||
|
#
|
||||||
addr = server.sockets[0].getsockname()
|
# async with server:
|
||||||
|
# await server.serve_forever()
|
||||||
async with server:
|
#
|
||||||
await server.serve_forever()
|
# asyncio.run(main())
|
||||||
|
print(look_at_plats([], (5, 5)))
|
||||||
asyncio.run(main())
|
|
Loading…
Reference in New Issue
Block a user