Asp.Net 8 Queen Web表单

问题描述

我的程序有问题:谁能帮忙找出问题所在?

如果我尝试使用lazieri()方法打印矩阵,则效果很好;但是,当我尝试从button1_click()方法打印矩阵时,所有成员都是假的。

namespace chesc
{  
    public partial class _Default : Page
    {
        private List<Board> boardList;
       
        string error;
        protected void Page_Load(object sender,EventArgs e)
        {

        }

        protected void Button1_Click(object sender,EventArgs e)
        {   
            error = "";
            Label1.Text = "";
            int boardSize = 1;
            int.TryParse(size.Text,out boardSize);
            int ansIndex = 0;
            int.TryParse(index.Text,out ansIndex);

            if (boardSize < 1)
            {
                error += "გთხოვთ მიუთითეთ დაფის კორექტული მნიშვნელობა\n";
            }
            else
            {
                boardList = new List<Board>();
                Board board = new Board() {
                    cBoard = new bool[boardSize,boardSize],boardSize = boardSize,hor = new bool[boardSize],ver = new bool[boardSize],diag_up = new bool[boardSize * 2 - 1],diag_down = new bool[boardSize * 2 - 1]
                };
                
                lazieri(board);
                if (ansIndex >= boardList.Count)
                {
                    Label1.Text = "min 0 max" + boardList.Count;
                }
                /* else
                 {
                     inputPanel.Visible = false;
                     tablePanel.Visible = true;

                     getTable(chesstable,boardList[0]);
                     TableRow tableRow = new TableRow();
                 }*/
                Label1.Text += "<br>";
                Label1.Text += "<br>";
                for (int q = 0; q < board.boardSize; q++)
                {

                    for (int w = 0; w < board.boardSize; w++)
                    {
                        Label1.Text += "" + board.cBoard[q,w];
                    }
                    Label1.Text += "<br>";
                }
            }
        }
       /* public void getTable(Table table,Board board)
        {
            for (int i = 0; i < board.boardSize; i++)
            {
                TableRow tableRow = new TableRow();
                chesstable.Controls.Add(tableRow);
                for (int j = 0; j < board.boardSize; j++)
                {
                    tableRow.Cells.Add(new TableCell() { Text= board.cBoard[i,j]? "♛" : "*" });
                }
            }
        }*/
        
        public void lazieri(Board board,int i = 0)
        {
            for (int j = 0; j < board.boardSize; j++)
            {
               if(!board.hor[i] && !board.ver[j] && !board.diag_down[i-j+board.boardSize-1] && !board.diag_up[i+j] && !board.cBoard[i,j])
                {
                    board.cBoard[i,j] = true;
                    board.hor[i] = true;
                    board.ver[j] = true;
                    board.diag_up[i + j] = true;
                    board.diag_down[i - j + board.boardSize - 1] = true;
                    if (i < board.boardSize - 1)
                    {
                        lazieri(board,(i + 1));
                    }
                    else
                    {
                        boardList.Add(board);
                        Label1.Text += "<br>";
                        Label1.Text += "<br>";
                        for (int q = 0; q < board.boardSize; q++)
                        {

                            for (int w = 0; w < board.boardSize; w++)
                            {
                                Label1.Text += "" + board.cBoard[q,w];
                            }
                            Label1.Text += "<br>";
                        }
                      
                    }
                    if (i < board.boardSize)
                    {
                        board.cBoard[i,j] = false;
                        board.hor[i] = false;
                        board.ver[j] = false;
                        board.diag_up[i + j] = false;
                        board.diag_down[i - j + board.boardSize - 1] = false;
                    }
                }
            }
        }

       
    }
}


public class Board
{
    public dynamic cBoard { get; set; }
    public dynamic hor { get; set; }
    public dynamic ver { get; set; }
    public dynamic diag_down { get; set; }
    public dynamic diag_up { get; set; }
    public int boardSize;
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)