Exemplo n.º 1
0
        public static void start(int size)
        {
            Stopwatch stopWatch_search = new Stopwatch();
            Stopwatch stopWatch_print  = new Stopwatch();

            puzzleSize = size;

            PuzzleState  startState = new PuzzleState();
            PuzzleSearch searcher   = new PuzzleSearch(startState);


            stopWatch_search.Start();

            searcher.DoSearch();
            stopWatch_search.Stop();

            TimeSpan t_search = stopWatch_search.Elapsed;

            IState state = searcher.Solutions[0];

            List <PuzzleState> solutionPath = new List <PuzzleState>();

            while (state != null)
            {
                solutionPath.Add((PuzzleState)state);
                state = state.Parent;
            }
            solutionPath.Reverse();

            int[,] table_tmp1 = new int[puzzleSize, puzzleSize];
            int[,] table_tmp2 = new int[puzzleSize, puzzleSize];

            table_tmp1 = solutionPath[0].Table;


            stopWatch_print.Start();

            foreach (PuzzleState s in solutionPath)
            {
                table_tmp2 = table_tmp1;
                table_tmp1 = s.Table;

                s.Print(table_tmp2, table_tmp1);
            }
            stopWatch_print.Stop();
            TimeSpan t_print = stopWatch_print.Elapsed;

            string SearchTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                              t_search.Hours, t_search.Minutes, t_search.Seconds,
                                              t_search.Milliseconds / 10);

            Console.WriteLine("Czas przeszukiwania " + SearchTime);

            string PrintTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                             t_print.Hours, t_print.Minutes, t_print.Seconds,
                                             t_print.Milliseconds / 10);

            Console.WriteLine("Czas wyswietlania " + PrintTime);
        }
Exemplo n.º 2
0
        protected override void buildChildren(IState parent)
        {
            PuzzleState state = (PuzzleState)parent;

            foreach (string id in state.id_list)
            {
                foreach (Heuristic_ways obj in state.Heuristic_vetor)
                {
                    if (obj.ID == id)
                    {
                        obj.h = PuzzleState.infinity;
                    }
                }
            }


            bool isZero = false;

            for (int i = 0; i <= (PuzzleState.PuzzleSize * PuzzleState.PuzzleSize * PuzzleState.PuzzleSize + state.G); i++)
            {
                foreach (Heuristic_ways obj in state.Heuristic_vetor)
                {
                    if (obj.F == i)
                    {
                        PuzzleState child = new PuzzleState(state, obj);
                        if (child.H == 0)
                        {
                            //isZero = true;
                        }
                        parent.Children.Add(child);
                        //state.Print(state.Table, child.Table);
                    }
                    if (isZero)
                    {
                        break;
                    }
                }
                if (isZero)
                {
                    break;
                }
            }
        }
Exemplo n.º 3
0
        public PuzzleState(PuzzleState parent, Heuristic_ways tmp) : base(parent)
        {
            this.table = new int[PuzzleSize, PuzzleSize];

            Array.Copy(tmp.Table, this.table, this.table.Length);
            // ciało konstruktora

            this.id = tmp.ID;
            id_list.Add(this.id);

            this.x = tmp.x;
            this.y = tmp.y;

            if (tmp.h != 0)
            {
                Heuristic_vector(x, y);
            }
            this.h = tmp.h;

            //W stanie w ktorym jestesmy droga jest o jeden większa niż w rodzicu
            this.g = parent.g + 1;
        }
Exemplo n.º 4
0
 public PuzzleSearch(PuzzleState state) : base(state, true, true)
 {
 }