Beispiel #1
0
        public void OptimizeManifest()
        {
            while (capital > 0 && cargoSlots > 0)
            {
                //Score all trades
                foreach (Trade trade in trades)
                {
                    trade.ScoreTrade(capital, cargoSlots);
                }

                //Remove trades with 0 score.
                for (int x = 0; x < trades.Count; x++)
                {
                    if (trades[x].Score <= 0 && trades[x].UnitsBought == 0)
                    {
                        trades.RemoveAt(x);
                        x--;
                    }
                }

                //Find trade with max score that has not already been used for purchase.
                Trade maxScoreTrade = null;

                foreach (Trade trade in trades)
                {
                    if ((maxScoreTrade == null || trade.Score > maxScoreTrade.Score) && trade.UnitsBought == 0)
                    {
                        maxScoreTrade = trade;
                    }
                }

                //No valid trades exist to make more purchases. This manifest is done.
                if (maxScoreTrade == null)
                {
                    break;
                }

                //Purchase the commodity  and update the available capital and cargo slots.
                maxScoreTrade.UnitsBought = maxScoreTrade.AffordUnits(capital, cargoSlots);
                capital    = capital - (maxScoreTrade.UnitsBought * maxScoreTrade.Commodity.BuyPrice);
                cargoSlots = cargoSlots - maxScoreTrade.UnitsBought;
            }

            for (int x = 0; x < trades.Count; x++)
            {
                if (trades[x].UnitsBought == 0)
                {
                    trades.RemoveAt(x);
                    x--;
                }
            }

            if (capital <= 0)
            {
                limitingFactor = "Capital. Try to earn or invest more capital for more lucrative results.";
            }
            else if (cargoSlots <= 0)
            {
                limitingFactor = "Cargo Hold. Try to expand the cargo hold or buy a larger ship for more lucrative results.";
            }
            else
            {
                limitingFactor = "Lack of Trades. Try expanding your known galaxy by adding more systems, stations, and commodities.";
            }
        }