Ejemplo n.º 1
0
        private void Button1_Click(object sender, EventArgs e)
        {
            Puzzle bufor = new Puzzle();

            if (sender is Puzzle)
            {
                Puzzle button = sender as Puzzle;

                if (CheckMove(button))
                {
                    bufor.Corner = button.Corner;
                    button.Corner = button9.Corner;
                    button9.Corner = bufor.Corner;
                }

                SetPuzzle();
            }
        }
Ejemplo n.º 2
0
        private void MovePuzzle()
        {
            foreach (MyPuzzle puzzle in curentState.allButton)
            {
                puzzle.ManhatanChange = false;

                if (curentPuzzle.curentBlock.Name == puzzle.curentBlock.Name)
                {
                    Puzzle bufor = new Puzzle();

                    for (int i = 0; i < 9; i++)
                    {
                        if (puzzle.curentBlock.Corner == Puzzle.AllCorner.LeftUP + i)
                        {
                            bufor.Corner = Puzzle.AllCorner.LeftUP + i;
                            break;
                        }
                    }

                    for (int i = 0; i < 9; i++)
                    {
                        if (curentState.allButton[8].curentBlock.Corner == Puzzle.AllCorner.LeftUP + i)
                        {
                            puzzle.curentBlock.Corner = Puzzle.AllCorner.LeftUP + i;
                            puzzle.ManhatanChange = true;
                            break;
                        }
                    }

                    curentState.allButton[8].curentBlock.Corner = bufor.Corner;
                    curentState.allButton[8].ManhatanChange = true;

                    break;
                }
            }
        }
Ejemplo n.º 3
0
        public string ReturnSolve()
        {
            bool calculate = true;
            Puzzle puzzle = new Puzzle();
            PuzzleState parent = new PuzzleState();

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

            finish.Add(closeState[closeState.Count - 1]);

            parent = closeState[closeState.Count - 1].parent;
            finish.Add(parent);

            while (calculate)
            {
                parent = FindParent(parent);
                finish.Add(parent);
                calculate = CheckStatus(parent, closeState[0]);
            }

            //foreach (PuzzleState state in finish)
            //{
            //    foreach (MyPuzzle myPuzzle in state.allButton)
            //    {
            //        if (myPuzzle.curentBlock.Name == "button9")
            //        {
            //            numberStep++;
            //            nextStep += numberStep.ToString() + " - " + myPuzzle.curentBlock.Corner + "\r\n";
            //        }
            //    }
            //}
            for (int i = finish.Count - 1; i != -1; i--)
            {
                for (int j = 8; j != -1; j--)
                {
                    numberStep++;
                    nextStep += numberStep.ToString() + " - " + finish[i].allButton[j].curentBlock.Corner + "\r\n";
                    break;
                }
            }

            return nextStep;
        }