public double survive()
        {
            SlotMachineSimulation simulation = null;

            /*
             * Re-evaluate target.
             */
            if (Util.REEVALUATE_TARGET_VECTOR == true)
            {
                Console.WriteLine("REEVALUATE_TARGET_VECTOR");
                simulation = new SlotMachineSimulation();
                simulation.load(population [targetIndex]);
                simulation.simulate(symbolsDiversity);
                fitness [targetIndex] = simulation.costFunction(targetRtp, symbolsDiversity);

                if (fitness [bestIndex] > fitness [targetIndex])
                {
                    bestIndex = targetIndex;
                }
            }

            /*
             * Evaluate new solution.
             */
            Console.WriteLine("Evaluate new solution");
            simulation = new SlotMachineSimulation();
            simulation.load(offspring);
            simulation.simulate(symbolsDiversity);

            double cost = simulation.costFunction(targetRtp, symbolsDiversity);

            /*
             * If better solution is not found - exit.
             */
            if (cost >= fitness [targetIndex])
            {
                return(fitness[targetIndex]);
            }

            fitness [targetIndex] = cost;

            for (int i = 0; i < offspring.Length; i++)
            {
                for (int j = 0; j < offspring [i].Length; j++)
                {
                    population [targetIndex] [i] [j] = offspring [i] [j];
                }
            }

            if (fitness [bestIndex] > fitness [targetIndex])
            {
                bestIndex = targetIndex;
            }
            return(cost);
        }
        public DiscreteDifferentialEvolution(int[][] reels, double targetRtp, int symbolsDiversity)
        {
            if (reels.Length != NUMBER_OF_REELS)
            {
                Console.WriteLine("Number of reals is incorrect!");
                return;
            }

            for (int i = 0; i < reels.Length; i++)
            {
                if (reels [i].Length != REEL_LENGTH)
                {
                    Console.WriteLine("Reel length is incorrect!");
                    return;
                }
            }

            for (int p = 0; p < POPULATION_SIZE; p++)
            {
                population [p] = new int[NUMBER_OF_REELS] [];
                for (int i = 0; i < NUMBER_OF_REELS; i++)
                {
                    population [p] [i] = new int[REEL_LENGTH];
                }
            }

            offspring = new int[NUMBER_OF_REELS] [];
            for (int i = 0; i < NUMBER_OF_REELS; i++)
            {
                offspring [i] = new int[REEL_LENGTH];
            }

            this.targetRtp        = targetRtp;
            this.symbolsDiversity = symbolsDiversity;

            if (Util.RANDOM_INITIAL_REELS == true)
            {
                initialRandomPoints();
            }
            else
            {
                initialSinglePoint(reels);
            }

            /*
             * Just put a big number (bad fitness), when there is no evaluation.
             */
            for (int p = 0; p < population.Length; p++)
            {
                fitness [p] = int.MaxValue;
            }

            /*
             * Evaluate population fintess.
             */
            bestIndex = 0;
            for (int p = 0; p < population.Length; p++)
            {
                /*
                 * It will be evaluated in the first surviver.
                 */
                if (Util.REEVALUATE_TARGET_VECTOR == true)
                {
                    break;
                }

                SlotMachineSimulation simulation = new SlotMachineSimulation();
                simulation.load(population [p]);
                simulation.simulate(symbolsDiversity);
                fitness [p] = simulation.costFunction(targetRtp, symbolsDiversity);
                if (fitness [bestIndex] > fitness [p])
                {
                    bestIndex = p;
                }
            }
        }