From 875d3e44730c9abee6a1dd808bc65cd5a7eba96f Mon Sep 17 00:00:00 2001 From: Krystian Kabat Date: Fri, 31 May 2019 14:50:11 +0200 Subject: [PATCH 1/2] Env - > look_at_plants --- env.py | 94 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/env.py b/env.py index e781fb1..c4ca3ef 100755 --- a/env.py +++ b/env.py @@ -93,52 +93,52 @@ def try_move(field, tractor): return False 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__": - - 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()) +# 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))) \ No newline at end of file From 7994cc70ae86d020bb27138d1becb1bf9b8befe1 Mon Sep 17 00:00:00 2001 From: Krystian Kabat Date: Fri, 31 May 2019 14:54:48 +0200 Subject: [PATCH 2/2] Env - > look_at_plants (v2) --- env.py | 96 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 50 insertions(+), 46 deletions(-) diff --git a/env.py b/env.py index c4ca3ef..24ae81e 100755 --- a/env.py +++ b/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))) \ No newline at end of file +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())