Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Posicio bfs(int equip, int id, int& distancia, Posicio& fin) {
- Mapa mapa(60, Fila(60, false));
- Matriu M(60, Fila2(60, -1));
- Info i = dades(id); //i = todo lo que tiene info.
- queue<Posicio> q; // cola de pair <int, int>
- q.push(i.pos);
- Posicio aux;
- M[i.pos.x][i.pos.y]= 0;
- Posicio fi = aux;
- while (not q.empty()) {
- aux = q.front();
- q.pop();
- for (int i = 0; i < 8; ++i) {
- Posicio aux2;
- aux2.x = aux.x + X[i];
- aux2.y = aux.y + Y[i];
- if (valid(aux2.x,aux2.y)) {
- if (not mapa[aux2.x][aux2.y]){
- if ((que(aux2.x, aux2.y) == BOSC or que(aux2.x, aux2.y) == GESPA) and temps_foc(aux2.x, aux2.y) == 0) {
- int id_post = de_qui_post(aux2.x, aux2.y);
- M[aux2.x][aux2.y]= M[aux.x][aux.y]+1;
- q.push(aux2);
- if (id_post >= 0 and id_post != equip) {
- distancia = M[aux2.x][aux2.y];
- fin.x = aux2.x;
- fin.y = aux2.y;
- return aux2;
- }
- }
- mapa[aux2.x][aux2.y] = true;
- }
- }
- }
- }
- return fi;
- }
- Posicio bfs2(int equip, int id, int& distancia, Posicio fin, int x, int y) {
- Mapa mapa(60, Fila(60, false));
- Matriu M(60, Fila2(60, -1));
- Info i = dades(id); //i = todo lo que tiene info.
- queue<Posicio> q; // cola de pair <int, int>
- Posicio ara;
- ara.x = x;
- ara.y = y;
- q.push(ara);
- Posicio aux;
- M[x][y]= 0;
- Posicio fi = aux;
- while (not q.empty()) {
- aux = q.front();
- q.pop();
- for (int i = 0; i < 8; ++i) {
- Posicio aux2;
- aux2.x = aux.x + X[i];
- aux2.y = aux.y + Y[i];
- if (valid(aux2.x,aux2.y)) {
- if (not mapa[aux2.x][aux2.y]){
- if ((que(aux2.x, aux2.y) == BOSC or que(aux2.x, aux2.y) == GESPA) and temps_foc(aux2.x, aux2.y) == 0) {
- int id_post = de_qui_post(aux2.x, aux2.y);
- M[aux2.x][aux2.y]= M[aux.x][aux.y]+1;
- q.push(aux2);
- if (fin.x == aux2.x and fin.y == aux2.y) {
- distancia = M[aux2.x][aux2.y];
- return aux2;
- }
- }
- mapa[aux2.x][aux2.y] = true;
- }
- }
- }
- }
- return fi;
- }
- void juga_soldat(int equip, int id) {
- int distancia = 0;
- int dist_actual = 0;
- Info i = dades(id);
- Posicio actual;
- Posicio fin;
- actual.x = i.pos.x;
- actual.y = i.pos.y;
- Posicio mou = bfs(equip, id, dist_actual, fin);
- for (int i = 0; i < 8; ++i) {
- Posicio nova = bfs2(equip, id, distancia, fin, actual.x + X[i], actual.y + Y[i]);
- if (distancia < dist_actual) {
- ordena_soldat(id, actual.x + X[i], actual.y + Y[i]);
- return;
- }
- }
- ataca(equip, id, i);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement