#include "Horse.h" #include "Position.h" #include #include #include 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 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(8, moves); } const char* Horse::print() { const char* me; if (color == 'B') me = "♞"; else me = "♘"; return me; }