示例#1
0
 public override void Update()
 {
     if (Input.KeyPressed(Key.D))
     {
         var search = new DFS <NearbyTiles, MoveAction>(_graphSearch);
         Game.SwitchScene(new LabyrinthScene <NearbyTiles, MoveAction>(_problem, search, _graphSearch));
     }
     else if (Input.KeyPressed(Key.B))
     {
         var graphSearchBFS = new GraphSearchBFS <NearbyTiles, MoveAction>();
         var search         = new BFS <NearbyTiles, MoveAction>(graphSearchBFS);
         Game.SwitchScene(new LabyrinthScene <NearbyTiles, MoveAction>(_problem, search, graphSearchBFS));
     }
     else if (Input.KeyPressed(Key.G))
     {
         var search = new GreedySearch <NearbyTiles, MoveAction>(_graphSearch,
                                                                 node => Math.Abs(21 - node.State.Center.X) + Math.Abs(20 - node.State.Center.Y));
         Game.SwitchScene(new LabyrinthScene <NearbyTiles, MoveAction>(_problem, search, _graphSearch));
     }
     else if (Input.KeyPressed(Key.A))
     {
         var search = new AStarSearch <NearbyTiles, MoveAction>(_graphSearch,
                                                                node => Math.Abs(21 - node.State.Center.X) + Math.Abs(20 - node.State.Center.Y));
         Game.SwitchScene(new LabyrinthScene <NearbyTiles, MoveAction>(_problem, search, _graphSearch));
     }
 }
示例#2
0
        /**
         * Creates a search instance.
         *
         * @param strategy
         *            search strategy. See static constants.
         * @param qSearchImpl
         *            queue search implementation: e.g. {@link #TREE_SEARCH}, {@link #GRAPH_SEARCH}
         *
         */
        public ISearchForActions <S, A> createSearch <S, A>(int strategy, int qSearchImpl, IToDoubleFunction <Node <S, A> > h)
        {
            QueueSearch <S, A>       qs     = null;
            ISearchForActions <S, A> result = null;

            switch (qSearchImpl)
            {
            case TREE_SEARCH:
                qs = new TreeSearch <S, A>();
                break;

            case GRAPH_SEARCH:
                qs = new GraphSearch <S, A>();
                break;

            case GRAPH_SEARCH_RED_FRONTIER:
                qs = new GraphSearchReducedFrontier <S, A>();
                break;

            case GRAPH_SEARCH_BFS:
                qs = new GraphSearchBFS <S, A>();
                break;

            case BIDIRECTIONAL_SEARCH:
                qs = new BidirectionalSearch <S, A>();
                break;
            }
            switch (strategy)
            {
            case DF_SEARCH:
                result = new DepthFirstSearch <S, A>(qs);
                break;

            case BF_SEARCH:
                result = new BreadthFirstSearch <S, A>(qs);
                break;

            case ID_SEARCH:
                result = new IterativeDeepeningSearch <S, A>();
                break;

            case UC_SEARCH:
                result = new UniformCostSearch <S, A>(qs);
                break;

            case GBF_SEARCH:
                result = new GreedyBestFirstSearch <S, A>(qs, h);
                break;

            case ASTAR_SEARCH:
                result = new AStarSearch <S, A>(qs, h);
                break;

            case RBF_SEARCH:
                result = new RecursiveBestFirstSearch <S, A>(new AStarSearch <S, A> .EvalFunction(h));
                break;

            case RBF_AL_SEARCH:
                result = new RecursiveBestFirstSearch <S, A>(new AStarSearch <S, A> .EvalFunction(h), true);
                break;

            case HILL_SEARCH:
                result = new HillClimbingSearch <S, A>(h);
                break;
            }
            return(result);
        }