/// <summary>
        /// Solves the specified maze.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="typeOfSolve">The type of solve.</param>
        /// <returns>the solve of the maze</returns>
        /// <exception cref="System.Exception">This maze does not exist - " + name</exception>
        public MazeSolution Solve(string name, int typeOfSolve)
        {
            if (mazesSolutions.ContainsKey(name))
            {
                return(mazesSolutions[name]);
            }

            if (mazes.ContainsKey(name))
            {
                Maze         maze = mazes[name];
                MazeSolution s    = Solve(maze, typeOfSolve);
                mazesSolutions.Add(name, s);
                return(s);
            }

            //if (multiPlayerWaiting.ContainsKey(name))
            //{
            //    Maze maze = multiPlayerWaiting[name];
            //    MazeSolution s = Solve(maze, typeOfSolve);
            //    mazesSolutions.Add(name, s);
            //    return s;
            //}

            throw new Exception("This maze does not exist - " + name);
        }
示例#2
0
        /// <summary>
        /// Froms the json.
        /// </summary>
        /// <param name="str">The string.</param>
        /// <returns></returns>
        public static MazeSolution FromJSON(string str)
        {
            MazeSolution ms  = new MazeSolution();
            JObject      obj = JObject.Parse(str);

            ms.GameName       = (string)obj["Name"];
            ms.SolutionString = (string)obj["Solution"];
            ms.EvaluatedNodes = (int)obj["NodesEvaluated"];
            return(ms);
        }
        /// <summary>
        /// Converts the solution of maze.
        /// </summary>
        /// <param name="s">The solution of the maze.</param>
        /// <param name="name">The name of the maze.</param>
        /// <returns>the maze solution</returns>
        private MazeSolution ConvertSolution(Solution <Position, int> s, string name)
        {
            List <Position> positionList = new List <Position>();

            foreach (State <Position, int> state in s.GetSolution())
            {
                positionList.Add(state.StateValue);
            }

            MazeSolution ms = new MazeSolution()
            {
                EvaluatedNodes = s.GetEvaluatedNodes(),
                Solution       = positionList,
                GameName       = name
            };

            return(ms);
        }
示例#4
0
        /// <summary>
        /// Solves the specified maze.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="typeOfSolve">The type of solve.</param>
        /// <returns>the solve of the maze</returns>
        /// <exception cref="System.Exception">This maze does not exist - " + name</exception>
        public MazeSolution Solve(string name, int typeOfSolve)
        {
            if (mazesSolutions.ContainsKey(name))
            {
                return(mazesSolutions[name]);
            }

            if (mazes.ContainsKey(name))
            {
                Maze         maze = mazes[name];
                MazeSolution s    = Solve(maze, typeOfSolve);
                mazesSolutions.Add(name, s);
                return(s);
            }



            throw new Exception("This maze does not exist - " + name);
        }