Pawn.cpp 858 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. Figure* Pawn::copy() {
  13. static Pawn p(position, color);
  14. Figure* f = &p;
  15. return f;
  16. }
  17. vector<Position> Pawn::get_moves()
  18. {
  19. vector<Position> moves;
  20. Position p;
  21. try {
  22. if (color == 'W') p = Position(position.posSym, (char)(position.posNum+1));
  23. if (color == 'B') p = Position(position.posSym, (char)(position.posNum-1));
  24. }
  25. catch (const std::invalid_argument) {}
  26. moves.push_back(p);
  27. return moves;
  28. }
  29. const char* Pawn::print()
  30. {
  31. const char* me;
  32. if (color == 'B')
  33. me = "♟";
  34. else
  35. me = "♙";
  36. return me;
  37. }