Example #1
0
        private void setMazeSolverName()
        {
            _allSolver.Add(DeadEndFilling.staticGetName(), new DeadEndFilling());
            _allSolver.Add(BackTracking.staticGetName(), new BackTracking());
            _allSolver.Add(Astar.staticGetName(), new Astar());

            foreach (KeyValuePair <String, ISolver> entry in _allSolver)
            {
                listViewSolver.Items.Add(entry.Key);
            }
            listViewSolver.SelectedIndex = 0;
        }
Example #2
0
        // analyze image and fins starting and finishing points
        private void imageAnalyzer(Bitmap i)
        {
            Console.WriteLine("Analyzing");
            for (int x = 0; x < i.Width; x++)
            {
                for (int y = 0; y < i.Height; y++)
                {

                    if (i.GetPixel(x, y).ToArgb() == BLACK || x == 0 || y == 0 || x == i.Width - 1 || y == i.Height - 1)
                    {
                        this.iData[x, y] = WALL;

                    }
                    else if (i.GetPixel(x, y).ToArgb() == WHITE)
                    {

                        this.iData[x, y] = EMPTY;
                    }
                    else
                    {
                        if (!foundStart)
                        {

                            startColor = i.GetPixel(x, y).ToArgb();

                            foundStart = true;
                            start = new Tuple<int, int>(x, y);
                            s1 = start;
                            s2 = s1;
                            s3 = s1;
                            s4 = s1;

                        }
                        else
                        {
                            if (i.GetPixel(x, y).ToArgb() != startColor && !foundFinish)
                            {
                                finishColor = i.GetPixel(x, y).ToArgb();
                                finish = new Tuple<int, int>(x, y);
                                f1 = finish;
                                f2 = f1;
                                f3 = f1;
                                f4 = f1;
                                foundFinish = true;
                            }

                            if (foundStart)//start in the center of the start pixels
                            {
                                if (i.GetPixel(x, y).ToArgb() == startColor)
                                {
                                    if (x < s1.Item1)
                                    {
                                        s1 = new Tuple<int, int>(x, y);

                                    }
                                    else if (x > s2.Item1)
                                    {
                                        s2 = new Tuple<int, int>(x, y);
                                    }
                                    else if (y < s3.Item2)
                                    {
                                        s3 = new Tuple<int, int>(x, y);

                                    }
                                    else if (y > s4.Item2)
                                    {
                                        s4 = new Tuple<int, int>(x, y);
                                    }
                                }
                            }
                            if (foundFinish)//end in the center of finish pixels
                            {
                                if (i.GetPixel(x, y).ToArgb() == finishColor)
                                {
                                    if (x < f1.Item1)
                                    {
                                        f1 = new Tuple<int, int>(x, y);

                                    }
                                    else if (x > f2.Item1)
                                    {
                                        f2 = new Tuple<int, int>(x, y);
                                    }
                                    else if (y < f3.Item2)
                                    {
                                        f3 = new Tuple<int, int>(x, y);

                                    }
                                    else if (y > f4.Item2)
                                    {
                                        f4 = new Tuple<int, int>(x, y);
                                    }
                                }
                            }
                        }

                    }

                }

            }
            start = new Tuple<int, int>((Math.Abs((s1.Item1 + s2.Item1) / 2)), (Math.Abs((s3.Item2 + s4.Item2) / 2)));
            finish = new Tuple<int, int>((Math.Abs((f1.Item1 + f2.Item1) / 2)), (Math.Abs((f3.Item2 + f4.Item2) / 2)));

            algorithm1 = new Astar(start, finish, img, iData);
            algorithm2 = new Mccurdy(start, finish, img, iData);
        }