void init(int pid, Coord c, const Map &map){ id = pid; size_t N = 4*(map.numRows()+map.numCols()); destroy(); front = new Front(N); frontNew = new Front(N); nStep = 1; front->push(c); map.mark(id, c) = 1; }
void step(Map &map){ frontNew->clear(); nStep++; while(!front->empty()){ const Coord &c = front->pop(); for(int dir = DirectionFirst+1; dir != DirectionLast; ++dir){ if (c.canStepTo(static_cast<Direction>(dir), map)){ Coord cNext = c.stepTo(static_cast<Direction>(dir)); if (!map.mark(id, cNext) && !map.isWall(cNext)){ map.mark(id, cNext) = nStep; frontNew->push(cNext); } } } } Front *f = front; front = frontNew; frontNew = f; }