public IHttpActionResult PutPopulationType(string id, PopulationType populationType)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != populationType.PopulationType1)
            {
                return(BadRequest());
            }

            db.Entry(populationType).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PopulationTypeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#2
0
 public Population(Civilization civlization, Upkeep upkeep, Beliefs beliefs, PopulationType startingType)
 {
     Civilization   = civlization;
     Upkeep         = upkeep;
     Beliefs        = beliefs;
     PopulationType = startingType;
 }
        public IHttpActionResult PostPopulationType(PopulationType populationType)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.PopulationTypes.Add(populationType);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (PopulationTypeExists(populationType.PopulationType1))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = populationType.PopulationType1 }, populationType));
        }
 void SetupPopulatedTilesArray()
 {
     populatedTiles = new PopulationType[columns][];
     for (int i = 0; i < populatedTiles.Length; i++)
     {
         populatedTiles[i] = new PopulationType[rows];
     }
 }
示例#5
0
    private void SetupPopulatedTilesArray()
    {
        populatedTiles = new PopulationType[roomWidth][];

        for (int i = 0; i < populatedTiles.Length; i++)
        {
            populatedTiles[i] = new PopulationType[roomHeight];
        }
    }
        public IHttpActionResult GetPopulationType(string id)
        {
            PopulationType populationType = db.PopulationTypes.Find(id);

            if (populationType == null)
            {
                return(NotFound());
            }

            return(Ok(populationType));
        }
示例#7
0
        public ResourceSegment(PopulationType type, PlayerBoard board)
        {
            var msg = "Storage: {0}[placeholder]</br>Production: {1}</br>Next Production: {2}";
            msg = String.Format(msg, board.GetStorage(type), board.GetProduction(type), board.GetNextProduction(type));
            if (type == PopulationType.Money)
               msg= msg.Replace("[placeholder]", "</br>Production less upkeep: " + (board.GetProduction(PopulationType.Money) - board.GetUpkeep()).ToString());
            else
                msg = msg.Replace("[placeholder]", "");

            Description = msg;

            Name = type.ToString();
        }
示例#8
0
    public Faction(FactionSdo sdo)
    {
        Religions         = new Dictionary <string, int>();
        EntitiesWithFluff = new List <Entity>();

        PopType           = sdo.PopType;
        FactionReputation = sdo.FactionReputation;
        Citizens          = new List <Entity>();
        EntitiesWithFluff = new List <Entity>();
        Name       = sdo.Name;
        Population = sdo.Population;
        Leader     = EntitySdo.ConvertToEntity(sdo.Leader);

        if (Leader == null)
        {
            Debug.Log($@"Leader missing for faction {Name}");
        }

        foreach (var id in sdo.CitizenIds)
        {
            if (!WorldData.Instance.Entities.ContainsKey(id))
            {
                continue;
            }

            var citizen = WorldData.Instance.Entities[id];
            citizen.Faction = this;
            Citizens.Add(citizen);
        }

        foreach (var id in sdo.EntitiesWithFluffIds)
        {
            if (!WorldData.Instance.Entities.ContainsKey(id))
            {
                continue;
            }

            var entity = WorldData.Instance.Entities[id];
            EntitiesWithFluff.Add(entity);
        }

        if (Leader != null && !WorldData.Instance.Entities.ContainsKey(Leader.Id))
        {
            WorldData.Instance.Entities[Leader.Id] = Leader;
        }

        if (!EntitiesWithFluff.Contains(Leader))
        {
            EntitiesWithFluff.Add(Leader);
        }
    }
        public IHttpActionResult DeletePopulationType(string id)
        {
            PopulationType populationType = db.PopulationTypes.Find(id);

            if (populationType == null)
            {
                return(NotFound());
            }

            db.PopulationTypes.Remove(populationType);
            db.SaveChanges();

            return(Ok(populationType));
        }
示例#10
0
        public void RunEvolution()
        {
            GeneticAlgorithmParameters parameters = new GeneticAlgorithmParameters(
                populationSize: 10,
                mutationRate: 0.3,
                mutationAmplitute: 0.5);

            //PopulationType specimenType = PopulationType.Arithmetic1D;
            PopulationType specimenType = PopulationType.Arithmetic15D;

            PopulationSetting populationSetting;

            switch (specimenType)
            {
            case (PopulationType.Arithmetic1D):
                populationSetting = new Arithmetic1DPopulation((s) => (Math.Pow(s.Genes[0] - 10, 2) + 5));
                break;

            case (PopulationType.Arithmetic2D):
                populationSetting = new Arithmetic2DPopulation((s) => (Math.Pow((s.Genes[0] + 2 * s.Genes[1] - 7), 2) + Math.Pow((2 * s.Genes[0] + s.Genes[1] - 5), 2)));
                break;

            case (PopulationType.Arithmetic15D):
                populationSetting = new Arithemtic15DPopulation((s) => GetResultOfFitFunctionForMultidimensionalFucntion(s));
                break;

            default: throw new Exception("Тип особей, для которых запускается симуляция, не задан! Завершение работы...");
            }

            geneticAlgorithm = new GeneticAlgorithm(parameters, populationSetting);

            for (int i = 0; i < 5000; i++)
            {
                geneticAlgorithm.NewGeneration();
                //Console.WriteLine();
                //Console.WriteLine("Поколение: " + geneticAlgorithm.GenerationNum);
                //ShowPopulation(geneticAlgorithm.CurrentGeneration);
                //ShowBestInGeneration(geneticAlgorithm.CurrentGeneration, populationSetting);
            }
            ShowBestOfAllTime(geneticAlgorithm.allGenerations, populationSetting);
        }
示例#11
0
 public bool HasAdvancedTechnology(PopulationType type)
 {
     return HasTechnology("Advanced " + type.ToString());
 }
示例#12
0
 public PopulationSquare(PopulationType type)
 {
     Type = type;
 }
示例#13
0
 private void LogNetProductionBefore(PopulationType popType)
 {
     _beforeLog = GetProduction(popType);
         if(popType==PopulationType.Money)
             _beforeLog -= GetUpkeep();
 }
示例#14
0
 private void LogNetProductionAfter(PopulationType popType)
 {
     var after = GetProduction(PopulationType.Money);
     if(popType==PopulationType.Money)
         after -= GetUpkeep();
     AddLogLine("Net " + popType+ " Production: " + SignedNumber(_beforeLog, after));
 }
示例#15
0
 private void AdjustPop(PopulationType type, int adjust)
 {
     LogNetProductionBefore(type);
     PopulationsCubes[type] += adjust;
     LogNetProductionAfter(type);
 }
示例#16
0
 public void SetStorage(PopulationType type, int value)
 {
     Storage[type] = value;
 }
示例#17
0
 public void RemovePop(PopulationType type)
 {
     AdjustPop(type, -1);
 }
示例#18
0
 public int GetStorage(PopulationType type)
 {
     return Storage[type];
 }
示例#19
0
 public bool CanSupportPopulation(PopulationType type)
 {
     return((double)this.MaxPopulationMod[(int)type] > 0.0);
 }
示例#20
0
 public String GetCurrentStorageDescription(PopulationType type)
 {
     return String.Format("{0} Storage: {1}", type, GetStorage(type));
 }
示例#21
0
 public String GetCurrentProductionDescription(PopulationType type)
 {
     return  String.Format("Net {0} Production: {1}", type.ToString(), GetNetProduction(type));
 }
示例#22
0
 public void AdjustStorage(PopulationType type, int adjustment)
 {
     var before = Storage[type];
     Storage[type] += adjustment;
     var after = Storage[type];
     AddLogLine(type.ToString() + " Storage: " + SignedNumber(before, after));
 }
示例#23
0
 public void AddPopulationCube(PopulationType type)
 {
     if (type == PopulationType.Unknown)
         throw new NotImplementedException();
     PopulationsCubes[type]++;
 }
示例#24
0
 public int GetNetProduction(PopulationType t)
 {
     if (t == PopulationType.Money)
     {
         return GetProduction(PopulationType.Money) - GetUpkeep();
     }
     else
         return GetProduction(t);
 }
示例#25
0
 public Job(PopulationType jobType, int totalSlots)
 {
     JobType       = jobType;
     TotalJobSlots = totalSlots;
 }
示例#26
0
 public int GetProduction(PopulationType type)
 {
     return GetProductionLevel(PopulationsCubes[type]);
 }
示例#27
0
    private void PickPopulationType()
    {
        var roll = Random.Range(0, 100);

        PopType = roll <= 40 ? PopulationType.MixedSpecies : PopulationType.Monospecies;
    }