Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <windows.h>
  5. #define QUADRADO 10
  6. #define robo_x 30
  7. #define robo_y 30
  8. #define zero 0
  9. #define um 1
  10.  
  11. void pensar(float x, float y, float angulo, float distancia_sensor);
  12. void ocupados(int cateto_o, int cateto_a);
  13. void livre(int x0, int y0, int x1, int y1);
  14. void mostrar_mapa(void);
  15.  
  16. // cada quadrado == 10 cm
  17. int mapa[60][60] = {0}; // 6x6 metros
  18.  
  19. int main(void){
  20. pensar(robo_x, robo_y, 120.2,10.34);
  21. return 0;
  22. }
  23.  
  24. void pensar(float x, float y, float alfa, float distancia_sensor){
  25.  
  26. int largura, altura;
  27. largura = (int) (x/QUADRADO); // casting of float for int
  28. altura = (int) (y/QUADRADO); // casting of float for int
  29.  
  30. int cateto_oposto, cateto_adjacente = 0;
  31. cateto_oposto = (int) (sin(alfa) * distancia_sensor)/QUADRADO; // altura == linhas
  32. cateto_adjacente = (int) (cos(alfa) * distancia_sensor)/QUADRADO; // largura == colunas
  33.  
  34. ocupados(cateto_oposto, cateto_adjacente);
  35. livre(robo_x, robo_y, cateto_adjacente, cateto_oposto);
  36.  
  37. }
  38.  
  39. void ocupados(int cateto_o, int cateto_a){
  40.  
  41. mapa[cateto_o][cateto_a]+=2;
  42.  
  43. if(mapa[cateto_o][cateto_a] > 10)
  44. mapa[cateto_o][cateto_a] = 10;
  45. }
  46.  
  47. // x0 e y0 == posição do robo
  48. // x1 e x2 == posição do objeto
  49. void livre(int x0, int y0, int x1, int y1){
  50.  
  51. int dx = abs(x1-x0), sx = x0<x1 ? 1 : -1;
  52. int dy = abs(y1-y0), sy = y0<y1 ? 1 : -1;
  53. int err = (dx>dy ? dx : -dy)/2, e2;
  54.  
  55. for(;;){
  56. mapa[y0][x0]-=1;
  57.  
  58. if(mapa[y0][x0] < -10)
  59. mapa[y0][x0] =-10;
  60.  
  61. if (x0==x1 && y0==y1) break;
  62. e2 = err;
  63. if (e2 >-dx) { err -= dy; x0 += sx; }
  64. if (e2 < dy) { err += dx; y0 += sy; }
  65. }
  66.  
  67. }
  68.  
  69. void mostrar_mapa(void){
  70.  
  71. int i,j = 0;
  72.  
  73. for(i=0;i<60;i++){
  74. for(j=0;j<60;j++){
  75. if(mapa[i][j] <= 0)
  76. printf(zero);
  77. else
  78. printf(um);
  79. }
  80. printf("\n");
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement