#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;
}

vector<Position> Horse::get_moves()
{
    vector<Position> moves;
    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.push_back(p);
        }
    }
    return moves;
}

const char* Horse::print()
{
    const char* me;
    if (color == 'B')
        me = "♞";
    else
        me = "♘";
    return me;
}