jezv před 11 měsíci
rodič
revize
ab60077277
2 změnil soubory, kde provedl 27 přidání a 26 odebrání
  1. 26 26
      Chessboard.cpp
  2. 1 0
      Figure.h

+ 26 - 26
Chessboard.cpp

@@ -8,17 +8,6 @@
 #include <utility>
 #include <stdexcept>
 
-std::ostream& operator <<(std::ostream& out, Chessboard& chess)
-{
-    for (int i = 7; i >= 0; i--) {
-        for(int j = 0; j < 8; j++) {
-            out << chess.board[i][j];            
-        }
-        out << '\n';
-    }
-    return out;
-}
-
 Cell Chessboard::get_cell(Position p)
 {
     return get_icell(p.posNum-'0'-1, p.posSym-'A');
@@ -34,8 +23,6 @@ bool compare_by_angle(std::pair<int, int> pos1, std::pair<int, int> pos2)
 vector<Position> Chessboard::get_possible_moves(Figure* fig)
 {
     vector<Position> moves = fig->get_moves();
-    // for(int i = 0; i < moves.size(); i++) std::cout << moves[i] << ';';
-    // std::cout << '\n';
     vector<std::pair<int, int>> grouped_moves;
     vector<Position> possible_moves;
     Position pos = fig->get_position();
@@ -44,9 +31,6 @@ vector<Position> Chessboard::get_possible_moves(Figure* fig)
     // Сортируем по углу и удалённости от фигуры
     sort(grouped_moves.begin(), grouped_moves.end(), compare_by_angle);
 
-    // for(int i = 0; i < grouped_moves.size(); i++) std::cout << char(grouped_moves[i].first+pos.posSym) << char(grouped_moves[i].second+pos.posNum) << ';';
-    // std::cout << '\n';
-
     bool blockedGroup = false;
 
     Figure* check_cell;
@@ -94,16 +78,6 @@ Chessboard::Chessboard(vector<Figure*> figures)
         p = figures[i]->get_position();
         board[p.posNum-'0'-1][p.posSym-'A'] = Cell(figures[i]);
     }
-
-    // vector<Position> grouped_moves;
-    // for(int j = 0; j < figures.size(); j++) {
-    //     grouped_moves = get_possible_moves(figures[j]);
-    //     std::cout << figures[j]->print() << ' ';
-    //     for(int i = 0; i < grouped_moves.size(); i++) {
-    //         std::cout << grouped_moves[i] << ';';
-    //     }
-    //     std::cout << std::endl;
-    // }
 }
 
 void Chessboard::create_move(Position pos1, Position pos2)
@@ -117,6 +91,7 @@ void Chessboard::create_move(Position pos1, Position pos2)
 
     for(int i = 0; i < pos_moves.size(); i++) {
         if (pos_moves[i].posSym == pos2.posSym and pos_moves[i].posNum == pos2.posNum) {
+            fig->set_position(Position((char)pos2.posSym, pos2.posNum));
             board[pos2.posNum-'0'-1][pos2.posSym-'A'] = Cell(fig);
             board[pos1.posNum-'0'-1][pos1.posSym-'A'] = Cell();
             return;
@@ -130,4 +105,29 @@ Cell Chessboard::get_icell(int index, int jindex)
     if (not (index >= 0 and index < 8 and jindex >= 0 and jindex < 8))
         throw std::invalid_argument("Trying to get figure out of board");
     return board[index][jindex];
+}
+
+std::ostream& operator <<(std::ostream& out, Chessboard& chess)
+{
+    vector<Figure*> figures;
+    for (int i = 7; i >= 0; i--) {
+        for(int j = 0; j < 8; j++) {
+            out << chess.board[i][j]; 
+            if (chess.board[i][j].get_figure() != nullptr) {
+                figures.push_back(chess.board[i][j].get_figure());
+            }           
+        }
+        out << '\n';
+    }
+
+    // vector<Position> grouped_moves;
+    // for(int j = 0; j < figures.size(); j++) {
+    //     grouped_moves = chess.get_possible_moves(figures[j]);
+    //     std::cout << figures[j]->print() << ' ' << figures[j]->get_position().posSym << figures[j]->get_position().posNum << ' ';
+    //     for(int i = 0; i < grouped_moves.size(); i++) {
+    //         std::cout << grouped_moves[i] << ';';
+    //     }
+    //     std::cout << std::endl;
+    // }
+    return out;
 }

+ 1 - 0
Figure.h

@@ -23,6 +23,7 @@ class Figure
     virtual const char* print() = 0;
 
     Position get_position(){return position;}
+    void set_position(Position pos){position = pos;}
     char get_color(){return color;}
 };