Beispiel #1
0
        public override void Path_Finding()
        {
            if (draw_copy.Start_point.z == -1 || draw_copy.Finish_point.z == -1)
            {
                MessageBox.Show("Встановіть старт та фініш", "Помилка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                form1.lock_buttons();
                form1.Hide_load_form();
                return;
            }

            int find_step = 0;

            First_Step();
            bool flag_find_step = true;

            while (open_Cells.Count != 0)
            {
                Mode = form1.Flag_radioButtons;
                open_Cells.Sort((x, y) => x.H.CompareTo(y.H));
                struct_open_cell work_cell = open_Cells[0];
                open_Cells.RemoveAt(0);
                draw_copy.Closed_cell[work_cell.point.z] = work_cell.parent_cell.z;
                draw_copy.Check_point = work_cell.point;

                for (int i = 0; i < 4; i++)
                {
                    Side_checker(work_cell, Mas_OF_sides[i]);
                }

                if (form1.checkBox2.Checked)
                {
                    for (int i = 4; i < 8; i++)
                    {
                        Side_checker(work_cell, Mas_OF_sides[i]);
                    }
                }
                if ((draw_copy.Closed_cell[draw_copy.Finish_point.z] != 0) && (draw_copy.Step != 2))
                {
                    if (flag_find_step)
                    {
                        find_step      = draw_copy.Step;
                        flag_find_step = false;
                    }
                    if (form1.checkBox1.Checked)
                    {
                        form1.visualisation_mode(Mode, form1, 1);
                        open_Cells.Clear();
                        break;
                    }
                }
                form1.textBox1.Text = Convert.ToString(draw_copy.Step);
                form1.visualisation_mode(Mode, form1, 1);
                draw_copy.Step++;
            }
            form1.textBox1.Text = Convert.ToString(draw_copy.Step);
            if (find_step != 0)
            {
                Stack <Ppoint> way_back = new Stack <Ppoint>();
                way_back.Push(draw_copy.Finish_point);
                int previous_element = draw_copy.Closed_cell[draw_copy.Finish_point.z];

                while (way_back.Peek() != draw_copy.Start_point)
                {
                    int x = 0, y = 0;
                    Drowing.Reference_to_XY(ref x, ref y, previous_element, draw_copy.NColumnX);
                    way_back.Push(new Ppoint(x, y, previous_element));
                    previous_element = draw_copy.Closed_cell[previous_element];
                }
                draw_copy.Anim.draw_way(way_back);
                form1.update_panel_without_redraw();
                draw_copy.Show_Step(find_step);
            }
            else
            {
                form1.Hide_load_form();

                MessageBox.Show("Шлях не знайдено", "Повідомелння", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            Reset_Values();
            form1.Hide_load_form();
        }
Beispiel #2
0
        public override void Path_Finding()
        {
            if (draw_copy.Start_point.z == -1 || draw_copy.Finish_point.z == -1)
            {
                MessageBox.Show("Встановіть старт та фініш", "Помилка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                form1.lock_buttons();
                form1.Hide_load_form();
                return;
            }

            int find_step = 0;

            First_Step();
            bool flag_find_step = true;

            while (open_Cells.Count != 0)//Початок знаходження шляху
            {
                Mode = form1.Flag_radioButtons;
                open_Cells.Sort((x, y) => x.F.CompareTo(y.F));
                struct_open_cell work_cell = open_Cells[0];
                open_Cells.RemoveAt(0);
                draw_copy.Closed_cell[work_cell.point.z] = work_cell.parent_cell.z;//Кладемо в текущу комірку ту з якої прийшли
                draw_copy.Check_point = work_cell.point;

                //Перевірка по 4 чи по 8 напрямкам
                for (int i = 0; i < 4; i++)
                {
                    Side_checker(work_cell, Mas_OF_sides[i]);
                }

                if (form1.checkBox2.Checked)
                {
                    for (int i = 4; i < 8; i++)
                    {
                        Side_checker(work_cell, Mas_OF_sides[i]);
                    }
                }
                if ((draw_copy.Closed_cell[draw_copy.Finish_point.z] != 0) && (draw_copy.Step != 2))//Перевірка чи не кінець
                {
                    if (flag_find_step)
                    {
                        find_step      = draw_copy.Step;
                        flag_find_step = false;
                    }
                    if (form1.checkBox1.Checked)
                    {
                        form1.visualisation_mode(Mode, form1, 1);
                        open_Cells.Clear();
                        break;
                    }
                }
                form1.textBox1.Text = Convert.ToString(draw_copy.Step);
                form1.visualisation_mode(Mode, form1, 1);
                draw_copy.Step++;
            }

            form1.textBox1.Text = Convert.ToString(draw_copy.Step);
            if (find_step != 0)//Побудова зворотнього шялху якщо він взвгвлі є
            {
                Stack <Ppoint> way_back = new Stack <Ppoint>();
                way_back.Push(draw_copy.Finish_point);
                int previous_element = draw_copy.Closed_cell[draw_copy.Finish_point.z];

                while (way_back.Peek() != draw_copy.Start_point)//Шлях назад
                {
                    int x = 0, y = 0;
                    Drowing.Reference_to_XY(ref x, ref y, previous_element, draw_copy.NColumnX);
                    way_back.Push(new Ppoint(x, y, previous_element));//Накидуєтсья масив точок для результуючого шляху
                    previous_element = draw_copy.Closed_cell[previous_element];
                }
                draw_copy.Anim.draw_way(way_back);
                form1.update_panel_without_redraw();
                form1.Hide_load_form();
                draw_copy.Show_Step(find_step);
            }
            else
            {
                form1.Hide_load_form();
                MessageBox.Show("Шлях не знайдено", "Повідомелння", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            Reset_Values();
        }