// we will pick up the mines one by one in the reverse order and
// test the minefield inconsistency each time
for(int i = 0; i < minesCount; i++) {
int lastIndex = (minesCount - 1) - i;
Coord minedCoord = minedFields.get(lastIndex);
pickUpMine(minedCoord);
pickedUpMines++;
if(checkOneField(affectedField)) {
// the minefield has a chance to be consistent now
// we will store the number of picked up mines
backjumpLength = pickedUpMines - 1;
break;
}
}
// now we have to put the removed mines back
for(int i = 0; i < pickedUpMines; i++)
{
int lastIndex = (minesCount - 1) - i;
Coord minedCoord = minedFields.get(lastIndex);
if(!canPutMine(minedCoord)) {
throw new MinesSolverInternalError("Unable to put back removed mines.");
}