So I tried "putting together" a chess game with a simple AI (Minimax algo) and it gave me the above error. I am kinda clueless as to how to proceed. Also please ignore the dummy print statements. TIA!
std::vector<move> possibleMoves(char pieceColor)
{ std::vector<move> output;
move toAdd;
for (int iRow = 0; iRow < 8; ++iRow) {
for (int iCol = 0; iCol < 8; ++iCol) {
if (MainGameBoard[iRow][iCol] != 0) {
// If it is a piece of the current player, see if it has a legal move
if (MainGameBoard[iRow][iCol]->GetColor() == pieceColor) {
for (int iMoveRow = 0; iMoveRow < 8; ++iMoveRow) {
for (int iMoveCol = 0; iMoveCol < 8; ++iMoveCol) {
if (MainGameBoard[iRow][iCol]->IsLegalMove(iRow, iCol, iMoveRow, iMoveCol, MainGameBoard)) {
// Make move and check whether king is in check
GamePiece* qpTemp = MainGameBoard[iMoveRow][iMoveCol];
MainGameBoard[iMoveRow][iMoveCol] = MainGameBoard[iRow][iCol];
MainGameBoard[iRow][iCol] = 0;
bool bCanMove = !IsInCheck(pieceColor);
// Undo the move
MainGameBoard[iRow][iCol] = MainGameBoard[iMoveRow][iMoveCol];
MainGameBoard[iMoveRow][iMoveCol] = qpTemp;
if (bCanMove) {
toAdd.srcrow=iRow;
toAdd.srccol=iCol;
toAdd.destrow=iMoveRow;
toAdd.destcol=iMoveCol;
output.push_back(toAdd);
}
}
}
}
}
}
}
}
return output;
}
move minimax(int depth, bool minimize){
move best_move;
best_move.score = -1000000 + 2000000*minimize;
if(0 == depth){
best_move.score = score();
return best_move;
}
for(auto & to : possibleMoves('B')){
This is the line that might be giving the error:
CBoard branch = *this;
branch.makemove(to);
move option = branch.minimax(depth-1, !minimize);
if((option.score > best_move.score && !minimize) || (option.score < best_move.score && minimize)){
best_move.score = option.score;
best_move.srccol = to.srccol;
best_move.destcol = to.destcol;
best_move.srcrow = to.srcrow;
best_move.destrow = to.destrow;
}
}
return best_move;
}
}
Link to whole code: