Exemplo n.º 1
0
        private static void MoveIvo(Ivo ivo, int[,] matrix)
        {
            while (ivo.Row >= 0)
            {
                if (ivo.Row < matrix.GetLength(0) && ivo.Col >= 0 && ivo.Col < matrix.GetLength(1))
                {
                    ivo.CollectPoints(matrix[ivo.Row, ivo.Col]);
                }

                ivo.UpdateCoordinates(ivo.Row - 1, ivo.Col + 1);
            }
        }
Exemplo n.º 2
0
        private static void UpdateCoordinates(string command, Ivo ivo, Evil evil)
        {
            var ivoCoordinates = command
                                 .Split(' ', StringSplitOptions.RemoveEmptyEntries)
                                 .Select(int.Parse)
                                 .ToArray();

            ivo.UpdateCoordinates(ivoCoordinates[0], ivoCoordinates[1]);

            command = Console.ReadLine();

            var evilCoordinates = command
                                  .Split(' ', StringSplitOptions.RemoveEmptyEntries)
                                  .Select(int.Parse)
                                  .ToArray();

            evil.UpdateCoordinates(evilCoordinates[0], evilCoordinates[1]);
        }
Exemplo n.º 3
0
        static void Main()
        {
            int[]       dimestions = ReadInput(Console.ReadLine());
            MatrixField matrix     = CreateMatrix(dimestions);

            InitializeMatrix(matrix);

            long   sum     = 0;
            string command = string.Empty;

            while ((command = Console.ReadLine()) != "Let the Force be with you")
            {
                int[] ivoS = ReadInput(command);
                Ivo   ivo  = CreateIvo(ivoS);

                int[] evilArgs = ReadInput(Console.ReadLine());
                Evil  evil     = CreateEvil(evilArgs);

                while (evil.X >= 0 && evil.Y >= 0)
                {
                    if (ValidCell(evil.X, evil.Y, matrix))
                    {
                        matrix[evil.X, evil.Y] = 0;
                    }
                    evil.X--;
                    evil.Y--;
                }

                while (ivo.X >= 0 && ivo.Y < matrix.GetLengthY())
                {
                    if (ValidCell(ivo.X, ivo.Y, matrix))
                    {
                        sum += matrix[ivo.X, ivo.Y];
                    }

                    ivo.X--;
                    ivo.Y++;
                }
            }

            Console.WriteLine(sum);
        }
Exemplo n.º 4
0
        public static void Main()
        {
            int[] galaxyDimestions = Console.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();

            Galaxy galaxy = new Galaxy(galaxyDimestions[0], galaxyDimestions[1]);
            long   sum    = 0;
            string command;

            while ((command = Console.ReadLine()) != "Let the Force be with you")
            {
                int[] ivoStartPoint = command
                                      .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                                      .Select(int.Parse)
                                      .ToArray();
                Ivo ivo = new Ivo(ivoStartPoint);

                int[] evilStartPoint = Console
                                       .ReadLine()
                                       .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                                       .Select(int.Parse)
                                       .ToArray();
                Evil evil = new Evil(evilStartPoint);

                while (evil.IsMoveAcross() && ivo.IsMoveAcross())
                {
                    if (evil.IsOnTheGalaxy(galaxy))
                    {
                        evil.Destroy(galaxy);
                    }

                    evil.Move();

                    if (ivo.IsOnTheGalaxy(galaxy))
                    {
                        sum += ivo.GetValue(galaxy);
                    }

                    ivo.Move();
                }
            }
            Console.WriteLine(sum);
        }
Exemplo n.º 5
0
        static void Main()
        {
            short[] sizes = Console.ReadLine()
                            .Split(' ', StringSplitOptions.RemoveEmptyEntries)
                            .Select(short.Parse)
                            .ToArray();

            var matrix = InitializeMatrix(sizes);
            var ivo    = new Ivo();
            var evil   = new Evil();

            string command;

            while ((command = Console.ReadLine()) != "Let the Force be with you")
            {
                UpdateCoordinates(command, ivo, evil);
                MoveEvil(evil, matrix);
                MoveIvo(ivo, matrix);
            }

            Console.WriteLine(ivo.Score);
        }
Exemplo n.º 6
0
        static void Main()
        {
            int[] sizes = Console.ReadLine()
                          .Split(" ", StringSplitOptions.RemoveEmptyEntries)
                          .Select(int.Parse)
                          .ToArray();

            int[,] matrix = FillUpMatrix(sizes);
            Ivo  ivo  = new Ivo();
            Evil evil = new Evil();

            string input;

            while ((input = Console.ReadLine()) != "Let the Force be with you")
            {
                UpdateCoordinates(input, ivo, evil);
                MovedEvil(evil, matrix);
                MovedIvo(ivo, matrix);
            }

            Console.WriteLine(ivo.Score);
        }
Exemplo n.º 7
0
        static void Main()
        {
            string[] dimensionSizes = Console.ReadLine().Split(" ");

            int x = int.Parse(dimensionSizes[0]);
            int y = int.Parse(dimensionSizes[1]);

            int[,] matrix = new int[x, y];

            int value = 0;

            for (int i = 0; i < x; i++)
            {
                for (int j = 0; j < y; j++)
                {
                    matrix[i, j] = value++;
                }
            }

            string command = Console.ReadLine();

            while (command != "Let the Force be with you")
            {
                string[] aCommand = command.Split(" ");
                Ivo      ivo      = new Ivo(int.Parse(aCommand[0]), int.Parse(aCommand[1]));

                aCommand = Console.ReadLine().Split(" ");
                Evil evil = new Evil(int.Parse(aCommand[0]), int.Parse(aCommand[1]));

                evil.Move(matrix);
                ivo.Move(matrix);

                command = Console.ReadLine();
            }

            Console.WriteLine(Ivo.Sum);
        }
Exemplo n.º 8
0
        static void Main()
        {
            int[] dimestions = Console.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
            int   x          = dimestions[0];
            int   y          = dimestions[1];

            int[,] matrix = new int[x, y];

            int value = 0;

            for (int i = 0; i < x; i++)
            {
                for (int j = 0; j < y; j++)
                {
                    matrix[i, j] = value++;
                }
            }

            var ivo = new Ivo();

            var evil = new Evil();

            string command = Console.ReadLine();
            long   sum     = 0;

            while (command != "Let the Force be with you")
            {
                int[] ivoS  = command.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
                int[] evilS = Console.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
                ivo.X  = ivoS[0];
                ivo.Y  = ivoS[1];
                evil.X = evilS[0];
                evil.Y = evilS[1];
                int xE = evil.X;
                int yE = evil.Y;

                while (xE >= 0 && yE >= 0)
                {
                    if (xE >= 0 && xE < matrix.GetLength(0) && yE >= 0 && yE < matrix.GetLength(1))
                    {
                        matrix[xE, yE] = 0;
                    }
                    xE--;
                    yE--;
                }

                int xI = ivo.X;
                int yI = ivo.Y;

                while (xI >= 0 && yI < matrix.GetLength(1))
                {
                    if (xI >= 0 && xI < matrix.GetLength(0) && yI >= 0 && yI < matrix.GetLength(1))
                    {
                        sum += matrix[xI, yI];
                    }

                    yI++;
                    xI--;
                }

                command = Console.ReadLine();
            }

            Console.WriteLine(sum);
        }