Write() публичный Метод

public Write ( System textwriter ) : void
textwriter System
Результат void
        public static PlayerAction FindBestBigMoneyWithCardVsStrategy(PlayerAction playerAction, Card card, bool logProgress = false)
        {
            Random random = new Random();
            var initialPopulation = Enumerable.Range(0, 10).Select(index => new BigMoneyWithCardDescription(card)).ToArray();

            var algorithm = new GeneticAlgorithm.GeneticAlgorithmAgainstConstant<BigMoneyWithCardDescription, MutateDescriptionFromParameters, CompareBigMoneyWithCardDescription>(
                initialPopulation,
                new MutateDescriptionFromParameters(random),
                new CompareBigMoneyWithCardDescription(playerAction),
                new Random());

            BigMoneyWithCardDescription result = new BigMoneyWithCardDescription(card);
            double maxScore = -100;
            double lastMaxScore = maxScore;
            int countScoreUnchanged = 0;

            for (int i = 0; i < 1000; ++i)
            {
                if (logProgress)
                {
                    System.Console.WriteLine("Generation {0}", i);
                    System.Console.WriteLine("==============", i);
                }
                algorithm.RunOneGeneration();
                for (int j = 0; j < 10; ++j)
                {
                    double currentScore = algorithm.nextMembers[j].species.GetScoreVs(playerAction, showReport:logProgress);
                    if (currentScore > maxScore)
                    {
                        maxScore = currentScore;
                        result = algorithm.nextMembers[j].species;
                    }
                    if (logProgress)
                    {
                        algorithm.nextMembers[j].species.Write(System.Console.Out);
                        System.Console.WriteLine();
                    }
                }

                if (lastMaxScore == maxScore)
                {
                    if (countScoreUnchanged++ >= 3)
                        break;
                }
                else
                {
                    lastMaxScore = maxScore;
                    countScoreUnchanged = 0;
                }

                if (logProgress)
                {
                    System.Console.WriteLine();
                }
            }

            result.Write(System.Console.Out);
            System.Console.WriteLine();

            return result.ToPlayerAction();
        }
Пример #2
0
        public static PlayerAction FindBestBigMoneyWithCardVsStrategy(object playerActionOrString, Card card, bool logProgress = false)
        {
            PlayerAction playerAction      = Program.strategyLoader.GetPlayerAction(playerActionOrString);
            Random       random            = new Random();
            var          initialPopulation = Enumerable.Range(0, 10).Select(index => new BigMoneyWithCardDescription(card)).ToArray();

            var algorithm = new GeneticAlgorithm.GeneticAlgorithmAgainstConstant <BigMoneyWithCardDescription, MutateBigMoneyWithCardDescription, CompareBigMoneyWithCardDescription>(
                initialPopulation,
                new MutateBigMoneyWithCardDescription(random),
                new CompareBigMoneyWithCardDescription(playerAction),
                new Random());

            BigMoneyWithCardDescription result = new BigMoneyWithCardDescription(card);
            double maxScore            = -100;
            double lastMaxScore        = maxScore;
            int    countScoreUnchanged = 0;

            for (int i = 0; i < 1000; ++i)
            {
                if (logProgress)
                {
                    System.Console.WriteLine("Generation {0}", i);
                    System.Console.WriteLine("==============", i);
                }
                algorithm.RunOneGeneration();
                for (int j = 0; j < 10; ++j)
                {
                    double currentScore = algorithm.nextMembers[j].species.GetScoreVs(playerAction, showReport: logProgress);
                    if (currentScore > maxScore)
                    {
                        maxScore = currentScore;
                        result   = algorithm.nextMembers[j].species;
                    }
                    if (logProgress)
                    {
                        algorithm.nextMembers[j].species.Write(System.Console.Out);
                        System.Console.WriteLine();
                    }
                }

                if (lastMaxScore == maxScore)
                {
                    if (countScoreUnchanged++ >= 3)
                    {
                        break;
                    }
                }
                else
                {
                    lastMaxScore        = maxScore;
                    countScoreUnchanged = 0;
                }

                if (logProgress)
                {
                    System.Console.WriteLine();
                }
            }

            result.Write(System.Console.Out);
            System.Console.WriteLine();

            return(result.ToPlayerAction());
        }