Beispiel #1
0
        /// <summary>
        /// Allocate an instance of a derived AI class based on the specified
        /// type.
        /// </summary>
        /// <param name="type">AI type to instance</param>
        /// <returns>Reference to instantiated AI class</returns>
        static private AI Instance(AI.AIType type)
        {
            switch (type)
            {
            case AI.AIType.DuckAndFire:
                return(new DuckAndFireAI());

            case AI.AIType.Flyby:
                return(new FlybyAI());

            case AI.AIType.ShotArc:
                return(new ShotArcAI());

            case AI.AIType.Static:
                return(new StaticAI());

            case AI.AIType.Aggressive:
                return(new AggressiveAI());
            }

            Debug.Assert(false,
                         "AIHandler.Instance: Invalid AI type specified");

            return(null);
        }
Beispiel #2
0
        /// <summary>
        /// Create an instace of the specified AI type.  Because the types
        /// are derived, a polymorphed AI pointer is returned.
        /// </summary>
        /// <param name="type">AI type to create</param>
        /// <returns>Reference to instantiated AI class</returns>
        static public AI Create(AI.AIType type)
        {
            AI aiInst = Instance(type);

            aiInst.Load(type);

            return(aiInst);
        }
Beispiel #3
0
        public Cell(CellManager setCellManager, Cell parent, AI.AIType aiType, Vector2 startPosition, float dnaSize, float dnaSpeed, float dnaPerception) : base(startPosition)
        {
            CM         = setCellManager;
            ai         = AI.GetAI(aiType, parent, this);
            size       = dnaSize;
            speed      = dnaSpeed;
            perception = dnaPerception;

            energy = energyRequirement;
        }
Beispiel #4
0
        public void Initilize()
        {
            Content.Clear();
            civilazationTime = 0;
            pause            = false;

            const int starterCells = 5;

            AI.AIType[] starterAI = new AI.AIType[starterCells]
            {
                AI.AIType.PointsTargeting,
                AI.AIType.PointsTargeting,
                AI.AIType.PointsTargeting,
                AI.AIType.PointsTargeting,
                AI.AIType.PointsTargeting
            };

            int[,] starterDNA = new int[starterCells, 3]
            {
                { 10, 20, 100 },
                { 10, 20, 100 },
                { 14, 30, 50 },
                { 14, 30, 50 },
                { 14, 30, 50 }
            };

            for (int i = 0; i < starterCells; i++)
            {
                Cell c = new Cell
                             (this, new Cell(this, null, AI.AIType.NoBrain, Vector2.Zero, 0, 0, 0), starterAI[i],
                             new Vector2(
                                 StaticGlobal.Random.Next(-0 * StaticGlobal.SectorSize, starterCells * 2 * StaticGlobal.SectorSize),
                                 StaticGlobal.Random.Next(-0 * StaticGlobal.SectorSize, starterCells * 2 * StaticGlobal.SectorSize)),
                             starterDNA[i, 0], starterDNA[i, 1], starterDNA[i, 2]
                             );

                Content.Add(c);

                for (int f = 0; f < 3; f++)
                {
                    int[] nORp = new int[] { -1, 1 };
                    Content.Add
                    (
                        new Food(
                            new Vector2(
                                c.Position.X + nORp[StaticGlobal.Random.Next(2)] * StaticGlobal.Random.Next((int)Math.Floor(c.Size), (int)Math.Floor(c.Size) + StaticGlobal.SectorSize),
                                c.Position.Y + nORp[StaticGlobal.Random.Next(2)] * StaticGlobal.Random.Next((int)Math.Floor(c.Size), (int)Math.Floor(c.Size) + StaticGlobal.SectorSize)
                                )
                            )
                    );
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Create an instance of the AI class as specified by the given
        /// DataRow.
        /// Because the types are derived, a polymorphed AI pointer is
        /// returned.
        /// </summary>
        /// <param name="ai">AI instance to be created</param>
        /// <returns>Reference to instantiated AI class</returns>
        static public AI Create(DataRow dr)
        {
            AI.AIType aiType = (AI.AIType) int.Parse((string)dr["Type"],
                                                     CultureInfo.InvariantCulture);
            Debug.Assert(aiType >= 0 && aiType < AI.AIType.Count,
                         "AI.AI: Invalid AI Type");

            AI aiInst = Instance(aiType);

            aiInst.Load(dr);

            return(aiInst);
        }