Beispiel #1
0
        static void Main(string[] args)
        {
            List <int[]> blocks = new List <int[]>();
            int          row = -1, col = -1;
            Task         t = readfile();

            Task.WaitAll(t);
            foreach (String line in lines)
            {
                row++;
                col = -1;
                foreach (char c in line)
                {
                    col++;
                    if (c == '*')
                    {
                        blocks.Add(new[] { row, col });
                    }
                    else if (c == 'c')
                    {
                        start = new[] { row, col }
                    }
                    ;
                    else if (c == 'e')
                    {
                        end = new[] { row, col }
                    }
                    ;
                }
            }

            matrixElement[,] matrix = new matrixElement[3, 3];
            operations op = new operations();

            matrix = op.Create_matrix((row + 1), (col + 1), blocks, start, end);
            op.finding_path(matrix, start, start, new[] { 5, 5 });
            List <int[, ]> array = op.smallest_list();

            Console.ReadLine();
            //CanTok.Cancel();

            //ThreadPool.QueueUserWorkItem(l => operations.finding_path(matrix, new[] { 4, 0 }, new[] { 4, 0 }, new[] { 5, 5 }));
            //new Task(operations.finding_path,object{matrix, new[] { 4, 0 }, new[] { 4, 0 }, new[] { 5, 5 });
        }
    }
Beispiel #2
0
 public matrixElement[,] Create_matrix(int row, int column, List <int[]> blocks, int[] start_element, int[] end_element)//بكريت الماتريكس بناء على الانبوت اللى داخلها
 {
     matrixElement[,] matrix = new matrixElement[row, column];
     for (int i = 0; i < row; i++)
     {
         for (int j = 0; j < column; j++)
         {
             matrix[i, j] = new matrixElement();
         }
     }
     for (int k = 0; k < blocks.Count; k++)
     {
         Addblocks(k, row, column, blocks, matrix);                                // parallel for
     }
     Parallel.For(0, blocks.Count, k => Addblocks(k, row, column, blocks, matrix));
     matrix[start_element[0], start_element[1]].element_type = 1;
     matrix[end_element[0], end_element[1]].element_type     = 2;
     return(matrix);
 }