gpt4 book ai didi

c++ - 运行时检查失败 #2 - 变量 'positions' 周围的堆栈已损坏

转载 作者:行者123 更新时间:2023-11-28 03:49:59 26 4
gpt4 key购买 nike

我在返回结构时遇到问题。它说 Run-Time Check Failure #2 - Stack around the variable 'positions' was corrupted 我不知道为什么。我必须在今晚之前完成这项工作才能继续该项目的其余部分。知道的帮帮忙。谢谢:)

struct Position
{
int SrcDstScore[50][5];
char pieceColor [50][2];
};

int Sort(Position s2, Position s1)
{
int x; // use compreto method
return x;
}
Position EvaluateMoves(Piece * theBoard[8][8])
{
//store my result boards here
Position positions;
for (int t=0; t<50; t++)
{
positions.SrcDstScore[t][1]= 0;
positions.SrcDstScore[t][2]= 0;
positions.SrcDstScore[t][3]= 0;
positions.SrcDstScore[t][4]= 0;
positions.SrcDstScore[t][5]= 0;
positions.pieceColor[t][1]= ' ';
positions.pieceColor[t][2]= ' ';
//cout << "Eval";
}
char mcPlayerTurn = 'w';
int counter = 0;
// Fetching the board containing positions of these pieces
for (int Row = 0; Row < 8; ++Row)
{
for (int Col = 0; Col < 8; ++Col)
{
if (theBoard[Row][Col] != 0)
{
if (theBoard[Row][Col]->GetColor() == 'w')
{
Piece * piece = theBoard[Row][Col];
for (int MoveableRow = 0; MoveableRow < 8; ++MoveableRow) // Now that we have found the knight find the legal squares.
{
for (int MoveableCol = 0; MoveableCol < 8; ++MoveableCol)
{
if(piece->IsLegalMove(Row, Col, MoveableRow, MoveableCol, theBoard))
{
cout << counter << theBoard[Row][Col]->GetPiece() << " " << theBoard[Row][Col]->GetColor() <<" " << Row <<" " << Col <<" " << MoveableRow <<" " << MoveableCol << "\n";
positions.SrcDstScore[counter][1]= Row;
positions.SrcDstScore[counter][2]= Col;
positions.SrcDstScore[counter][3]= MoveableRow;
positions.SrcDstScore[counter][4]= MoveableCol;

//If the move is a capture add it's value to the score
if (theBoard[MoveableRow][MoveableRow] != 0)
{
positions.SrcDstScore[counter][5] += theBoard[MoveableRow][MoveableRow]->GetValue();

if (theBoard[Row][Row]->GetValue() < theBoard[MoveableRow][MoveableRow]->GetValue())
{
positions.SrcDstScore[counter][5] += theBoard[MoveableRow][MoveableRow]->GetValue() - theBoard[Row][Row]->GetValue();
}
//Add Score for Castling
}
counter ++;
}
}
}
}
}
}
}

return positions;
}

最佳答案

在初始循环中,您分别使用索引 1 到 5 和 1 到 2 索引到 SrcDstScorepieceColor。这些应该是索引 0 到 4 和 0 到 1。

这同样适用于往下,在这一行和它之后的三行:

positions.SrcDstScore[counter][1]= Row;

在您有 positions.SrcDstScore[counter][5] 的两个实例中,应该是 ...[4]

关于c++ - 运行时检查失败 #2 - 变量 'positions' 周围的堆栈已损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5855147/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com