Exemplo n.º 1
0
    private int GetGeneValuesCount(GeneType geneType)
    {
        GeneScriptableObject geneScriptableObject = GetGeneFromType(geneType);

        return(geneScriptableObject.Values.Count);
    }
Exemplo n.º 2
0
        public void Draw(SpriteBatch sb)
        {
            float buildPhase = (BuildTime - buildTimer) / (float)BuildTime;

            if (buildTimer == 0)
            {
                sb.Draw(Textures[0], ScreenLocation, null, Color.White, 0, texOrigin, 1, SpriteEffects.None, 0);

                if (GeneSpecs.HasAny)
                {
                    GeneType gt           = GeneSpecs.GetPrimaryElem();
                    int      geneIdx      = (int)gt - 1;
                    Color    geneUpgColor = Color.DarkGray;
                    switch (gt)
                    {
                    case GeneType.Red: geneUpgColor = Color.Red; break;

                    case GeneType.Green: geneUpgColor = Color.Green; break;

                    case GeneType.Blue: geneUpgColor = Color.Blue; break;
                    }
                    Vector2 firstLocation = new Vector2(ScreenLocation.X + CurrentGame.ball.Width / 2 - GeneSpecs.BaseTiers[geneIdx] * 11 / 2, ScreenLocation.Y - ParentMap.TileHalfHeight);
                    for (int i = 0; i < GeneSpecs.BaseTiers[geneIdx]; i++)
                    {
                        sb.Draw(CurrentGame.ball, firstLocation + new Vector2(i * 11, 0), geneUpgColor);
                    }
                }
            }
            else if (IsExample)
            {
                sb.Draw(Textures[0], ScreenLocation, null, Color.White * 0.6f, 0, texOrigin, 1, SpriteEffects.None, 0);
            }

            if (buildFinishedCounter > 0 && buildTimer < BuildTime)
            {
                #region UGLY OUTLINE ANIMATION
                Color lineColor   = buildTimer == 0? Color.White : Color.GreenYellow;
                Color borderColor = Color.Black * 0.4f;
                lineColor   *= buildFinishedCounter / (float)buildFinishedInit;
                borderColor *= buildFinishedCounter / (float)buildFinishedInit;

                sb.Draw(CurrentGame.pixel, new Rectangle((int)(ScreenLocation.X - ParentMap.TileWidth / 4 - 1), (int)ScreenLocation.Y - ParentMap.TileHeight / 2 - 1, ParentMap.TileWidth / 2, 4),
                        null, borderColor, 0f, Vector2.Zero, SpriteEffects.None, 0);
                sb.Draw(CurrentGame.pixel, new Rectangle((int)(ScreenLocation.X + ParentMap.TileWidth / 4 + 2), (int)ScreenLocation.Y - ParentMap.TileHeight / 2, ParentMap.TileWidth / 2, 4),
                        null, borderColor, MathHelper.ToRadians(60.9f), Vector2.Zero, SpriteEffects.None, 0);
                sb.Draw(CurrentGame.pixel, new Rectangle((int)(ScreenLocation.X + ParentMap.TileWidth / 2 + 1), (int)ScreenLocation.Y, ParentMap.TileWidth / 2, 4),
                        null, borderColor, MathHelper.ToRadians(118.2f), Vector2.Zero, SpriteEffects.None, 0);
                sb.Draw(CurrentGame.pixel, new Rectangle((int)(ScreenLocation.X + ParentMap.TileWidth / 4 + 1), (int)ScreenLocation.Y + ParentMap.TileHeight / 2 + 2, ParentMap.TileWidth / 2 + 1, 4),
                        null, borderColor, (float)Math.PI, Vector2.Zero, SpriteEffects.None, 0);
                sb.Draw(CurrentGame.pixel, new Rectangle((int)(ScreenLocation.X - ParentMap.TileWidth / 4 - 2), (int)ScreenLocation.Y + ParentMap.TileHeight / 2 + 2, ParentMap.TileWidth / 2 + 1, 4),
                        null, borderColor, MathHelper.ToRadians(240.8f), Vector2.Zero, SpriteEffects.None, 0);
                sb.Draw(CurrentGame.pixel, new Rectangle((int)(ScreenLocation.X - ParentMap.TileWidth / 2 - 1), (int)ScreenLocation.Y, ParentMap.TileWidth / 2, 4),
                        null, borderColor, (float)Math.PI * (5 / 3f), Vector2.Zero, SpriteEffects.None, 0);

                sb.Draw(CurrentGame.pixel, new Rectangle((int)(ScreenLocation.X - ParentMap.TileWidth / 4 - 1), (int)(ScreenLocation.Y - ParentMap.TileHeight / 2),
                                                         (int)Math.Min(ParentMap.TileWidth / 2, ParentMap.TileWidth / 2 * buildPhase * 6), 2), lineColor);
                if (buildPhase >= 1 / 6f)
                {
                    sb.Draw(CurrentGame.pixel, new Vector2(ScreenLocation.X + ParentMap.TileWidth / 4 + 1, ScreenLocation.Y - ParentMap.TileHeight / 2), null, lineColor, MathHelper.ToRadians(60.9f),
                            Vector2.Zero, new Vector2(Math.Min(ParentMap.TileWidth / 2, ParentMap.TileWidth / 2 * (buildPhase - 1 / 6f) * 6), 2), SpriteEffects.None, 0);
                }
                if (buildPhase >= 2 / 6f)
                {
                    sb.Draw(CurrentGame.pixel, new Vector2(ScreenLocation.X + ParentMap.TileWidth / 2, ScreenLocation.Y), null, lineColor, MathHelper.ToRadians(118.2f) /*(float)Math.PI * (1.98f / 3f)*/, //118.95f
                            Vector2.Zero, new Vector2(Math.Min(ParentMap.TileWidth / 2, ParentMap.TileWidth / 2 * (buildPhase - 2 / 6f) * 6), 2), SpriteEffects.None, 0);
                }
                if (buildPhase >= 3 / 6f)
                {
                    sb.Draw(CurrentGame.pixel, new Vector2(ScreenLocation.X + ParentMap.TileWidth / 4, ScreenLocation.Y + ParentMap.TileHeight / 2 + 1), null, lineColor, (float)Math.PI,
                            Vector2.Zero, new Vector2(Math.Min(ParentMap.TileWidth / 2, ParentMap.TileWidth / 2 * (buildPhase - 3 / 6f) * 6), 2), SpriteEffects.None, 0);
                }
                if (buildPhase >= 4 / 6f)
                {
                    sb.Draw(CurrentGame.pixel, new Vector2(ScreenLocation.X - ParentMap.TileWidth / 4 - 1, ScreenLocation.Y + ParentMap.TileHeight / 2 + 1), null, lineColor, MathHelper.ToRadians(240.8f),//(float)Math.PI * (4f / 3f)
                            Vector2.Zero, new Vector2(Math.Min(ParentMap.TileWidth / 2, ParentMap.TileWidth / 2 * (buildPhase - 4 / 6f) * 6), 2), SpriteEffects.None, 0);
                }
                if (buildPhase >= 5 / 6f)
                {
                    sb.Draw(CurrentGame.pixel, new Vector2(ScreenLocation.X - ParentMap.TileWidth / 2, ScreenLocation.Y), null, lineColor, (float)Math.PI * (5 / 3f),
                            Vector2.Zero, new Vector2(Math.Min(ParentMap.TileWidth / 2 - 1, ParentMap.TileWidth / 2 * (buildPhase - 5 / 6f) * 6), 2), SpriteEffects.None, 0);
                }
                #endregion
            }

            if (ShowRadius || radiusFade > 0) //-------------------RADIUS
            {
                if (ShowRadius && radiusFade < radiusFadeCycles)
                {
                    radiusFade++;
                }
                else if (!ShowRadius)
                {
                    radiusFade--;
                }

                if (radiusFade > 0)
                {
                    if (Range == InitRange)
                    {
                        sb.Draw(radiusTextures[0], new Rectangle((int)(ScreenLocation.X - radiusTextures[0].Width / 2), (int)(ScreenLocation.Y - radiusTextures[0].Height / 2), radiusTextures[0].Width, radiusTextures[0].Height), Color.White * (radiusFade / radiusFadeCycles));
                    }
                    else
                    {
                        sb.Draw(radiusTextures[0], new Rectangle((int)(ScreenLocation.X - radiusTextures[0].Width / 2), (int)(ScreenLocation.Y - radiusTextures[0].Height / 2), radiusTextures[0].Width, radiusTextures[0].Height), Color.White * (radiusFade / radiusFadeCycles) * 0.5f);
                        sb.Draw(radiusTextures[1], new Rectangle((int)(ScreenLocation.X - radiusTextures[1].Width / 2), (int)(ScreenLocation.Y - radiusTextures[1].Height / 2), radiusTextures[1].Width, radiusTextures[1].Height), Color.White * (radiusFade / radiusFadeCycles));
                    }
                }
            }
        }
Exemplo n.º 3
0
 public static Rational selectionProb(GeneType g, Population pop)
 {
     return(new Rational(pop [g], pop.Values.Aggregate((a, b) => a + b)));
 }
Exemplo n.º 4
0
    public List <int> PriorityOrder = new List <int>(); //priority order for this gene type (lower index = higher priority)

    public GeneResolution(GeneType geneType)
    {
        GeneType = geneType;
    }
Exemplo n.º 5
0
Arquivo: Run.cs Projeto: wintonpc/Quqe
        public static ProtoGene Create(string name, double minValue, double maxValue, GeneType type)
        {
            switch (type)
            {
            case GeneType.Discrete: return(new ProtoGene(name, minValue, maxValue, 1, false));

            case GeneType.Continuous: return(new ProtoGene(name, minValue, maxValue, 0.00001, false));

            default: throw new Exception("Unexpected type: " + type);
            }
        }
Exemplo n.º 6
0
        public void TakeAHit(Bullet bullet)
        {
            if (Alive)
            {
                float hpLoss;
                if (ElemArmors.HasAny)
                {
                    GeneType bulletPrimarySpec    = bullet.ElemSpecs.GetPrimaryElem();
                    GeneType creaturePrimaryArmor = ElemArmors.GetPrimaryElem();
                    float    bStr = bullet.ElemSpecs.GetPrimaryElemStrength();
                    float    cArm = ElemArmors.GetPrimaryElemStrength();
                    float    armorReducedNormalDmg = (bullet.dmg * (1 - bStr)) * (1 - cArm); // normal vs armor = (dmg * (1-spec)) * (1-armor)
                    float    penetratingDmg        = bullet.dmg * bStr;                      //----------------------- penetration = dmg * specialization

                    if (bulletPrimarySpec == creaturePrimaryArmor)                           // match
                    {
                        hpLoss = penetratingDmg + armorReducedNormalDmg;
                    }
                    else                     // uncompatible bullet
                    {
                        hpLoss = armorReducedNormalDmg;
                    }
                }
                else if (bullet.ElemSpecs.HasAny)                 // if just the bullet has specialization
                {
                    float bStr = bullet.ElemSpecs.GetPrimaryElemStrength();
                    hpLoss = bullet.dmg * (1 - bStr);
                }
                else
                {
                    hpLoss = bullet.dmg;
                }

                if (hp - hpLoss <= 0)
                {
                    hp    = 0;
                    Alive = false;
                    ParentMap.Players[0].GenePoints[0] += (int)Math.Round(ElemArmors[GeneType.Red] * 10);
                    ParentMap.Players[0].GenePoints[1] += (int)Math.Round(ElemArmors[GeneType.Green] * 10);
                    ParentMap.Players[0].GenePoints[2] += (int)Math.Round(ElemArmors[GeneType.Blue] * 10);
                    CurrentGame.HUD.UpdateGeneBars();
                    ParentMap.Players[0].EnergyPoints += EnergyBounty;
                    ParentMap.AliveCreatures.Remove(this);
                    BugInfoBox bugBox = HUD.BugBoxes.Find(bb => bb.Target == this);
                    if (bugBox != null)
                    {
                        bugBox.locked = false;
                        CurrentGame.HUD.bugHoverCounter = HUD.bugHoverFade;
                    }
                    Splatter.IsActive     = true;
                    Splatter.Location     = Location;
                    Splatter.EmitterAngle = Vector2.Normalize(Location - bullet.originPoint);
                    ParentMap.creatureCue = CurrentGame.soundBank.GetCue("narsk");
                    ParentMap.creatureCue.Play();
                }
                else
                {
                    hp -= hpLoss;

                    if (bullet.slow[0] > 0)                     //if bullet has a slow percentage
                    {
                        if (!isSlowed)
                        {
                            //Speed *= bullet.slow[0] * 0.01f; // DONE IN UPDATE TO SMOOTH DOWN THE CHANGE
                            CurrentSlowEffect = bullet.slow;
                            slowedCounter     = (int)bullet.slow[1];
                            isSlowed          = true;
                            justGotSlowed     = true;
                        }
                        else
                        {
                            if (bullet.slow[0] > CurrentSlowEffect[0])
                            {
                                CurrentSlowEffect = bullet.slow;
                            }
                            //else // if already slowed more... ?

                            slowedCounter = (int)bullet.slow[1];
                            justGotSlowed = false;
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// Constructor
 /// </summary>
 public BooleanFunction(int variablesCount, GeneType type)
 {
     this.variablesCount = variablesCount;
     // se genera el valor
     Generate(type);
 }
Exemplo n.º 8
0
        void UpdateText()
        {
            //Text = "";
            int    lines    = 2;
            string hpString = ((int)Target.Hp).ToString();

            hpStringWidth = CurrentGame.font.MeasureString(hpString).X;
            float nameStringWidth = CurrentGame.font.MeasureString(Target.Name).X;

            Lines      = new List <string>();
            LineColors = new List <Color>();
            Lines.Add(/*"Name: " + */ Target.Name);
            LineColors.Add(Color.SlateGray);
            Lines.Add(/*"HP: " + */ enter + Target.Hp);            //+ "/" + target.InitHp);
            LineColors.Add(Color.Orange);
            if (IsMovingTarget)
            {
                Lines.Add(/*enter + hpDigits + */ enter + '/' + Target.InitHp.ToString());
                LineColors.Add(Color.SlateGray);

                Width = Padding * 2 + (int)Math.Max(hpStringWidth + slashCharWidth + initHpStringWidth, nameStringWidth);
            }
            else
            {
                Width = Padding * 2 + (int)nameStringWidth;
            }

            if (Target.ElemArmors.HasAny)
            {
                GeneType gt = Target.ElemArmors.GetPrimaryElem();
                Lines.Add(/*target.ElemArmors.GetPrimaryElem().ToString() + ": " + */ enter + enter + ((int)((Target.ElemArmors.GetPrimaryElemStrength()) * 100)).ToString());
                lines++;
                switch (gt)
                {
                case GeneType.Red: LineColors.Add(Color.Red); break;

                case GeneType.Green: LineColors.Add(Color.ForestGreen); break;

                case GeneType.Blue: LineColors.Add(Color.CornflowerBlue); break;
                }
            }

            Height = lines * CurrentGame.font.LineSpacing + YPadding;
            if (ParentBox != null)
            {
                if (lines < 3)
                {
                    if (abovePoint)
                    {
                        PosY = ParentBox.Bounds.Top - Bounds.Height;
                    }
                    else
                    {
                        PosY = ParentBox.Bounds.Bottom;
                    }
                }
                PosX = (int)(ParentBox.Bounds.Center.X - Width * 0.5f);
            }

            //for (int i = 0; i < Lines.Count; i++)
            //    Text += Lines[i] + Environment.NewLine;
        }
Exemplo n.º 9
0
 /// <summary>
 /// crea un nuevo nodo de cierto tipo
 /// </summary>
 public ITreeGene CreateNew(GeneType type)
 {
     return new BooleanFunction(variablesCount, type);
 }
Exemplo n.º 10
0
 /// <summary>
 /// generar un nodo aleatoriamente de un cierto tipo
 /// </summary>
 public void Generate(GeneType type)
 {
     this.type = type;
     val = rand.Next((type == GeneType.Function) ? FunctionsCount : variablesCount);
 }
Exemplo n.º 11
0
 public Gene(GeneType _type, int _count, PlacementType _palcement, int _compAbilityStat)
 {
     initGene(_type, _count, _palcement, _compAbilityStat);
 }
Exemplo n.º 12
0
        private void initGene(GeneType _type, int _count, PlacementType _palcement, int _compAbilityStat)
        {
            type = _type;
            count = _count;
            placement = _palcement;
            compAbilityStat = _compAbilityStat;

            IncrementGeneCounter();
        }
Exemplo n.º 13
0
 public Gene(GeneType type, float value)
 {
     this.type  = type;
     this.value = value;
 }
Exemplo n.º 14
0
        public Genotype(int geneCount, int geneLength, float crossoverRate, float mutationRate, CrossoverType crossoverType, MutationType mutationType, GeneType geneType)
        {
            GeneType   = geneType;
            GeneCount  = geneCount;
            GeneLength = geneLength;

            CrossoverRate = crossoverRate;
            MutationRate  = mutationRate;

            CrossoverType = crossoverType;
            MutationType  = mutationType;
        }
Exemplo n.º 15
0
        public static Dictionary <int, List <Gene> > CalculateGenePairings(AnimalData female, AnimalData male, GeneType geneType)
        {
            byte[] femaleGene;
            byte[] maleGene;
            switch (geneType)
            {
            case GeneType.SIZE:
                femaleGene = female.SizeGene.geneBytes;
                maleGene   = male.SizeGene.geneBytes;
                break;

            case GeneType.LONGEVITY:
                femaleGene = female.LongevityGene.geneBytes;
                maleGene   = male.LongevityGene.geneBytes;
                break;

            case GeneType.UNKNOWN_1:
                return(null);

            case GeneType.FERTILITY:
                femaleGene = female.FertilityGene.geneBytes;
                maleGene   = male.FertilityGene.geneBytes;
                break;

            case GeneType.IMMUNITY:
                femaleGene = female.ImmunityGene.geneBytes;
                maleGene   = male.ImmunityGene.geneBytes;
                break;

            case GeneType.UNKNOWN_2:
                return(null);

            default:
                return(null);
            }
            Dictionary <int, List <Gene> > pairings = new Dictionary <int, List <Gene> >();

            Gene[] genes = new Gene[4];
            genes[0] = new Gene(femaleGene.Take(6).Concat(maleGene.Take(6)).ToArray());
            genes[1] = new Gene(femaleGene.Skip(6).Take(6).Concat(maleGene.Take(6)).ToArray());
            genes[2] = new Gene(femaleGene.Take(6).Concat(maleGene.Skip(6).Take(6)).ToArray());
            genes[3] = new Gene(femaleGene.Skip(6).Take(6).Concat(maleGene.Skip(6).Take(6)).ToArray());
            switch (geneType)
            {
            case GeneType.SIZE:
            case GeneType.LONGEVITY:
                foreach (Gene gene in genes)
                {
                    int value = (int)(gene.GetGeneValue(GeneValueType.HOMOGENEITY) * 100f);
                    if (!pairings.ContainsKey(value))
                    {
                        pairings.Add(value, new List <Gene>()
                        {
                            gene
                        });
                    }
                    else
                    {
                        pairings[value].Add(gene);
                    }
                }
                break;

            case GeneType.FERTILITY:
            case GeneType.IMMUNITY:
                foreach (Gene gene in genes)
                {
                    int value = (int)(gene.GetGeneValue(GeneValueType.DIVERSITY) * 100f);
                    if (!pairings.ContainsKey(value))
                    {
                        pairings.Add(value, new List <Gene>()
                        {
                            gene
                        });
                    }
                    else
                    {
                        pairings[value].Add(gene);
                    }
                }
                break;

            default:
                return(null);
            }

            return(pairings);
        }