Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. var request = require('request');
  2.  
  3. /*
  4. request.post('http://192.168.12.73:8080/buscamecha', {form:{posx:1,posy:2}}, function (error, response, body) {
  5. console.log('error:', error); // Print the error if one occurred
  6. console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
  7. console.log('body:', body); // Print the HTML for the Google homepage.
  8. });
  9. */
  10.  
  11. var busca = function(x,y,maxx,maxy){
  12. console.log("BUSCANDO: "+x+" "+y+ " "+maxx+" "+maxy);
  13. llamadas++;
  14. request.post('http://192.168.12.73:8080/buscamecha', {form:{posx:x,posy:y}}, function (error, res, body) {
  15. console.log(body);
  16. let valores = JSON.parse(res.body);
  17. console.log(JSON.stringify(valores));
  18. if(valores.posx ==0 && valores.posy == 0){
  19. console.log("ENCONTRADO "+x+" "+y);
  20. console.log("LLAMADAS "+llamadas);
  21. }else if(valores.posx == 0){
  22. if(valores.posy>0){
  23. busca(x,Math.floor(y/2),maxx,y)
  24. }else{
  25. busca(x,y+Math.floor((maxy-y)/2),x,maxy);
  26. }
  27. }else if(valores.posy == 0){
  28. if(valores.posx>0){
  29. busca(Math.floor(x/2),y,x,maxy);
  30. }else{
  31. busca(x+Math.floor((maxx-x)/2),y,maxx,maxy);
  32. }
  33. }else{
  34. var bx,by,mx,my;
  35. if(valores.posx>0){
  36. bx=Math.floor(x/2);
  37. mx=x;
  38. }else{
  39. bx=x+Math.floor((maxx-x)/2);
  40. mx=maxx;
  41. }
  42.  
  43. if(valores.posy<0){
  44. by = Math.floor(y/2);
  45. my = y;
  46. }else{
  47. by = y+Math.floor((maxy-y)/2);
  48. my = maxy;
  49. }
  50.  
  51. //console.log("BUSCANDO: "+bx+" "+by+ " "+mx+" "+my);
  52. busca(bx,by,mx,my);
  53. }
  54. });
  55. }
  56.  
  57. var encontrado = false;
  58. var max=10000000;
  59. var i = max;
  60. var j= max;
  61. var llamadas = 0;
  62.  
  63. busca(i,j,max,max);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement