コード例 #1
0
 public RicochetIndividual(RicochetIndividual father)
 {
     this.genome = new List <IGene>();
     foreach (GeneRicochet g in father.genome)
     {
         this.genome.Add(new GeneRicochet(g));
     }
     Mutate();
 }
コード例 #2
0
        public Individual getIndividual(String type)
        {
            Individual ind = null;

            switch (type)
            {
            case "Ricochet":
                ind = new RicochetIndividual();
                break;
            }
            return(ind);
        }
コード例 #3
0
        public Individual getIndividual(String type, Individual father,
                                        Individual mother)
        {
            Individual ind = null;

            switch (type)
            {
            case "Ricochet":
                ind = new RicochetIndividual((RicochetIndividual)father,
                                             (RicochetIndividual)mother);
                break;
            }
            return(ind);
        }
コード例 #4
0
        public RicochetIndividual(RicochetIndividual father, RicochetIndividual mother)
        {
            this.genome = new List <IGene>();
            int cuttingPoint =
                Parameters.randomGenerator.Next(father.genome.Count);

            foreach (GeneRicochet g in father.genome.Take(cuttingPoint))
            {
                this.genome.Add(new GeneRicochet(g));
            }
            foreach (GeneRicochet g in mother.genome.Skip(cuttingPoint))
            {
                this.genome.Add(new GeneRicochet(g));
            }
            Mutate();
        }
コード例 #5
0
        internal static double Evaluate(RicochetIndividual individual)
        {
            var  xOlds   = new List <int>();
            var  yOlds   = new List <int>();
            bool end     = false;
            var  listRem = new List <GeneRicochet>();

            foreach (GeneRicochet g in individual.genome)
            {
                if (!end)
                {
                    xOlds.Add(g.Pawn.X);
                    yOlds.Add(g.Pawn.Y);
                    Board.MovePawn(g.Direction, (PawnModel)g.Pawn);
                    end = g.Pawn.X == Board.Target.X && g.Pawn.Y == Board.Target.Y;
                }
                else
                {
                    listRem.Add(g);
                }
            }

            foreach (var g in listRem)
            {
                individual.genome.Remove(g);
            }
            int distance = Math.Abs(Board.Target.X - Board.Target.Pawn.X) +
                           Math.Abs(Board.Target.Y - Board.Target.Pawn.Y);


            for (var i = individual.genome.Count - 1; i >= 0; i--)
            {
                GeneRicochet genome = (GeneRicochet)individual.genome[i];
                genome.Pawn.X = xOlds[i];
                genome.Pawn.Y = yOlds[i];
            }

            return(distance * 100);
        }