예제 #1
0
 /// <summary>
 /// Constructor, Creates entity with defined genome.
 /// </summary>
 /// <param name="world">The world to live in.</param>
 /// <param name="genome">The specific genome.</param>
 public AIEntity(SimulationWorld world, Genome genome) : base(world, Globals.startPos)
 {
     this.genome  = genome;
     fittingValue = 0;
     lastJump     = 0;
     UpdateMutation();
 }
예제 #2
0
        /// <summary>
        /// Breed two Genome with "Uniform crossover".
        /// </summary>
        /// <param name="world">Thw world the population lives in.</param>
        /// <param name="a">The genome of the first parent.</param>
        /// <param name="b">The genome of the second parent.</param>
        /// <param name="newEntityIndex">Where we want the childs to be inserted in the entity arraylist.</param>
        /// <param name="entitys">The entitys in the population.</param>
        /// <param name="populationAmount">The amount of entitys in the population.</param>
        private static void BreedGenome(SimulationWorld world, Genome a, Genome b, int newEntityIndex, AIEntity[] entitys, int populationAmount)
        {
            int amount = a.GetAmount();

            //Creat the new Genome.
            Genome c = new Genome(amount);
            Genome d = new Genome(amount);

            //For each gen select which parent they get there genes from.
            for (int i = 0; i < amount; i++)
            {
                if (Globals.rand.NextDouble() > 0.5f)
                {
                    c.SetGene(i, a.GetGene(i).Copy());
                    d.SetGene(i, b.GetGene(i).Copy());
                }
                else
                {
                    d.SetGene(i, b.GetGene(i).Copy());
                    c.SetGene(i, a.GetGene(i).Copy());
                }
            }

            //Insert the new genome into new entitys and replace them in the list.
            int newIndex = populationAmount - newEntityIndex - 1;

            entitys[newIndex]     = new AIEntity(world, c);
            entitys[newIndex - 1] = new AIEntity(world, d);
        }
예제 #3
0
        private float velocity;         //The current velocity.

        /// <summary>
        /// Constuctor.
        /// </summary>
        /// <param name="world">The world to spawn block in.</param>
        /// <param name="pos">The position.</param>
        /// <param name="upMovement">The amount to move up.</param>
        public Blocker(SimulationWorld world, Vector2 pos, float upMovement) : base(world, new Rectangle(0, 0, 50, 200), new Rectangle(0, 0, 1, 1), Globals.pixel)
        {
            speed           = 100;
            velocity        = speed;
            this.pos        = pos;
            orginalPos      = pos;
            this.upMovement = upMovement;
        }
예제 #4
0
        protected SimulationWorld world;    //The world to spawn in.

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="world">The world to spawn in.</param>
        /// <param name="recHit">The collision rectangle.</param>
        /// <param name="recDraw">The rectangle to take from texture.</param>
        /// <param name="texture">The texture to applay to object.</param>
        public GameObject(SimulationWorld world, Rectangle recHit, Rectangle recDraw, Texture2D texture)
        {
            this.world   = world;
            this.recHit  = recHit;
            this.recDraw = recDraw;
            this.texture = texture;
            this.color   = Color.Black;
        }
예제 #5
0
        protected bool dead;                //Is the entity dead.

        /// <summary>
        /// Constructor. Creates the entity.
        /// </summary>
        /// <param name="world">The world to spawn to.</param>
        /// <param name="pos">The position of entity.</param>
        public Entity(SimulationWorld world, Vector2 pos) : base(world, new Rectangle(0, 0, 32, 32), new Rectangle(0, 0, 32, 32), Globals.sheet)
        {
            this.pos  = pos;
            jumpPower = 0;
            rotation  = 0;
            left      = true;
            origin    = new Vector2(recHit.Width / 2, recHit.Height / 2);
            dead      = false;
        }
예제 #6
0
        private int amount;             //The amount of entitys in this population.

        /// <summary>
        /// Constuctor. Creates the entitys in the population.
        /// </summary>
        /// <param name="world">The world the population lives in.</param>
        /// <param name="amount">The amount of entitys in this population.</param>
        public Population(SimulationWorld world, int amount)
        {
            this.amount = amount;
            this.world  = world;
            entitys     = new AIEntity[amount];
            dead        = new List <AIEntity>();

            for (int i = 0; i < amount; i++)
            {
                entitys[i] = new AIEntity(world);
            }
        }
예제 #7
0
        /// <summary>
        /// Breed the population in the world.
        /// </summary>
        /// <param name="world">The world the population lives in.</param>
        /// <param name="population">The population we want to breed.</param>
        public static void Breed(SimulationWorld world, Population population)
        {
            AIEntity[] entitys = population.GetEntitys();

            //Bread the top half section to the lower half.
            int topAmount = (int)(population.GetAmount() * 0.5f);

            for (int i = 0; i < topAmount; i += 2)
            {
                Genome a = entitys[i].GetGenome();
                Genome b = entitys[i + 1].GetGenome();
                BreedGenome(world, a, b, i, entitys, population.GetAmount());
                entitys[i]     = new AIEntity(world, a.Copy());
                entitys[i + 1] = new AIEntity(world, b.Copy());
            }
        }
예제 #8
0
        private float range;                //The range in points to the next platform.

        /// <summary>
        /// Constructor, creates a genome whit 250 genes.
        /// </summary>
        /// <param name="world">The world to live in.</param>
        public AIEntity(SimulationWorld world) : this(world, new Genome(250))
        {
        }
예제 #9
0
 protected override void LoadContent()
 {
     Globals.Load(this);
     spriteBatch = new SpriteBatch(GraphicsDevice);
     world       = new SimulationWorld();
 }
예제 #10
0
        private float radian;   //The radian for rotation.

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="world">The world to spawn to.</param>
        /// <param name="pos">The position of trampoline.</param>
        /// <param name="radian">The radian of the circulation.</param>
        /// <param name="speed">The speed of the circultaion.</param>
        public Trampolin(SimulationWorld world, Vector2 pos, float radian, float speed) : base(world, new Rectangle(0, 0, 40, 10), new Rectangle(0, 0, 1, 1), Globals.pixel)
        {
            this.pos    = pos;
            this.radian = radian;
            this.speed  = speed;
        }