// --- QGAMES::Position SabreWulfScene::limitPosition (int mn, const QGAMES::Position& pos, const QGAMES::Vector& or) { // If the orientation has no a valid value... // It is not possible to continue... QGAMES::Position result = pos; if (or == QGAMES::Vector::_cero) return (result); // Select all zones valid... Locations vLocs; QGAMES::Rectangle l = QGAMES::Rectangle::_noRectangle; SabreWulfScene::Locations locs = calculateLocations (mn); for (int i = 0; i < (int) locs.size (); i++) if (locs [i]._zone.hasIn (pos)) vLocs [i] = locs [i]; if (vLocs.empty ()) return (result); // Incredible, but it could happen. Sabreman movements take into account // the position of the corner most oriented to the movement // When this method is calling, the position could be any! bool found = false; while (!found) { for (Locations::const_iterator j = vLocs.begin (); j != vLocs.end () && !found; j++) if (!(*j).second._zone.hasIn (result)) // The minimum zone... found = true; if (!found) result += or; } return (result); }
std::vector<int> getPath(const Locations& input) { if(input.empty()) return {}; Locations locations(input); std::vector<int> results; Locations::iterator current = locations.begin(); do { Position curPos = current->second; results.push_back(current->first); locations.erase(current); current = findClosest(curPos, locations); } while(!locations.empty()); return results; }