Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Posicio bfs(int i, int j) {
- bool trobat = false;
- queue< Posicio > q;
- q.push(Posicio(i, j));
- Graf g (60, vector<pair<char,Posicio> > (60));
- int primer = 0;
- while (not q.empty()) {
- Posicio pos = q.front(); q.pop();
- if (quin_soldat(pos.x,pos.y) > 0) {return g[pos.x][pos.y].second;}
- if (valor_post(pos.x,pos.y) > 0) {return g[pos.x][pos.y].second;}
- g[pos.x][pos.y].first = 'X';
- for(int i=0; i<8; ++i)
- {
- int a = pos.x+X[i], b = pos.y+Y[i];
- if(valid(a, b) and g[a][b].first != 'X' and (que(a,b) == GESPA or que(a,b) == BOSC)) {
- q.push(Posicio(a, b));
- if (primer < 8) {
- g[a][b].second.x = a;
- g[a][b].second.y = b;
- } else {
- g[a][b].second.x = g[pos.x][pos.y].second.x;
- g[a][b].second.y = g[pos.x][pos.y].second.y;
- }
- }
- ++primer;
- }
- }
- return Posicio(-1,-1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement