Im有一個返回結構的問題。它說運行時檢查失敗#2 - 圍繞變量「位置」堆棧已損壞,我不知道爲什麼。今晚我必須完成這個項目才能繼續進行其餘的項目。如果你知道,請幫忙。謝謝:)運行時檢查失敗#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;
}
非常感謝你。它現在完美了! – GeeKaush 2011-05-02 09:03:18