Beispiel #1
0
        private void button4_Click(object sender, EventArgs e)
        {
            Queue <park> Q = new Queue <park> ();

            Q.Enqueue(p1);

            label1.Text = "Working ..."; Application.DoEvents();

            searchResults r = parkSpaceLogic.SpaceSearch2(Q);

            int sol_count = 0;

            int steps_to_sol = -1;

            if (r.solutions != null)
            {
                sol_count = r.solutions.Count;
            }

            int state_count = r.states;

            if (r.solutions.Count > 0)
            {
                searchResults r2 = parkSpaceLogic.SpaceSearch2(r.solutions);

                steps_to_sol = r2.D[p1.GetHashCode()];
            }

            label1.Text = state_count.ToString() + " states, " + sol_count.ToString() + " solution(s), " + steps_to_sol.ToString() + " steps to solution";
        }
Beispiel #2
0
        private void button8_Click(object sender, EventArgs e)
        {
            label1.Text = "Solving ...";

            Queue <park> Q = new Queue <park>();

            Q.Enqueue(p1);

            searchResults r = parkSpaceLogic.SpaceSearch2(Q);

            if (r.solutions.Count == 0)
            {
                MessageBox.Show("No solutions found!", "Error");

                return;
            }

            searchResults r2 = parkSpaceLogic.SpaceSearch2(r.solutions);

            int current_steps_to_sol = r2.D[p1.GetHashCode()];

            int moveCount = 0;

            while (current_steps_to_sol > 0)
            {
                moveCount++;

                movesList L = parkLogic.generateMoves2(p1);

                for (int i = 0; i < L.count; i++)
                {
                    park p2 = p1.Clone();

                    p2 = parkLogic.makeMove2(p2, L.car_ind[i], L.dir[i]);

                    int steps_to_sol = r2.D[p2.GetHashCode()];

                    if (steps_to_sol < current_steps_to_sol)
                    {
                        current_steps_to_sol = steps_to_sol;

                        p1 = parkLogic.makeMove2(p1, L.car_ind[i], L.dir[i]);

                        pictureBox1.Refresh();

                        Application.DoEvents();

                        System.Threading.Thread.Sleep(250);

                        break;
                    }
                }
            }

            label1.Text = "Done1";
        }