Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var request = require('request');
- /*
- request.post('http://192.168.12.73:8080/buscamecha', {form:{posx:1,posy:2}}, function (error, response, body) {
- console.log('error:', error); // Print the error if one occurred
- console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
- console.log('body:', body); // Print the HTML for the Google homepage.
- });
- */
- var busca = function(x,y,maxx,maxy){
- console.log("BUSCANDO: "+x+" "+y+ " "+maxx+" "+maxy);
- llamadas++;
- request.post('http://192.168.12.73:8080/buscamecha', {form:{posx:x,posy:y}}, function (error, res, body) {
- console.log(body);
- let valores = JSON.parse(res.body);
- console.log(JSON.stringify(valores));
- if(valores.posx ==0 && valores.posy == 0){
- console.log("ENCONTRADO "+x+" "+y);
- console.log("LLAMADAS "+llamadas);
- }else if(valores.posx == 0){
- if(valores.posy>0){
- busca(x,Math.floor(y/2),maxx,y)
- }else{
- busca(x,y+Math.floor((maxy-y)/2),x,maxy);
- }
- }else if(valores.posy == 0){
- if(valores.posx>0){
- busca(Math.floor(x/2),y,x,maxy);
- }else{
- busca(x+Math.floor((maxx-x)/2),y,maxx,maxy);
- }
- }else{
- var bx,by,mx,my;
- if(valores.posx>0){
- bx=Math.floor(x/2);
- mx=x;
- }else{
- bx=x+Math.floor((maxx-x)/2);
- mx=maxx;
- }
- if(valores.posy<0){
- by = Math.floor(y/2);
- my = y;
- }else{
- by = y+Math.floor((maxy-y)/2);
- my = maxy;
- }
- //console.log("BUSCANDO: "+bx+" "+by+ " "+mx+" "+my);
- busca(bx,by,mx,my);
- }
- });
- }
- var encontrado = false;
- var max=10000000;
- var i = max;
- var j= max;
- var llamadas = 0;
- busca(i,j,max,max);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement