Pawn.cpp 762 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include "Pawn.h"
  2. #include "Position.h"
  3. #include <utility>
  4. #include <stdexcept>
  5. #include <iostream>
  6. Pawn::Pawn(Position pos, char c) {
  7. if (c != 'B' and c != 'W')
  8. throw std::invalid_argument("Impossible color of figure!");
  9. position = pos;
  10. color = c;
  11. }
  12. vector<Position> Pawn::get_moves()
  13. {
  14. vector<Position> moves;
  15. Position p;
  16. try {
  17. if (color == 'W') p = Position(position.posSym, (char)(position.posNum+1));
  18. if (color == 'B') p = Position(position.posSym, (char)(position.posNum-1));
  19. }
  20. catch (const std::invalid_argument) {}
  21. moves.push_back(p);
  22. return moves;
  23. }
  24. const char* Pawn::print()
  25. {
  26. const char* me;
  27. if (color == 'B')
  28. me = "♟";
  29. else
  30. me = "♙";
  31. return me;
  32. }