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