Ejemplo n.º 1
0
    private static void TraverseField(MatrixCoordinates size, bool[,] field, int directionChangesCount)
    {
        MatrixCoordinates position = new MatrixCoordinates(field.GetLength(0) - 1, 0);

        field[position.Row, position.Col] = true;

        for (int i = 0; i < directionChangesCount; i++)
        {
            string[] command = GetCommand();
            int      moves   = int.Parse(command[1]);

            MatrixCoordinates dirChange = GetDirChange(command[0]);

            for (int move = 0; move < moves - 1; move++)
            {
                if (!IsInRange(size, position.Row + dirChange.Row, position.Col + dirChange.Col))
                {
                    break;
                }

                position.Row += dirChange.Row;
                position.Col += dirChange.Col;

                field[position.Row, position.Col] = true;
            }
        }
    }
    private static bool IsInRange(MatrixCoordinates size, int row, int col)
    {
        bool rowIsInRange = row > -1 && row < size.Row;
        bool colIsInRange = col > -1 && col < size.Col;

        return rowIsInRange && colIsInRange;
    }
 public static MatrixCoordinates operator -(MatrixCoordinates first, MatrixCoordinates second)
 {
     int newCoordinatesRow = first.Row - second.Row;
     int newCoordinatesColumn = first.Column - second.Column;
     MatrixCoordinates newCoordinates = new MatrixCoordinates(newCoordinatesRow, newCoordinatesColumn);
     return newCoordinates;
 }
Ejemplo n.º 4
0
    private static bool IsInRange(MatrixCoordinates size, int row, int col)
    {
        bool rowIsInRange = row > -1 && row < size.Row;
        bool colIsInRange = col > -1 && col < size.Col;

        return(rowIsInRange && colIsInRange);
    }
Ejemplo n.º 5
0
        public static void MapCursorMovements(string fileName, string outputFile, Char[,] Keyboard)
        {
            /* This code will script the path of the cursor over the keyboard.
             * Keyboard is a parameter to allow for other keyboards in the future.  */

            bool AppendOutput = false;

            if (File.Exists(fileName))
            {
                // Read input text file
                using (System.IO.StreamReader sr = new System.IO.StreamReader(fileName))
                {
                    String line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        //convert string to array
                        char[] InputArray = line.ToUpper().ToCharArray();

                        StringBuilder CursorPath = new StringBuilder();

                        /* Assume cursor starting at A for each line read from file */
                        int LastVertical   = 0;
                        int LastHorizontal = 0;

                        for (int j = 0; j < InputArray.Length; j++)
                        {
                            if (InputArray[j] == ' ')
                            {
                                CursorPath.Append(",S");
                            }
                            else
                            {
                                MatrixCoordinates KB = GetCoordinates(InputArray[j], Keyboard);

                                /*  if there is a possibility of a character not on the keyboard (except for space),
                                 * add a check here so that if (KB.CurrentVertical == -1) go to error processing  */

                                CursorPath.Append(TraverseKeyboard(LastVertical, KB.CurrentVertical, 'U', 'D'));
                                CursorPath.Append(TraverseKeyboard(LastHorizontal, KB.CurrentHorizontal, 'L', 'R'));

                                LastVertical   = KB.CurrentVertical;
                                LastHorizontal = KB.CurrentHorizontal;
                                CursorPath.Append(",#");
                            }
                        }

                        /* writing out one path for the DVR for each input line */
                        /* First write will clear out anything that was already in this file (anything from when this was previously executed) */
                        WriteLineToFile(outputFile, AppendOutput, CursorPath.ToString().TrimStart(','));

                        AppendOutput = true;
                    }
                }
            }  /* may want to add error processing here if input file does not exist */
        }
        public void CheckForProperEqualsMethodBehaviour()
        {
            // arange
            var point      = new MatrixCoordinates(1, 1);
            var compareObj = new MatrixCoordinates(1, 1);

            // action
            var result = point.Equals(compareObj);

            // assert
            Assert.AreEqual(true, result, "Equals method does not work proper");
        }
        public void CheckForProperToStringOutput()
        {
            // arrage
            var point    = new MatrixCoordinates(1, 1);
            var expected = "(1, 1)";

            // action
            var result = point.ToString();

            // assert
            Assert.AreEqual(expected, result, "ToString Method does not return expected result");
        }
        public void CheckForInvalidTypeCastByEqualsMethod()
        {
            // arange
            var point      = new MatrixCoordinates(1, 1);
            var compareObj = new
            {
                Row = 1,
                Col = 1
            };

            // action
            point.Equals(compareObj);
        }
Ejemplo n.º 9
0
    internal static void Main()
    {
        MatrixCoordinates dimensions = GetDimensions();

        bool[,] field = new bool[dimensions.Row, dimensions.Col];
        int directionChangesCount = int.Parse(Console.ReadLine());

        TraverseField(dimensions, field, directionChangesCount);

        long result = GetSum(field);

        Console.WriteLine(result);
    }
        public void CheckMatrixRowValueForProperPlusOperatorResult()
        {
            // arrange
            var point1           = new MatrixCoordinates(1, 1);
            var point2           = new MatrixCoordinates(2, 2);
            var expectedRowValue = 3;

            // action
            var result = point1 + point2;

            // assert
            Assert.AreEqual(expectedRowValue, result.Row, "Plus Operator for the Row is not correct");
        }
        public void CheckMatrixColValueForProperMinusOperatorResult()
        {
            // arrange
            var point1           = new MatrixCoordinates(2, 2);
            var point2           = new MatrixCoordinates(1, 1);
            var expectedColValue = 1;

            // action
            var result = point1 - point2;

            // assert
            Assert.AreEqual(expectedColValue, result.Col, "Minus Operator for the Col is not correct");
        }
Ejemplo n.º 12
0
 public Cloud(MatrixCoordinates topLeft, CloudImages cloudImage)
     : base(topLeft)
 {
     if ((int)cloudImage == 0)
     {
         this.Image = image1;
     }
     else
     {
         this.Image = image2;
     }
     this.Color = Colors.Cyan;
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Transpose the CVS instance in place.
 /// </summary>
 public void Transpose()
 {
     (int rows, int columns)size = (Size.columns, Size.rows);
     Parallel.ForEach(LinearIndex, (lis) =>
     {
         for (int i = 0; i < lis.Count; i++)
         {
             lis[i] = MatrixCoordinates.TransposeLinearIndex(Size, lis[i], LinearIndexMode).linearIndex;
         }
         lis.Sort();
     });
     Size = size;
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Transpose the matrix to a new CVS instance.
        /// </summary>
        /// <param name="cvs">The matrix as CVS.</param>
        /// <returns>The transposed matrix as CVS.</returns>
        public CVS <T> TransposeToNewCVS()
        {
            (List <T> value, List <List <int> > linearIndex, MatrixLinearIndexMode linearIndexMode, (int rows, int columns)size) = this;
            List <T>           newValue       = new List <T>();
            List <List <int> > newLinearIndex = new List <List <int> >();
            List <int>         lis;

            for (int i = 0; i < value.Count; i++)
            {
                newValue.Add(value[i]);
                lis = new List <int>();
                foreach (var li in linearIndex[i])
                {
                    lis.Add(MatrixCoordinates.TransposeLinearIndex(size, li, linearIndexMode).linearIndex);
                }
                lis.Sort();
                newLinearIndex.Add(lis);
            }
            return(new CVS <T>(newValue, newLinearIndex, linearIndexMode, (size.columns, size.rows)));
        }
Ejemplo n.º 15
0
        public static MatrixCoordinates GetCoordinates(Char Target, Char[,] Matrix)
        {
            // returns the position of the first occurrence or target character in a two-dimensional array of characters
            MatrixCoordinates result = new MatrixCoordinates();

            result.CurrentVertical   = -1;
            result.CurrentHorizontal = -1;
            for (int v = 0; ((v < Matrix.GetLength(0)) && (result.CurrentVertical == -1)); v++)
            {
                for (int h = 0; ((h < Matrix.GetLength(1)) && (result.CurrentHorizontal == -1)); h++)
                {
                    if (Matrix[v, h] == Target)
                    {
                        result.CurrentVertical   = v;
                        result.CurrentHorizontal = h;
                        return(result);
                    }
                }
            }
            return(result);  /* may want error-handling and/or special process either here or later if -1 returned for coordinates */
        }
Ejemplo n.º 16
0
 public Water(MatrixCoordinates topLeft)
     : base(topLeft)
 {
     this.Image = image;
     this.Color = Colors.Blue;
 }
Ejemplo n.º 17
0
 public Pole(MatrixCoordinates topLeft)
     : base(topLeft)
 {
     this.Image = image;
     this.Color = Colors.Cyan;
 }
Ejemplo n.º 18
0
 public Castle(MatrixCoordinates topLeft)
     : base(topLeft)
 {
     this.Image = image;
     this.Color = Colors.Yellow;
 }
Ejemplo n.º 19
0
 public Brick(MatrixCoordinates topLeft, Colors color)
     : this(topLeft)
 {
     this.Image = image;
     this.Color = color;
 }
Ejemplo n.º 20
0
 public Brick(MatrixCoordinates topLeft)
     : base(topLeft)
 {
     this.Image = image;
     this.Color = Colors.Gray;
 }
 public King(MatrixCoordinates coordinates)
     : base(KingSymbol, coordinates)
 {
 }
 protected StaticObject(MatrixCoordinates topLeft)
     : base(topLeft)
 {
 }
 public Pawn(char symbol, MatrixCoordinates coordinates)
 {
     this.symbol = symbol;
     this.coordinates = coordinates;
 }
Ejemplo n.º 24
0
 public LevelGround(MatrixCoordinates topLeft)
     : base(topLeft)
 {
     this.Image = image;
     this.Color = Colors.Gray;
 }
 public static MatrixCoordinates operator -(MatrixCoordinates coordinates1, MatrixCoordinates coordinates2)
 {
     MatrixCoordinates newCoordinates =
         new MatrixCoordinates(coordinates1.Row - coordinates2.Row, coordinates1.Column - coordinates2.Column);
     return newCoordinates;
 }
Ejemplo n.º 26
0
 public Coin(MatrixCoordinates topLeft)
     : base(topLeft)
 {
     this.Image = image;
     this.Color = Colors.Green;
 }
    private static void TraverseField(MatrixCoordinates size, bool[,] field, int directionChangesCount)
    {
        MatrixCoordinates position = new MatrixCoordinates(field.GetLength(0) - 1, 0);

        field[position.Row, position.Col] = true;

        for (int i = 0; i < directionChangesCount; i++)
        {
            string[] command = GetCommand();
            int moves = int.Parse(command[1]);

            MatrixCoordinates dirChange = GetDirChange(command[0]);

            for (int move = 0; move < moves - 1; move++)
            {
                if (!IsInRange(size, position.Row + dirChange.Row, position.Col + dirChange.Col))
                {
                    break;
                }

                position.Row += dirChange.Row;
                position.Col += dirChange.Col;

                field[position.Row, position.Col] = true;
            }
        }
    }