コード例 #1
0
        public FishPopulation()
        {
            this.CurrentFishIDCounter = 0;

            this.AllFish = new List <Tuple <int, string, int, int, int> >();

            foreach (KeyValuePair <int, string> item in Game1.content.Load <Dictionary <int, string> >("Data\\Fish"))
            {
                string[] fishFields = item.Value.Split('/');

                if (fishFields[1] != "trap" && fishFields[0] != "Green Algae" && fishFields[0] != "White Algae" && fishFields[0] != "Seaweed")
                {
                    this.AllFish.Add(new Tuple <int, string, int, int, int>(item.Key, fishFields[0] + " ", int.Parse(fishFields[3]), int.Parse(fishFields[4]), 1));
                }
                else if (fishFields[1] == "trap")
                {
                    this.TrapFish.Add(fishFields[0]);
                }
            }

            this.population = new Dictionary <string, List <FishModel> >();


            Random rand = new Random();

            for (int i = 0; i < this.AllFish.Count; i++)
            {
                List <FishModel> thisFishPopulation = new List <FishModel>();

                int populationSize = 50;

                for (int j = 0; j < populationSize; j++)
                {
                    string name      = this.AllFish[i].Item2;
                    int    minLength = this.AllFish[i].Item3;
                    int    maxLength = this.AllFish[i].Item4;

                    int    quality;
                    double r = rand.NextDouble();

                    if (r > 0.99)
                    {
                        quality = 4;
                    }
                    else if (r > 0.95)
                    {
                        quality = 2;
                    }
                    else if (r > 0.85)
                    {
                        quality = 1;
                    }
                    else
                    {
                        quality = 0;
                    }

                    double length = EvolutionHelpers.GetMutatedFishLength((maxLength + minLength) / 2, minLength, maxLength);

                    thisFishPopulation.Add(new FishModel(this.CurrentFishIDCounter, name, minLength, maxLength, length, quality));
                    this.CurrentFishIDCounter++;
                }

                this.population.Add(this.AllFish[i].Item2, thisFishPopulation);
            }
        }
コード例 #2
0
 public FishModel MakeBaby()
 {
     return(new FishModel(this.uniqueID, this.name, this.minLength, this.maxLength, EvolutionHelpers.GetMutatedFishLength(this.length, this.minLength, this.maxLength), this.quality));
 }