コード例 #1
0
        public static void Main()
        {
            var matrixHeight = int.Parse(Console.ReadLine());
            var matrixWidth = int.Parse(Console.ReadLine());
            var horseStartRow = int.Parse(Console.ReadLine());
            var horseStartColumn = int.Parse(Console.ReadLine());

            matrix = new int[matrixHeight, matrixWidth];
            moves = new Queue<Horse>();

            var horse = new Horse(horseStartRow, horseStartColumn, StartValue);
            moves.Enqueue(horse);
            MoveThroughChessBoard();
            Output(matrixWidth, matrixHeight);
        }
コード例 #2
0
        private static void TryToMove(Horse knight, int deltaX, int deltaY)
        {
            var newX = knight.X + deltaX;
            var newY = knight.Y + deltaY;

            var isInsideTheMatrix = newX >= 0 && newX < matrix.GetLength(0) &&
                                    newY >= 0 && newY < matrix.GetLength(1);

            if (isInsideTheMatrix)
            {
                if (matrix[newX, newY] == 0)
                {
                    moves.Enqueue(new Horse(newX, newY, knight.Value + 1));
                }
            }
        }