public static Gene CreateEconomyGeneVariations() { // Assign probabilities int workerPercentage = 25; int survivorPercentage = 25; int thiefPercentage = 25; int sumNonMurderers = workerPercentage + survivorPercentage + thiefPercentage; //int murdererPercentage = 100 - sumNonMurderers; // init gene randomly var rand = RandomHelper.StandardGeneratorInstance.Next(0, 100); EconomyGene geneValue = EconomyGene.Fungal; if (rand < workerPercentage) { geneValue = EconomyGene.Worker; } else if (rand < workerPercentage + survivorPercentage) { geneValue = EconomyGene.Survivor; } else if (rand < sumNonMurderers) { geneValue = EconomyGene.Thief; } return(CreateEconomyGene(geneValue)); }
/// <summary> /// Economy Gene: /// 1. Worker - will cultivate resources, never steals. /// 2. Survivor - will cultivate resources. If none available might steal. /// 3. Thief - Steals first. Steals partial resources not all. Cultivates if there is nothing to steal. /// 4. Murderer - steals from others and kills them, taking all resources. /// </summary> public static Gene CreateEconomyGene(EconomyGene geneValue = EconomyGene.Worker) { int value = (int)geneValue; // ReSharper disable once UseObjectOrCollectionInitializer var gene = new Gene { GeneDescription = GeneEnum.Economy.ToString(), LastValue = value, Minimum = 1, Maximum = Enum.GetNames(typeof(EconomyGene)).Length, CanMutate = true, IsDormant = false, GeneType = GeneEnum.Economy }; gene.CurrentValue = value; return(gene); }
/// <summary> /// Economy Match Score = 0-100 /// Fungal types will join anyone. /// Workers and survivors will join each other. Higher rate if both organisms are identical /// Thieves only join thieves. /// All non-fungals may still accept to join fungals because of the strength in numbers. More so in case of thieves since they are stealing /// any way and greater numbers works better and hardly much resources are lost to fungals. /// </summary> private double GetEconomyMatchPercentage(Organism curOrganism, Organism vicinityOrganism) { EconomyGene currentOrganismEconomy = curOrganism.IsInGroup ? curOrganism.Group.GroupEconomyGene : (EconomyGene)curOrganism.GetGeneValueByType(GeneEnum.Economy); EconomyGene vicinityOrganismEconomy = vicinityOrganism.IsInGroup ? vicinityOrganism.Group.GroupEconomyGene : (EconomyGene)vicinityOrganism.GetGeneValueByType(GeneEnum.Economy); switch (currentOrganismEconomy) { default: return(0); case EconomyGene.Fungal: // Fungal types always want to join return(EjFungal); case EconomyGene.Worker: switch (vicinityOrganismEconomy) { default: return(0); case EconomyGene.Fungal: return(EjWorkerFungal); case EconomyGene.Worker: return(EjWorkerWorker); case EconomyGene.Survivor: return(EjWorkerSurvivor); } case EconomyGene.Survivor: switch (vicinityOrganismEconomy) { default: return(0); case EconomyGene.Fungal: return(EjSurvivorFungal); case EconomyGene.Worker: return(EjSurvivorWorker); case EconomyGene.Survivor: return(EjSurvivorSurvivor); } case EconomyGene.Thief: switch (vicinityOrganismEconomy) { default: return(0); case EconomyGene.Fungal: return(EjThiefFungal); case EconomyGene.Thief: return(EjThiefThief); } } }