예제 #1
0
 public Strategy(PuzzleState init, RichTextBox box)
 {
     initial  = init;
     frontier = new Stack <PuzzleState>();
     frontier.Push(initial);
     rt = box;
     SolvePuzzle();
 }
예제 #2
0
        private void Solve_Click(object sender, EventArgs e)
        {
            if ((puzzle.Count != 0) || (dictionary.Count != 0))
            {
                PuzzleState puz = new PuzzleState(puzzle, dictionary, null, dataGridView1);
                Strategy    str = new Strategy(puz, richTextBox1);
            }

            else
            {
                MessageBox.Show("Please Load The Puzzle !!!", "Puzzle Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #3
0
        void SolvePuzzle()
        {
            bool Solved = false;

            while (frontier.Count > 0)
            {
                PuzzleState currentstate = frontier.Pop();

                currentstate.PrintPuzzle();
                if (currentstate.Wordfound != null)
                {
                    MessageBox.Show(currentstate.Wordfound + " Found", "Word Found", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    rt.AppendText("Word Found: " + currentstate.Wordfound + "\n");
                }

                if (GoalTest(currentstate))
                {
                    initial.PrintPuzzle();
                    MessageBox.Show("Puzzle Solved !!!", "Puzzle Solved", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    rt.AppendText("Puzzle Solved !!!");
                    Solved = true;
                    break;
                }

                for (int i = 0; i < currentstate.NextWords.Count; i++)
                {
                    frontier.Push(currentstate.NextWords[i]);
                }
            }

            if (!Solved)
            {
                MessageBox.Show("Puzzle Cannot Be Solved !!!", "Puzzle Not Solved", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                rt.AppendText("Puzzle Not Solved !!!");
            }
        }
예제 #4
0
 bool GoalTest(PuzzleState puz)
 {
     return(puz.CheckBlankPuzzle());
 }