예제 #1
0
        private void startButton_Click_1(object sender, EventArgs e)//开始搜索
        {
            myDraw.Change(CurrentLaby);
            myDraw.DrawLaby();
            MethodNum = 0;
            IsChosen  = new bool[6] {
                false, false, false, false, false, false
            };

            if (breadthBox.Checked)//使用宽度优先搜索
            {
                breadthSearch = new BreadthFirst(myDraw.Laby);
                MethodNum++;
                IsChosen[0] = true;
            }

            if (depthBox.Checked)//使用深度优先搜索
            {
                depthSearch = new DepthFirst(myDraw.Laby);
                MethodNum++;
                IsChosen[1] = true;
            }
            if (bestBox.Checked)//使用最佳优先搜索
            {
                bestSearch = new BestFirst(myDraw.Laby);
                MethodNum++;
                IsChosen[2] = true;
            }

            if (dijkstraBox.Checked)//使用一致代价搜索
            {
                dijkstraSearch = new Dijkstra(myDraw.Laby);
                MethodNum++;
                IsChosen[3] = true;
            }

            if (AstarBox.Checked)//使用A*搜索
            {
                astarSearch = new AStar(myDraw.Laby);
                MethodNum++;
                IsChosen[4] = true;
            }

            if (bibreadthBox.Checked)//使用双向宽度优先搜索
            {
                bibreadthSearch = new BiBreadthFirst(myDraw.Laby);
                MethodNum++;
                IsChosen[5] = true;
            }

            if (MethodNum == 0)
            {
                MessageBox.Show("请选择搜索算法以开始游戏!", "未选择");
                return;
            }
            labyPicture.Enabled         = false;
            generateButton.Enabled      = false;
            startButton.Enabled         = false;
            SaveButton.Enabled          = false;
            materialTab.SelectedTab     = showPage;
            materialTabSelector.Enabled = false;

            minPathLength = int.MaxValue;
            minPathCost   = int.MaxValue;

            initLabels();
            initTable();
            CurrentLine   = 0;
            CurrentMethod = 0;
            addLine();
            refreshTimer.Enabled = true;
            labelcost.Visible    = false;
            ResetButton.Enabled  = false;
        }