예제 #1
0
        public override void Solve()
        {
            States.Push(StartingState);
            int       bound    = HeuristicFunction(StartingState);
            bool      isSolved = false;
            Stopwatch timer    = new Stopwatch();

            timer.Start();

            while (isSolved != true)
            {
                var result = Search(bound);
                if (result.Item1)
                {
                    timer.Stop();
                    SolvedState = CurrentState;
                    Console.WriteLine("Done!");
                    isSolved = true;
                    continue;
                }

                if (result.Item2 == Int32.MaxValue)
                {
                    break;
                }

                bound = result.Item2;
            }

            if (timer.IsRunning)
            {
                timer.Stop();
            }

            DataWriter.WriteSolutionToFile(new InformationDataPack
            {
                SizeOfSolvedPuzzle = SolvedState?.DepthLevel ?? -1,
                Solution           = SolvedState?.GetPath() ?? "",
            }, SolutionPath);

            DataWriter.WriteInfoToFile(new InformationDataPack
            {
                DepthSize          = MaxDepth,
                SizeOfSolvedPuzzle = SolvedState?.DepthLevel ?? -1,
                StatesVisited      = Visited,
                StatesProcessed    = Visited,
                Time = timer.Elapsed.TotalMilliseconds
            }, InfoPath);
        }
예제 #2
0
 private static int LevelsInState(IEnumerable <SolvedStats> stats, Level.LevelType type, SolvedState state)
 {
     return(stats.Aggregate(0, (s, stat) => s + ((stat.State == state) ? 1 : 0)));
 }