Exemplo n.º 1
0
        /// <summary>
        /// Compute the solution of the SearchGame with the given name by using
        /// the algorithm in the input.
        /// </summary>
        /// <param name="name">
        /// The name of the SearchGame that will be solved.
        /// </param>
        /// <param name="algorithm">
        /// The algorithm that we will use.
        /// </param>
        /// <returns>
        /// The solution that was computed.
        /// </returns>
        public Solution <Position> ComputeSolution(string name, Algorithm algorithm)
        {
            ISearchGame game = GetGameByName(name);

            if (!ReferenceEquals(game, null))
            {
                // game was created/found
                string key = game.GetSearchArea();
                if (cache.IsSolved(key))
                {
                    //Maze already solved, get solution from cache.
                    return(cache.GetSolution(key));
                }
                Solution <Position> solution = numToAlgorithm[algorithm].Search(game.AsSearchable());
                //Add solution to the cache.
                cache.AddSolution(key, solution);
                return(solution);
            }
            return(new Solution <Position>());
        }