Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. Posicio bfs(int equip, int id, int& distancia, Posicio& fin) {
  2. Mapa mapa(60, Fila(60, false));
  3. Matriu M(60, Fila2(60, -1));
  4. Info i = dades(id); //i = todo lo que tiene info.
  5. queue<Posicio> q; // cola de pair <int, int>
  6. q.push(i.pos);
  7. Posicio aux;
  8. M[i.pos.x][i.pos.y]= 0;
  9. Posicio fi = aux;
  10. while (not q.empty()) {
  11. aux = q.front();
  12. q.pop();
  13. for (int i = 0; i < 8; ++i) {
  14. Posicio aux2;
  15. aux2.x = aux.x + X[i];
  16. aux2.y = aux.y + Y[i];
  17. if (valid(aux2.x,aux2.y)) {
  18. if (not mapa[aux2.x][aux2.y]){
  19. if ((que(aux2.x, aux2.y) == BOSC or que(aux2.x, aux2.y) == GESPA) and temps_foc(aux2.x, aux2.y) == 0) {
  20. int id_post = de_qui_post(aux2.x, aux2.y);
  21. M[aux2.x][aux2.y]= M[aux.x][aux.y]+1;
  22.  
  23. q.push(aux2);
  24. if (id_post >= 0 and id_post != equip) {
  25. distancia = M[aux2.x][aux2.y];
  26. fin.x = aux2.x;
  27. fin.y = aux2.y;
  28. return aux2;
  29. }
  30. }
  31. mapa[aux2.x][aux2.y] = true;
  32. }
  33. }
  34. }
  35. }
  36. return fi;
  37. }
  38.  
  39.  
  40. Posicio bfs2(int equip, int id, int& distancia, Posicio fin, int x, int y) {
  41. Mapa mapa(60, Fila(60, false));
  42. Matriu M(60, Fila2(60, -1));
  43. Info i = dades(id); //i = todo lo que tiene info.
  44. queue<Posicio> q; // cola de pair <int, int>
  45. Posicio ara;
  46. ara.x = x;
  47. ara.y = y;
  48. q.push(ara);
  49. Posicio aux;
  50. M[x][y]= 0;
  51. Posicio fi = aux;
  52. while (not q.empty()) {
  53. aux = q.front();
  54. q.pop();
  55. for (int i = 0; i < 8; ++i) {
  56. Posicio aux2;
  57. aux2.x = aux.x + X[i];
  58. aux2.y = aux.y + Y[i];
  59. if (valid(aux2.x,aux2.y)) {
  60. if (not mapa[aux2.x][aux2.y]){
  61. if ((que(aux2.x, aux2.y) == BOSC or que(aux2.x, aux2.y) == GESPA) and temps_foc(aux2.x, aux2.y) == 0) {
  62. int id_post = de_qui_post(aux2.x, aux2.y);
  63. M[aux2.x][aux2.y]= M[aux.x][aux.y]+1;
  64.  
  65. q.push(aux2);
  66. if (fin.x == aux2.x and fin.y == aux2.y) {
  67. distancia = M[aux2.x][aux2.y];
  68. return aux2;
  69. }
  70. }
  71. mapa[aux2.x][aux2.y] = true;
  72. }
  73. }
  74. }
  75. }
  76. return fi;
  77. }
  78.  
  79. void juga_soldat(int equip, int id) {
  80. int distancia = 0;
  81. int dist_actual = 0;
  82. Info i = dades(id);
  83. Posicio actual;
  84. Posicio fin;
  85. actual.x = i.pos.x;
  86. actual.y = i.pos.y;
  87. Posicio mou = bfs(equip, id, dist_actual, fin);
  88. for (int i = 0; i < 8; ++i) {
  89. Posicio nova = bfs2(equip, id, distancia, fin, actual.x + X[i], actual.y + Y[i]);
  90. if (distancia < dist_actual) {
  91. ordena_soldat(id, actual.x + X[i], actual.y + Y[i]);
  92. return;
  93. }
  94. }
  95. ataca(equip, id, i);
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement