【发布时间】:2011-05-02 08:45:46
【问题描述】:
我在返回结构时遇到问题。它说运行时检查失败 #2 - 变量“位置”周围的堆栈已损坏,我不知道为什么。我必须在今晚之前完成这项工作,才能继续该项目的其余部分。如果您知道,请提供帮助。谢谢你:)
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;
}
【问题讨论】: