std::vector<Move> Chessboard::getMoves(char color) { std::vector<Move> moves; char kingInCheck = 0; for (int row = 0; row < 8; row++) { for (int col = 0; col < 8; col++) { if (getColor(row, col) == color) { std::vector<Move> m; char piece = get(row, col); if (isPawn(piece)) { m = getPawnMoves(*this, row, col); } else if (isKnight(piece)) { m = getKnightMoves(*this, row, col); } else if (isBishop(piece)) { m = getBishopMoves(*this, row, col); } else if (isRook(piece)) { m = getRookMoves(*this, row, col); } else if (isQueen(piece)) { m = getQueenMoves(*this, row, col); } else if (isKing(piece)) { m = getKingMoves(*this, row, col); } moves.insert(moves.end(), m.begin(), m.end()); } } } buildCheckBoard(moves); return moves; }
static int performAction(pawn *currentPawn, pawn *targetPawn) { if (targetPawn == NULL) { ///< Targeted field was empty. return UNIT_MOVED; } if (isKing(currentPawn)) { if (isKing(targetPawn)) { return BOTH_UNITS_DIED; } else if (isPeasant(targetPawn)) { return ATTACKER_KILLED; } else if (isKnight(targetPawn)) { return DEFENDER_KILLED_KING; } else { return ERROR; } } else if (isPeasant(currentPawn)) { if (isKing(targetPawn)) { return DEFENDER_KILLED; } else if (isPeasant(targetPawn)) { return BOTH_UNITS_DIED; } else if (isKnight(targetPawn)) { return DEFENDER_KILLED; } else { return ERROR; } } else if (isKnight(currentPawn)) { if (isKing(targetPawn)) { return ATTACKER_KILLED_KING; } else if (isPeasant(targetPawn)) { return ATTACKER_KILLED; } else if (isKnight(targetPawn)) { return BOTH_UNITS_DIED; } else { return ERROR; } } else { return ERROR; } }