示例#1
0
        public LinkedList <KnightSpearmanState> Solve(KnightSpearmanState initial)
        {
            closed = new List <KnightSpearmanState>();
            AddState(initial);

            while (HasElements())
            {
                KnightSpearmanState state = NextState();

                if (state.IsSolution())
                {
                    return(FindPath(state));
                }

                closed.Add(state);

                LinkedList <KnightSpearmanState> moves = state.GetPossibleMoves();

                foreach (KnightSpearmanState move in moves)
                {
                    if (!closed.Contains(move))
                    {
                        AddState(move);
                    }
                }
            }

            return(null);
        }
示例#2
0
        static void Main(string[] args)
        {
            KnightSpearmanState knightsSpearman    = new KnightSpearmanState();
            LinkedList <KnightSpearmanState> moves = null;
            DFS solver = new DFS();

            moves = solver.Solve(knightsSpearman);

            int n = 1;

            foreach (KnightSpearmanState state in moves)
            {
                KnightSpearmanState nextState = (KnightSpearmanState)state;

                Console.WriteLine(n.ToString() + " ");

                if (nextState.IsSolution())
                {
                    Console.WriteLine("Solution");
                }

                Console.WriteLine(nextState.ToString());
                n++;
            }

            Console.ReadKey();
        }