123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- #include "Horse.h"
- #include "Position.h"
- #include <utility>
- #include <stdexcept>
- #include <cmath>
- Horse::Horse(Position pos, char c) {
- if (c != 'B' and c != 'W')
- throw std::invalid_argument("Impossible color of figure!");
- position = pos;
- color = c;
- }
- std::pair<int, Position*> Horse::get_moves()
- {
- Position* moves = new Position[8];
- int moveNum = 0;
- for(int i = -2; i < 3; i++) {
- for(int j = -2; j < 3; j++) {
- if(std::abs(i) == std::abs(j) or i == 0 or j == 0) continue;
- Position p;
- // Position выдаст ошибку если указать невозможную позицию
- try {
- p = Position((char)(position.posSym+i), (char)(position.posNum+j));
- }
- catch (const std::invalid_argument) {
- continue;
- }
- moves[moveNum] = p;
- moveNum++;
- }
- }
- return std::pair<int, Position*>(8, moves);
- }
- const char* Horse::print()
- {
- const char* me;
- if (color == 'B')
- me = "♞";
- else
- me = "♘";
- return me;
- }
|