示例#1
0
        public static void Create(OrganismDesign design, Point position, Game1 game)
        {
            Organism newOrganism = new Organism
            {
                Position           = position,
                FractionalPosition = Vector2.Zero,
                Design             = design,
                Energy             = 38,
                Pieces             = new List <OrganismPiece>(16),
                baby     = true,
                nextGrow = (short)(design.GrowPatterns.Count - 1)
            };

            int organismIndex = game.AllocOrganism();

            newOrganism.organismIndex = organismIndex;
            newOrganism.Grow(Point.Zero, BlockType.Heart, game, reproduce: false);
            game.Organisms[organismIndex] = newOrganism;
        }
示例#2
0
        public static OrganismDesign Mutate(OrganismDesign design)
        {
            List <OrganismDesign.GrowPattern> copyPattern;

            switch (Game1.rnd.Next(80))
            {
            case 0:     // change block type
            {
                copyPattern = design.GrowPatterns.ToList();
                int index = Game1.rnd.Next(copyPattern.Count);
                OrganismDesign.GrowPattern p = copyPattern[index];
                p.blockType        = (BlockType)(Game1.rnd.Next(6) + 1);
                copyPattern[index] = p;
            }
            break;

            case 1:     // change direction
            {
                copyPattern = design.GrowPatterns.ToList();
                int index = Game1.rnd.Next(copyPattern.Count);
                OrganismDesign.GrowPattern p = copyPattern[index];
                p.direction        = (Direction)(Game1.rnd.Next(4));
                copyPattern[index] = p;
            }
            break;

            case 2:     // change blockNum
            {
                copyPattern = design.GrowPatterns.ToList();
                int index = Game1.rnd.Next(copyPattern.Count);
                OrganismDesign.GrowPattern p = copyPattern[index];
                p.blockNum         = Game1.rnd.Next(index);
                copyPattern[index] = p;
            }
            break;

            case 3:     // add a block
            {
                if (design.GrowPatterns.Count < 255)
                {
                    copyPattern = design.GrowPatterns.ToList();
                    OrganismDesign.GrowPattern p = new OrganismDesign.GrowPattern();
                    p.blockType = (BlockType)(Game1.rnd.Next(7) + 1);
                    p.direction = (Direction)(Game1.rnd.Next(4));
                    p.blockNum  = Game1.rnd.Next(copyPattern.Count);
                    copyPattern.Add(p);
                }
                else
                {
                    return(design);
                }
            }
            break;

            case 4:     // remove a block
            {
                copyPattern = design.GrowPatterns.ToList();
                int index = Game1.rnd.Next(copyPattern.Count);
                copyPattern.RemoveAt(index);
                for (int Idx = index; Idx < copyPattern.Count; ++Idx)
                {
                    OrganismDesign.GrowPattern p = copyPattern[Idx];
                    if (p.blockNum > index)
                    {
                        p.blockNum--;
                    }
                    copyPattern[Idx] = p;
                }
            }
            break;

            default:
                return(design);
            }

            OrganismDesign copyDesign = new OrganismDesign
            {
                GrowPatterns = copyPattern
            };

            return(copyDesign);
        }