Exemple #1
0
        private static void EPuzzleTesterIDAStarHelper(String start, String goal, int value)
        {
            IStateSearchable <EightPuzzle> iss = new IDAStar <EightPuzzle>(EightPuzzleFactory.Create(start), EightPuzzleFactory.Create(goal));

            iss.FindPath();
            Assert.AreEqual(true, iss.HasSolution);
            Assert.AreEqual(value, iss.MinimumCost);
        }
Exemple #2
0
        // Done!
        private static void HeuristicHelper(string current, string goal, int value)
        {
            EightPuzzle pCurrent = EightPuzzleFactory.Create(current);
            EightPuzzle pGoal    = EightPuzzleFactory.Create(goal);

            int h = pCurrent.GetHeuristic(pCurrent, pGoal);

            Assert.AreEqual(value, h);
        }
Exemple #3
0
        static void Main()
        {
            Console.WriteLine("Type Start and End States. (One per line)");

            string startState = Console.ReadLine();
            string closeState = Console.ReadLine();

            if (string.IsNullOrWhiteSpace(startState) || startState.Trim().Length != 9)
            {
                startState = "012345678";
                Console.WriteLine("Assuming StartState as: {0}", startState);
            }

            if (string.IsNullOrWhiteSpace(closeState) || closeState.Trim().Length != 9)
            {
                closeState = "087654321";
                Console.WriteLine("Assuming StartState as: {0}", closeState);
            }

            IStateSearchable <EightPuzzle> stateSearch;

            try
            {
                EightPuzzle start = EightPuzzleFactory.Create(startState);
                EightPuzzle close = EightPuzzleFactory.Create(closeState);

                stateSearch = new AStar <EightPuzzle>(start, close);

                stateSearch.FindPath();

                if (stateSearch.HasSolution == false)
                {
                    Console.WriteLine("No solution Found");
                    Console.ReadKey();
                    return;
                }
            }
            catch
            {
                Console.WriteLine("Was not possible to solve the puzzle!");
                Console.ReadKey();
                return;
            }

            AnimateSolutions(stateSearch);
            Console.WriteLine("Cost: " + stateSearch.MinimumCost);
            Console.ReadKey();
        }
Exemple #4
0
        private static void EPuzzleMovesTesterHelper(IEnumerable <string> s, Move[] m)
        {
            List <EightPuzzle> p = new List <EightPuzzle>();

            foreach (var item in s)
            {
                p.Add(EightPuzzleFactory.Create(item));
            }

            IList <Move> moves = Moves(p);

            Assert.AreEqual(moves.Count, m.Length);

            Assert.AreEqual(moves.Count, m.Length);

            for (int i = 0; i < moves.Count; ++i)
            {
                Assert.AreEqual(moves[i], m[i]);
            }
        }
Exemple #5
0
        // Done!
        private static void MovesHelper(string parent, ICollection <string> childreen)
        {
            EightPuzzle pParent = EightPuzzleFactory.Create(parent);

            IList <EightPuzzle> pChildreen = pParent.Children();

            Assert.AreEqual(childreen.Count, pChildreen.Count);

            var q1 = from x in pChildreen
                     orderby x.ToString()
                     select x;

            var q2 = (from x in childreen
                      orderby x
                      select x).ToList();

            int i = 0;

            foreach (var item in q1)
            {
                Assert.AreEqual(q2[i++], item.ToString());
            }
        }