Esempio n. 1
0
 /// <summary>
 /// do the command from the menu
 /// </summary>
 /// <param name="parameters">params of the command</param>
 public override void DoCommand(params string[] parameters)
 {
     try
     {
         if (parameters.Length != 2)
         {
             m_view.Output("We expected for 2 parameters!"); // check the params
             return;
         }
         string name = parameters[0];
         string alg  = parameters[1];
         if (checkingIfProper(name, alg) == true)
         {
             ASearchingAlgorithm new_alg = m_model.checkAlg(alg);
             m_view.Output("Solve the maze <" + name + "> with the algorithm <" + alg + ">"); // open new Thread
             m_model.SolveMaze(name, new_alg);
             m_view.Output("Solution for maze <" + name + "> is ready!");                     // succeded
         }
     }
     catch (Exception e)
     {
         m_view.Output("The maze <" + parameters[0] + "> couldn't be solved!");
         m_view.Output(e.Message);
     }
 }
Esempio n. 2
0
        public void SolveMaze(string maze_name, ASearchingAlgorithm alg)
        {
            Thread thread = new Thread(() => SolveMazeInNewThread(maze_name, alg));

            thread.Name = "SolveMazeThread";
            thread.Start();
            m_threads.Add(thread);
            //  m_controller.Output("Solution for maze <" + name + "> is ready!"); // succeded
        }
Esempio n. 3
0
        /// <summary>
        /// solve the maze in new Thread
        /// </summary>
        /// <param name="name">mame of the thread</param>
        /// <param name="new_alg">alg of solving</param>
        private void SolveMazeInNewThread(string name, ASearchingAlgorithm new_alg)
        {
            Maze             m_from_dic    = m_DicOfMazes[name];
            Maze3d           m_3d          = m_from_dic as Maze3d;
            SearchableMaze3d maze3dS       = new SearchableMaze3d(m_3d);
            Solution         maze_solution = new_alg.Solve(maze3dS); // solve the maze

            IfSolutionExist(name);                                   // if the solution exist with identical name - remove it.
            m_solutions.Add(name, maze_solution);                    // add to dictionary of solutions
        }
Esempio n. 4
0
        /// <summary>
        /// rin in thread pool the solution
        /// </summary>
        /// <param name="maze_name">name of the maze</param>
        /// <param name="alg">algorithem to solve the maze</param>
        private void RunInThreadPoolOfSolution(Maze maze, string name)
        {
            ThreadPool.QueueUserWorkItem
            (
                new WaitCallback((state) =>
            {
                ASearchingAlgorithm new_alg = checkAlg();
                Maze m_from_dic             = m_DicOfMazes[name];
                Maze3d m_3d = m_from_dic as Maze3d;
                SearchableMaze3d maze3dS = new SearchableMaze3d(m_3d);
                Solution maze_solution   = new_alg.Solve(maze3dS); // solve the maze

                m_solutions.Add(name, maze_solution);              // add to dictionary of solutions
                m_mazeAndSolutions.Add(maze, maze_solution);
                ModelChanged("SolutionIsReady", name);
            })
            );
        }