Esempio n. 1
0
        private static void RunSingleSearch(string initStateString, string goalStateString)
        {
            PuzzleState initState = new PuzzleState(initStateString);
            PuzzleState goalState = new PuzzleState(goalStateString);

            RunSingleSearch(initState, goalState);
        }
Esempio n. 2
0
        // runs all search algorithms for start and goal state
        private static void RunSingleSearch(PuzzleState initState, PuzzleState goalState)
        {
            var searcher = new Searcher(initState, goalState);

            // for 15-puzzle, cost from one state to next is always 1
            CostFunc cost = (fromState, toState) => 1;

            // do each search on a separate thread to speed things up
            var searchThreads = new List <Thread>
            {
                new Thread(() => Console.WriteLine(searcher.DepthFirstSearch(6).ToString())),
                new Thread(() => Console.WriteLine(searcher.DepthFirstSearch(12).ToString())),
                new Thread(() => Console.WriteLine(searcher.DepthFirstSearch(18).ToString())),
                new Thread(() => Console.WriteLine(searcher.IterativeDeepeningDfs().ToString())),
                new Thread(() => Console.WriteLine(searcher.BreadthFirstSearch().ToString())),
                new Thread(() => Console.WriteLine(searcher.UniformCostSearch(cost).ToString())),
                new Thread(() => Console.WriteLine(searcher.AStarSearch(cost, new MyHeuristic()).ToString())),
                new Thread(() => Console.WriteLine(searcher.GreedySearch(cost, new MyHeuristic()).ToString())),
                new Thread(() => Console.WriteLine(searcher.GreedySearch(cost, new ManhattanDistanceHeuristic()).ToString())),
                new Thread(() => Console.WriteLine(searcher.AStarSearch(cost, new ManhattanDistanceHeuristic()).ToString())),
            };

            // start all searches
            searchThreads.ForEach(x => x.Start());

            // wait for all searches to complete
            searchThreads.ForEach(x => x.Join());
        }
Esempio n. 3
0
        public PuzzleState Right()
        {
            PuzzleSpace oldVoidLocation = GetSpace(0);

            if (oldVoidLocation.Col == 3)
            {
                return(null);
            }

            PuzzleState newState        = Clone();
            PuzzleSpace newVoidLocation = new PuzzleSpace(oldVoidLocation.Row, oldVoidLocation.Col + 1);

            int valToBeSwapped = newState.Board[newVoidLocation.Row, newVoidLocation.Col];

            newState.Board[newVoidLocation.Row, newVoidLocation.Col] = 0;
            newState.Board[oldVoidLocation.Row, oldVoidLocation.Col] = valToBeSwapped;
            newState._valueLookup[0] = newVoidLocation;
            newState._valueLookup[valToBeSwapped] = oldVoidLocation;
            return(newState);
        }
Esempio n. 4
0
        private static void RunSingleSearch(PuzzleState initState, PuzzleState goalState)
        {
            Searcher searcher = new Searcher(initState, goalState);
            CostFunc cost     = (state1, state2) => 1;

            List <Thread> searchThreads = new List <Thread>()
            {
                new Thread(() => Console.WriteLine(searcher.BFS().ToString())),
                new Thread(() => Console.WriteLine(searcher.DFS(6).ToString())),
                new Thread(() => Console.WriteLine(searcher.DFS(12).ToString())),
                new Thread(() => Console.WriteLine(searcher.DFS(18).ToString())),
                new Thread(() => Console.WriteLine(searcher.UCS().ToString())),
                new Thread(() => Console.WriteLine(searcher.GreedyBestFirstSearch(new ManhattanDistanceHeuristic()).ToString())),
                new Thread(() => Console.WriteLine(searcher.AStarSearch(new ManhattanDistanceHeuristic()).ToString())),
                new Thread(() =>
                           Console.WriteLine(searcher.GreedyBestFirstSearch(new ManhanttanDistanceWithLinearConflictHeuristic()).ToString())),
                new Thread(() =>
                           Console.WriteLine(searcher.AStarSearch(new ManhanttanDistanceWithLinearConflictHeuristic()).ToString()))
            };

            searchThreads.ForEach(x => x.Start());

            searchThreads.ForEach(x => x.Join());
        }
Esempio n. 5
0
        // runs all search algorithms for start and goal state
        private static void RunSingleSearch(PuzzleState initState, PuzzleState goalState)
        {
            var searcher = new Searcher(initState, goalState);

            // for 15-puzzle, cost from one state to next is always 1
            CostFunc cost = (fromState, toState) => 1;

            // do each search on a separate thread to speed things up
            var searchThreads = new List<Thread>
            {
                new Thread(() => Console.WriteLine(searcher.DepthFirstSearch(6).ToString())),
                new Thread(() => Console.WriteLine(searcher.DepthFirstSearch(12).ToString())),
                new Thread(() => Console.WriteLine(searcher.DepthFirstSearch(18).ToString())),
                new Thread(() => Console.WriteLine(searcher.IterativeDeepeningDfs().ToString())),
                new Thread(() => Console.WriteLine(searcher.BreadthFirstSearch().ToString())),
                new Thread(() => Console.WriteLine(searcher.UniformCostSearch(cost).ToString())),
                new Thread(() => Console.WriteLine(searcher.AStarSearch(cost, new MyHeuristic()).ToString())),
                new Thread(() => Console.WriteLine(searcher.GreedySearch(cost, new MyHeuristic()).ToString())),
                new Thread(() => Console.WriteLine(searcher.GreedySearch(cost, new ManhattanDistanceHeuristic()).ToString())),
                new Thread(() => Console.WriteLine(searcher.AStarSearch(cost, new ManhattanDistanceHeuristic()).ToString())),
            };

            // start all searches
            searchThreads.ForEach(x => x.Start());

            // wait for all searches to complete
            searchThreads.ForEach(x => x.Join());
        }
Esempio n. 6
0
 // runs all search algorithms for start and goal state
 private static void RunSingleSearch(string initStateString, string goalStateString)
 {
     var initState = new PuzzleState(initStateString);
     var goalState = new PuzzleState(goalStateString);
     RunSingleSearch(initState, goalState);
 }