FillStartMatrixRandomly() public method

public FillStartMatrixRandomly ( ) : void
return void
コード例 #1
0
        private void Start(object sender, RoutedEventArgs e)
        {
            var matrixSize = LogConstants.MatrixSize;

            var commandsForGetDirection = new GetDirectionAlgorithm().Algorithm;
            var commandsForGetAction    = new GetActionAlgorithm().Algorithm;
            var creator = new CreatorOfCreature(commandsForGetAction, commandsForGetDirection);

            _matrix = new Matrix(matrixSize, matrixSize, creator, new FillingFromCornersByWavesStrategy());
            _matrix.FillStartMatrixRandomly();
            Print(_step, matrixSize, _matrix);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Zhuchenko/creatures
        private static void Main(string[] args)
        {
            var length = 100;
            var matrix = new Matrix(length, length);
            matrix.Cells = new Creature[length, length];
            matrix.Length = length;
            matrix.Width = length;

            matrix.FillStartMatrixRandomly();
            Print(0, length, matrix);

            Console.WriteLine("0:{0}", matrix.AliveCount);
            var log = new StringBuilder();

            for (int i = 0; i < 1000; i++)
            {
                matrix.MakeTurn();
                Print(i + 1, length, matrix);
                Console.WriteLine("{0}:{1}", i + 1, matrix.AliveCount);
                var generationStat =
                    string.Join(" ",
                    matrix
                        .CellsAsEnumerable
                        .Select(x => x.Generation)
                        .GroupBy(x => x)
                        .OrderBy(x => x.Key)
                        .Select(x => string.Format("{0}:{1}", x.Key, x.Count()))
                        .ToArray());

                log.AppendLine(generationStat);
            }

            File.WriteAllText(@"C:\Temp\Creatures\Log.txt", log.ToString());
            Console.WriteLine(Stats.Up);
            Console.WriteLine(Stats.Right);
            Console.WriteLine(Stats.Down);
            Console.WriteLine(Stats.Left);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: taler0n/Students
        private static void Main(string[] args)
        {
            var matrixSize = LogConstants.MatrixSize;
            int scale      = 500 / matrixSize;

            var commandsForGetDirection = new GetDirectionAlgorithm().Algorithm;
            var commandsForGetAction    = new GetActionAlgorithm().Algorithm;
            var creator = new CreatorOfCreature(commandsForGetAction, commandsForGetDirection);

            var matrix = new Matrix(matrixSize, matrixSize, creator, new FillingFromCornersByWavesStrategy());

            matrix.FillStartMatrixRandomly();
            CreateDirectory();
            Print(0, matrixSize, matrix, scale);
            Console.WriteLine("0:{0}", matrix.AliveCount);

            var log = new StringBuilder();

            for (int i = 0; i < LogConstants.CountOfTurns; i++)
            {
                if (matrix.AliveCount == 0)
                {
                    break;
                }
                matrix.MakeTurn();

                if (i % 100 == 0)
                {
                    MarkParts(matrixSize, matrix);
                }


                Print(i + 1, matrixSize, matrix, scale);
                Console.WriteLine("{0}:{1}", i + 1, matrix.AliveCount);
                var generationStat =
                    string.Join(" ",
                                matrix
                                .CreaturesAsEnumerable
                                .Select(x => x.Generation)
                                .GroupBy(x => x)
                                .OrderBy(x => x.Key)
                                .Select(x => $"{x.Key}:{x.Count()}")
                                .ToArray());

                log.AppendLine(generationStat);

                //PrintGeneration(matrix, i);
            }

            var maxGeneration     = matrix.CreaturesAsEnumerable.Max(n => n.Generation);
            var averageGeneration = (int)matrix.CreaturesAsEnumerable.Average(n => n.Generation);
            var limit             = (int)(0.75 * maxGeneration);
            var step = averageGeneration / 5;

            var youngCreatures =
                matrix.CreaturesAsEnumerable.Where(n => n.Generation > limit && n.Generation != maxGeneration).ToArray();
            var mediumAgeCreatures =
                matrix.CreaturesAsEnumerable.Where(
                    n => n.Generation >= averageGeneration - step && n.Generation <= averageGeneration + step).ToArray();

            var randomYoung  = ChooseRandom(youngCreatures);
            var randomMedium = ChooseRandom(mediumAgeCreatures);

            var youngCreatureLog    = CreateLogOfCreature(randomYoung.Creature as Creature, randomYoung.Generation);
            var mediumCreatureLog   = CreateLogOfCreature(randomMedium.Creature as Creature, randomMedium.Generation);
            var originalCreatureLog = CreateLogOfCreature(creator.CreateAbstractCreature() as Creature, 1);

            File.WriteAllText(LogConstants.PathToLogDirectory + "\\randomYoungCommands.txt", youngCreatureLog);
            File.WriteAllText(LogConstants.PathToLogDirectory + "\\randomMediumCommands.txt", mediumCreatureLog);
            File.WriteAllText(LogConstants.PathToLogDirectory + "\\originalCommands.txt", originalCreatureLog);

            File.WriteAllText(LogConstants.PathToLogDirectory + "\\Log.txt", log.ToString());
            Console.WriteLine("Up: " + Stats.Up);
            Console.WriteLine("Right: " + Stats.Right);
            Console.WriteLine("Down: " + Stats.Down);
            Console.WriteLine("Left: " + Stats.Left);
            Console.WriteLine("Mutations: " + Mutator.Mutator.MUTATIONS);
            Console.WriteLine("Successful mutations: " + Mutator.Mutator.MUTATIONSREAL);
            Console.WriteLine("Exceptions: " + Matrix.EXCEPTIONS);
            Console.ReadKey();
        }