예제 #1
0
        private static int GetNewDirection(PositionInMatrix position, int currrentDir)
        {
            while (!CanGoInThisDirection(position, currrentDir))
            {
                currrentDir = (currrentDir == 7) ? 0 : currrentDir + 1;
            }

            return currrentDir;
        }
예제 #2
0
 private static bool CanGoInThisDirection(PositionInMatrix position, int currentDir)
 {
     int nextRow = position.CurrenRow + directionsRow[currentDir];
     int nextCol = position.CurrentCol + directionsCol[currentDir];
     var result =
         IsInsideMatrix(nextRow, nextCol) &&
         matrix[nextRow, nextCol] == 0;
     return result;
 }
예제 #3
0
        private static bool IsNextToEmptyCell(PositionInMatrix position)
        {
            int row;
            int col;

            for (int i = 0; i < directionsRow.Length; i++)
            {
                row = position.CurrenRow + directionsRow[i];
                col = position.CurrentCol + directionsCol[i];
                if (IsInsideMatrix(row, col) && matrix[row, col] == 0)
                {
                    return true;
                }
            }

            return false;
        }
예제 #4
0
        private static bool TryGetEmptyCell(PositionInMatrix position)
        {
            for (int row = 0; row < matrix.GetLength(0); row++)
            {
                for (int col = 0; col < matrix.GetLength(1); col++)
                {
                    if (matrix[row, col] == 0)
                    {
                        position.CurrenRow = row;
                        position.CurrentCol = col;
                        return true;
                    }
                }
            }

            position.CurrenRow = 0;
            position.CurrentCol = 0;
            return false;
        }