コード例 #1
0
ファイル: DFS.cs プロジェクト: kafunkajunk/Puzzle
        public void recursive_depth(State state)
        {
            if (ClosedSet.ContainsKey(state.Key) == false)
              {
            ClosedSet.Add(state.Key, state);
              }

              if (state.IsEqualToGoal())
              {
            watch.Stop();
            SolutionFound(state);

              }
              else
              {
            var list = state.BuildChildren();

            #if DEBUG
            Console.WriteLine("Children of node: {0}", state);
            foreach(var item in list){

              item.Format();
              Console.WriteLine();
            }

            #endif
            foreach (var item in list)
            {
              if (ClosedSet.ContainsKey(item.Key))
              {
            #if DEBUG
            Console.WriteLine("ClosedSet already contains key {0}", item.Key);
            #endif
            continue;
              }
              OpenSet.Push(item);
              if(!parents.ContainsKey(item.Key)) parents.Add(item.Key,state);
            }
            state = OpenSet.Pop();

            //Debugger.Break();
            if (OpenSet.Count == 0)
            {
              throw new Exception("no solution");
            }
            recursive_depth(state);
              }
        }
コード例 #2
0
ファイル: BiDirectional.cs プロジェクト: kafunkajunk/Puzzle
 public BiDirectional(int[] arr)
 {
     CurrentState = new State(arr);
 }
コード例 #3
0
ファイル: BiDirectional.cs プロジェクト: kafunkajunk/Puzzle
        private void SolutionFound(State FinalState)
        {
            //Debugger.Break();
              var temp = FinalState;

              while(true){

            if(!frontparents.ContainsKey(temp.Key)) break;

            moves.AddLast(frontparents[temp.Key]);
            temp = frontparents[temp.Key];

              }

              temp = FinalState;
              while(true){

            if(!backparents.ContainsKey(temp.Key)) break;
            moves.AddLast(backparents[temp.Key]);
            temp = backparents[temp.Key];

              }

              Console.WriteLine("Move list: ");
              var move = moves.First;
              int count = 0;
              while(move != null){

            Console.WriteLine( move.Value );
            move = move.Next;
            if(count++ > 100)break;

              }
              if(moves.Count > 100) Console.WriteLine("More than 100 ...");

              Console.WriteLine("Goal: ");
              new State(GlobalVar.GOAL).Format();

              Console.WriteLine("Number of expanded nodes: {0}", moves.Count);
        }
コード例 #4
0
ファイル: BFS.cs プロジェクト: kafunkajunk/Puzzle
 public BreadthFirst(int[] arr)
 {
     CurrentState = new State(arr);
 }
コード例 #5
0
ファイル: DFS.cs プロジェクト: kafunkajunk/Puzzle
 public DepthFirstSearch(int[] arr)
 {
     CurrentState = new State(arr);
 }
コード例 #6
0
ファイル: astar.cs プロジェクト: kafunkajunk/Puzzle
 public astar(int[] arr, bool heuristic)
 {
     CurrentState = new State(arr);
       use_manhattan = heuristic;
 }
コード例 #7
0
ファイル: greedy.cs プロジェクト: kafunkajunk/Puzzle
 public greedy(int[] arr)
 {
     CurrentState = new State(arr);
       parents[CurrentState.Key] = null;
 }
コード例 #8
0
ファイル: greedy.cs プロジェクト: kafunkajunk/Puzzle
        public void SolutionFound(State FinalState)
        {
            var temp = FinalState;
              while(true){
            if(parents[temp.Key] == null) break;
            moves.AddFirst(parents[temp.Key]);
            temp = parents[temp.Key];
              }

              Console.WriteLine("Move list: ");
              var move = moves.First;
              int count = 0;
              while(move != null) {

            Console.WriteLine( move.Value );
            move = move.Next;

            if(count++ > 100) break;

              }
              if(moves.Count > 100) Console.WriteLine("More than 100 ...");
              Console.WriteLine("Goal: ");
              new State(GlobalVar.GOAL).Format();

              Console.WriteLine("Number of expanded nodes: {0}", moves.Count);
        }