Pawn.cpp 733 B

12345678910111213141516171819202122232425262728293031323334353637
  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. std::pair<int, Position*> Pawn::get_moves()
  13. {
  14. Position* moves = new Position[1];
  15. Position p;
  16. try {
  17. p = Position(position.posSym, (char)(position.posNum+1));
  18. }
  19. catch (const std::invalid_argument) {
  20. p = Position();
  21. }
  22. moves[0] = p;
  23. return std::pair<int, Position*>(1, moves);
  24. }
  25. const char* Pawn::print()
  26. {
  27. const char* me;
  28. if (color == 'B')
  29. me = "♟";
  30. else
  31. me = "♙";
  32. return me;
  33. }