Pawn.cpp 660 B

1234567891011121314151617181920212223242526272829303132333435
  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. p = Position(position.posSym, (char)(position.posNum+1));
  18. }
  19. catch (const std::invalid_argument) {}
  20. moves.push_back(p);
  21. return moves;
  22. }
  23. const char* Pawn::print()
  24. {
  25. const char* me;
  26. if (color == 'B')
  27. me = "♟";
  28. else
  29. me = "♙";
  30. return me;
  31. }