def do_POST(self): """Respond to a POST request.""" content_len = int(self.headers.getheader('content-length')) post_body = self.rfile.read(content_len) robot = Robot() robot.from_json(post_body) if(not robots.has_key(robot.getId())): robots[robot.getId()] = calculatePath(robot, board) self.send_response(200) self.send_header("Content-type", "text/html") self.end_headers() return print 'id: {0}, path: {1}, position: {2}'.format(robot.getId(), robots[robot.getId()], robot.position) self.send_response(200) self.send_header("Content-type", "text/html") self.end_headers() if robot.getOwnPosition() in robot.destination: self.wfile.write('{ "move": [ %s, %s ] }' % robot.getOwnPosition()) else: moves = robot.allowedMoves desired = robots[robot.getId()][0] if desired in moves: del robots[robot.getId()][0] self.wfile.write('{ "move": [ %s, %s ] }' % desired) else: self.wfile.write('{ "move": [ %s, %s ] }' % robot.getOwnPosition())
def do_POST(self): """Respond to a POST request.""" content_len = int(self.headers.getheader("content-length")) post_body = self.rfile.read(content_len) print post_body robot = Robot() robot.from_json(post_body) print self.send_response(200) self.send_header("Content-type", "text/html") self.end_headers() if robot.getOwnPosition() in robot.destination: self.wfile.write('{ "move": [ %s, %s ], "speed" : 0, "velocity" : [1, 1] }' % robot.getOwnPosition()) else: move = physics_a_star( (robot.position, robot.velocity, robot.speed), a_star(robot.position, robot.destination[0], robot.robots), ) log = '{"robotID" : %s, "move": [ %s, %s ], "speed" : %s, "velocity" : [%s, %s] }' % ( robot.id, move[0][0], move[0][1], move[2], move[1][0], move[1][1], ) print log self.wfile.write(log)
def do_POST(self): """Respond to a POST request.""" content_len = int(self.headers.getheader('content-length')) post_body = self.rfile.read(content_len) print post_body robot = Robot() robot.from_json(post_body) self.send_response(200) self.send_header("Content-type", "text/html") self.end_headers() if robot.getOwnPosition() in robot.destination: self.wfile.write('{ "move": [ %s, %s ], "speed" : 1, "velocity" : [1, 1] }' % robot.getOwnPosition()) else: move = robot.allowedMoves[int(random.random() * len(robot.allowedMoves))] self.wfile.write('{ "move": [ %s, %s ], "speed" : 1, "velocity" : [%s, %s] }' %( move[0][0], move[0][1], move[1][0], move[1][1]))