Example #1
0
        private void OnRouteUpdated()
        {
            RouteResults.Items.Clear();
            for (int i = 0; i < currentRoute.Count; i++)
            {
                RouteNode r = currentRoute[i];
                string    distanceToPrev = (i > 0) ? currentRoute[i - 1].Rare.Distance(r.Rare).ToString("0.00") : "N/A";

                ListViewItem newItem = new ListViewItem();
                newItem.Text = r.Rare.LocationName;
                newItem.SubItems.Add(i.ToString());
                newItem.SubItems.Add(r.Rare.Station);
                newItem.SubItems.Add(r.Rare.StationDistance);
                newItem.SubItems.Add(r.Rare.Name);
                newItem.SubItems.Add(distanceToPrev);
                if (currentRoute[i].SellHere.Count == 0)
                {
                    newItem.SubItems.Add("N/A");
                    newItem.SubItems.Add("N/A");
                }
                for (int j = 0; j < currentRoute[i].SellHere.Count; j++)
                {
                    RareGood s = currentRoute[i].SellHere[j];
                    newItem.SubItems.Add(s.Name);
                    newItem.SubItems.Add(s.Distance(r.Rare).ToString("0.00"));
                    if (j < currentRoute[i].SellHere.Count - 1)
                    {
                        RouteResults.Items.Add(newItem);
                        newItem      = new ListViewItem();
                        newItem.Text = "";
                        newItem.SubItems.Add("");
                        newItem.SubItems.Add("");
                        newItem.SubItems.Add("");
                        newItem.SubItems.Add("");
                        newItem.SubItems.Add("");
                    }
                }
                RouteResults.Items.Add(newItem);
            }
        }
Example #2
0
    public List <RouteNode> FindRoute(StarSystem currentSystem, float idealDistance, int jumpsPerLeg, int maxJumps)
    {
        RareGood closest = rares.OrderBy(r => currentSystem.Distance(r.Location)).FirstOrDefault();

        List <RouteNode> route = new List <RouteNode>();

        route.Add(new RouteNode(closest));
        List <RareGood> currentRares = new List <RareGood>();

        //float idealCutoff = 3.0f * idealDistance / 4.0f;
        while (route.Count < maxJumps)
        {
            RareGood current = route[route.Count - 1].Rare;
            currentRares.Add(current);
            RareGood next = rares.Where(delegate(RareGood r) {
                // Check to see if we've already visited this location in this leg
                if (currentRares.Contains(r))
                {
                    return(false);
                }

                // Check to see if this step is inefficient in the scope of the leg
                float distance = current.Distance(r);
                //if (distance > idealCutoff) { return false; }
                r.Fitness = distance;

                // Check to see if we have to sell here
                float sellOffsets = 0.0f;
                bool canSell      = false;
                foreach (RareGood s in currentRares)
                {
                    float toSeller = s.Distance(r);
                    if (toSeller >= idealDistance)
                    {
                        canSell = true;
                    }
                    sellOffsets -= (toSeller - idealDistance);
                }
                if (currentRares.Count == jumpsPerLeg && !canSell)
                {
                    return(false);
                }
                r.Fitness += sellOffsets / 10.0f;

                // This rare is valid
                return(true);
            }).OrderBy(r => r.Fitness).FirstOrDefault();
            if (next == null)
            {
                break;
            }
            List <RareGood> sellable = new List <RareGood>();
            foreach (RareGood r in currentRares)
            {
                if (next.Distance(r) >= idealDistance)
                {
                    sellable.Add(r);
                }
            }
            foreach (RareGood r in sellable)
            {
                currentRares.Remove(r);
            }
            route.Add(new RouteNode(next, sellable));
        }

        return(route);
    }