Quellcode durchsuchen

Add function for Gi1dor getter next Cell

GeorgeKolog vor 6 Jahren
Ursprung
Commit
bc8e03cdf7
2 geänderte Dateien mit 23 neuen und 12 gelöschten Zeilen
  1. 1 1
      include/Cell.h
  2. 22 11
      source/Cell.cpp

+ 1 - 1
include/Cell.h

@@ -141,7 +141,7 @@ public:
 	/*
 	 * Отвечает за запрос, куда попадет шар, если ее направить в клетку-параметр
 	 * Выполнится только с лучае, если эта следующая клетка существует
+	 * Gi1dor знает, что это такое
 	 */
 	Cell* getRealShootTarget(Cell*);
-	void print();
 };

+ 22 - 11
source/Cell.cpp

@@ -288,7 +288,7 @@ void Cell::updateUnMovealeCells_(std::queue<Cell*> & Q) {
 }
 
 void Cell::print() {
-	std::cout << col_ << " " << row_ << std::endl;
+	std::cout << "(" << col_ << ", " << row_ << ")";
 }
 
 Cell* Cell::getRealShootTarget(Cell* next){
@@ -297,35 +297,46 @@ Cell* Cell::getRealShootTarget(Cell* next){
 	}
 	int next_col = next->col_;
 	int next_row = next->row_;
-	if(next_col - col_ == next_row - row_){
+	if(next_col - col_ == next_row - row_){//GoMainDiagonal
 		if(next_col > col_){
 			return getrightDown()->getright();
 		}
 		if(next_col < col_){
 			return getleftUp()->getleft();
 		}
-		throw new std::string("Don`t recalculated");
+		throw std::string("Don`t recalculated");
 	}
-	if(-2 * (next_col - col_) == (next_row - row_)){
+	if(-2 * (next_col - col_) == (next_row - row_)){//GoSecondaryDiagonal
 		if(next_col < col_){
 			return getrightUp()->getright();
 		}
 		if(next_col > col_){
 			return getleftDown()->getleft();
 		}
-		throw new std::string("Don`t recalculated");
+		throw std::string("Don`t recalculated");
 	}
-	if(next_col - col_ == -2 * (next_row - row_)){
+	if(next_col - col_ == -2 * (next_row - row_)){//GoUp
 		if(next_col < col_){
 			return (getleftUp() != nullptr ? getleftUp()->getrightUp() : getrightUp()->getleftUp());
 		}
 		if(next_col > col_){
 			return (getleftDown() != nullptr ? getleftDown()->getrightDown() : getrightDown()->getleftDown());
 		}
-		throw new std::string("Don`t recalculated");
+		throw std::string("Don`t recalculated");
+	}
+	int row_secondary_diag = row_ - 2 * (next_col - col_);
+	int row_main_diag = row_ + next_col - col_;
+	int twice_row_up_line = 2 * row_ + col_ - next_col;
+	if(next_col > col_){
+		if(next_row < row_main_diag)return getleft();
+		if(2 * next_row < twice_row_up_line)return getleftUp();
+		if(next_row < row_secondary_diag)return getrightUp();
+		return getright();
+	}
+	else{
+		if(next_row < row_secondary_diag)return getleft();
+		if(2 * next_row < twice_row_up_line)return getleftDown();
+		if(next_row < row_main_diag)return getrightDown();
+		return getright();
 	}
-	return this;
-
-
-
 }