laserkestrel / starmap

Other
0 stars 0 forks source link

visitedStarSystems change to unordered map #7

Open laserkestrel opened 10 months ago

laserkestrel commented 10 months ago

can have each probe maintain a private unordered map to track all the stars it has visited. You can then iterate through this map and replicate each visited star's information to a new probe. Here's how you can do it:

class Probe {
public:
    void addVisitedStar(const std::string& starName, double x, double y) {
        visitedStarSystems[starName] = {x, y};
    }

    void replicateToNewProbe(Probe& newProbe) {
        for (const auto& entry : visitedStarSystems) {
            newProbe.addVisitedStar(entry.first, entry.second.x, entry.second.y);
        }
    }

private:
    std::unordered_map<std::string, StarInfo> visitedStarSystems;
};

In the Probe class:

The addVisitedStar method is used to add visited stars to the probe's private unordered map.

The replicateToNewProbe method takes a reference to a new probe (newProbe) as an argument and iterates through the visited stars stored in the current probe's map. For each visited star, it adds a corresponding entry to the newProbe's map using the addVisitedStar method.

By doing this, you can replicate the visited stars from one probe to another efficiently, ensuring that the new probe has the same information about the stars the original probe has visited.