|
@@ -22,6 +22,7 @@ bool compare_by_angle(std::pair<int, int> pos1, std::pair<int, int> pos2)
|
|
|
|
|
|
vector<Position> Chessboard::get_possible_moves(Figure* fig)
|
|
|
{
|
|
|
+ // std::cout << "\n\n\n1111111111\n\n\n";
|
|
|
vector<Position> moves = fig->get_moves();
|
|
|
vector<std::pair<int, int>> grouped_moves;
|
|
|
vector<Position> possible_moves;
|
|
@@ -33,6 +34,7 @@ vector<Position> Chessboard::get_possible_moves(Figure* fig)
|
|
|
|
|
|
bool blockedGroup = false;
|
|
|
|
|
|
+ // Проверяем первую фигуру
|
|
|
Figure* check_cell;
|
|
|
check_cell = board[grouped_moves[0].second+pos.posNum-'0'-1][grouped_moves[0].first+pos.posSym-'A'].get_figure();
|
|
|
if (check_cell != nullptr) {
|
|
@@ -41,14 +43,18 @@ vector<Position> Chessboard::get_possible_moves(Figure* fig)
|
|
|
}
|
|
|
else possible_moves.push_back(Position((char)(grouped_moves[0].first+pos.posSym), (char)(grouped_moves[0].second+pos.posNum)));
|
|
|
|
|
|
+ // Проверяем остальные
|
|
|
for(int i = 1; i < grouped_moves.size(); i++) {
|
|
|
+ // Разделение на разные группы по углу относ фигуры
|
|
|
if (std::atan2(grouped_moves[i-1].first, grouped_moves[i-1].second) != std::atan2(grouped_moves[i].first, grouped_moves[i].second)) {
|
|
|
blockedGroup = false;
|
|
|
}
|
|
|
+ // Пропускаем позиции перед которыми препядствие
|
|
|
if (blockedGroup == true) continue;
|
|
|
|
|
|
check_cell = board[grouped_moves[i].second+pos.posNum-'0'-1][grouped_moves[i].first+pos.posSym-'A'].get_figure();
|
|
|
|
|
|
+ // Добавление
|
|
|
if (check_cell != nullptr) {
|
|
|
blockedGroup = true;
|
|
|
if (check_cell->get_color() != fig->get_color()) possible_moves.push_back(Position(grouped_moves[i].first+pos.posSym, (char)(grouped_moves[i].second+pos.posNum)));
|
|
@@ -58,6 +64,35 @@ vector<Position> Chessboard::get_possible_moves(Figure* fig)
|
|
|
possible_moves.push_back(Position((char)(grouped_moves[i].first+pos.posSym), (char)(grouped_moves[i].second+pos.posNum)));
|
|
|
}
|
|
|
|
|
|
+ if (fig->print()[2] == "♟"[2] or fig->print()[2] == "♙"[2]) {
|
|
|
+ // std::cout << "pawn\n";
|
|
|
+ // std::cout << (char)(possible_moves[0].posSym+1) << (char)(possible_moves[0].posNum) << '\n';
|
|
|
+ try {
|
|
|
+ // std::cout << possible_moves[0].posSym+1 << possible_moves[0].posNum << '\n';
|
|
|
+ if (possible_moves.size() > 0 and
|
|
|
+ get_cell(Position(possible_moves[0].posSym+1, possible_moves[0].posNum)).get_figure() != nullptr
|
|
|
+ and get_cell(Position(possible_moves[0].posSym+1, possible_moves[0].posNum)).get_figure()->get_color() != fig->get_color())
|
|
|
+ possible_moves.push_back(Position(possible_moves[0].posSym+1, possible_moves[0].posNum));
|
|
|
+ }
|
|
|
+ catch( std::invalid_argument ) {}
|
|
|
+ // std::cout << (char)(possible_moves[0].posSym+1) << (char)(possible_moves[0].posNum) << '\n';
|
|
|
+ try {
|
|
|
+ // std::cout << possible_moves[0].posSym+1 << possible_moves[0].posNum << '\n';
|
|
|
+ if (possible_moves.size() > 0 and
|
|
|
+ get_cell(Position(possible_moves[0].posSym-1, possible_moves[0].posNum)).get_figure() != nullptr
|
|
|
+ and get_cell(Position(possible_moves[0].posSym-1, possible_moves[0].posNum)).get_figure()->get_color() != fig->get_color())
|
|
|
+ possible_moves.push_back(Position(possible_moves[0].posSym-1, possible_moves[0].posNum));
|
|
|
+ }
|
|
|
+ catch( std::invalid_argument ) {}
|
|
|
+ if (possible_moves.size() > 0 and get_cell(possible_moves[0]).get_figure() != nullptr ) {
|
|
|
+ vector<Position> possible_swap;
|
|
|
+ for(int i = 1; i < possible_moves.size(); i++) {
|
|
|
+ possible_swap.push_back(possible_moves[i]);
|
|
|
+ }
|
|
|
+ possible_moves = possible_swap;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
return possible_moves;
|
|
|
}
|
|
@@ -120,6 +155,8 @@ std::ostream& operator <<(std::ostream& out, Chessboard& chess)
|
|
|
out << '\n';
|
|
|
}
|
|
|
|
|
|
+ // Дебаг ходов
|
|
|
+
|
|
|
// vector<Position> grouped_moves;
|
|
|
// for(int j = 0; j < figures.size(); j++) {
|
|
|
// grouped_moves = chess.get_possible_moves(figures[j]);
|