コード例 #1
0
ファイル: Rubik.cs プロジェクト: mahdisml/SmlRubikSolver
        public string ida()
        {
            string result = "";

            if (check() == false)
            {
                return("This Rubik is InCorrect");
            }
            if (isGoal(start))
            {
                return("this is Goal");
            }

            int         limit  = 0;
            List <Cube> fringe = new List <Cube>();

            for (int i = 1; i <= 9; i++)
            {
                if (start.getNode(i).getF() > limit)
                {
                    limit = start.getNode(i).getF();
                }
                fringe.Add(start.getNode(i));
            }
            int nextLimit = limit + 999999999;

            while (true)
            {
                fringe = new List <Cube>();
                for (int i = 1; i <= 9; i++)
                {
                    fringe.Add(start.getNode(i));
                    if (isGoal(start.getNode(i)))
                    {
                        foreach (int m in start.getNode(i).getResult())
                        {
                            result = " > " + m;
                        }
                        return(result);
                    }
                }
                for (int j = 0; j < fringe.Count; j++)
                {
                    Cube cube = fringe[j];
                    for (int i = 1; i <= 9; i++)
                    {
                        if (isGoal(cube))
                        {
                            foreach (int m in cube.getResult())
                            {
                                result = " > " + m;
                            }
                            return(result);
                        }
                        if (cube.getNode(i).getF() <= limit)
                        {
                            fringe.Add(cube.getNode(i));
                            if (isGoal(cube.getNode(i)))
                            {
                                foreach (int m in cube.getNode(i).getResult())
                                {
                                    result = " > " + m;
                                }
                                return(result);
                            }
                        }
                        else
                        {
                            if (cube.getNode(i).getF() < nextLimit)
                            {
                                nextLimit = cube.getNode(i).getF();
                            }
                        }
                    }
                }
                limit     = nextLimit;
                nextLimit = nextLimit + 999999999;
            }

            return("not Found");
        }