434 {
435 auto que = deque<point>();
436 que.push_front(start);
437 while(!que.empty()) {
438 const auto p = que.front();
439 que.pop_front();
441 point(p.x + 1, p.y, p.step),
point(p.x - 1, p.y, p.step),
442 point(p.x, p.y + 1, p.step),
point(p.x, p.y - 1, p.step)};
443 for(auto next: nexts) {
444 if(next.x == 0 && next.y == 0) {
445 return next.step;
446 }
447 if(0 <= next.x && next.x <= max_x + 2 && 0 <= next.y && next.y <= max_y + 2 &&
448 field[next.x][next.y] != 2) {
449 if(field[next.x][next.y] == 0) {
450 que.push_front(next);
451 } else {
452
453 next.step++;
454 que.push_back(next);
455 }
456 field[next.x][next.y] = 2;
457 }
458 }
459 }
461 }