如何解决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 举报,一经查实,本站将立刻删除。