From 67cee4cd8444952b008b4113c5a994f9f4ab5344 Mon Sep 17 00:00:00 2001 From: Calcitem Date: Tue, 1 Sep 2020 00:24:59 +0800 Subject: [PATCH] =?UTF-8?q?position:=20=E7=AE=80=E5=8C=96=E7=BF=BB?= =?UTF-8?q?=E8=BD=AC/=E6=97=8B=E8=BD=AC/=E9=95=9C=E5=83=8F=E7=AD=89?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E7=9A=84=E4=BC=A0=E5=8F=82=E4=B8=AA=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 改为使用类成员变量。 --- src/position.cpp | 72 ++++++++++++++++++------------------ src/position.h | 6 +-- src/ui/qt/gamecontroller.cpp | 10 ++--- 3 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/position.cpp b/src/position.cpp index e255ab57..d78c4270 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -1743,7 +1743,7 @@ bool Position::is_star_square(Square s) s == 22); } -void Position::mirror(int32_t move_, Square s, bool cmdChange /*= true*/) +void Position::mirror(bool cmdChange /*= true*/) { Piece ch; int f, r; @@ -1759,14 +1759,14 @@ void Position::mirror(int32_t move_, Square s, bool cmdChange /*= true*/) uint64_t llp[3] = { 0 }; - if (move_ < 0) { - f = (-move_) / RANK_NB; - r = (-move_) % RANK_NB; + if (move < 0) { + f = (-move) / RANK_NB; + r = (-move) % RANK_NB; r = (RANK_NB - r) % RANK_NB; - move_ = -(f * RANK_NB + r); + move = static_cast(-(f * RANK_NB + r)); } else { - llp[0] = static_cast(from_sq((Move)move_)); - llp[1] = to_sq((Move)move_); + llp[0] = static_cast(from_sq((Move)move)); + llp[1] = to_sq((Move)move); for (i = 0; i < 2; i++) { f = static_cast(llp[i]) / RANK_NB; @@ -1775,14 +1775,14 @@ void Position::mirror(int32_t move_, Square s, bool cmdChange /*= true*/) llp[i] = (static_cast(f) * RANK_NB + r); } - move_ = static_cast(((llp[0] << 8) | llp[1])); + move = static_cast(((llp[0] << 8) | llp[1])); } - if (s != 0) { - f = s / RANK_NB; - r = s % RANK_NB; + if (currentSquare != 0) { + f = currentSquare / RANK_NB; + r = currentSquare % RANK_NB; r = (RANK_NB - r) % RANK_NB; - s = static_cast(f * RANK_NB + r); + currentSquare = static_cast(f * RANK_NB + r); } if (rule.allowRemovePiecesRepeatedlyWhenCloseSameMill) { @@ -1852,7 +1852,7 @@ void Position::mirror(int32_t move_, Square s, bool cmdChange /*= true*/) } } -void Position::turn(int32_t move_, Square s, bool cmdChange /*= true*/) +void Position::turn(bool cmdChange /*= true*/) { Piece ch; int f, r; @@ -1866,19 +1866,19 @@ void Position::turn(int32_t move_, Square s, bool cmdChange /*= true*/) uint64_t llp[3] = { 0 }; - if (move_ < 0) { - f = (-move_) / RANK_NB; - r = (-move_) % RANK_NB; + if (move < 0) { + f = (-move) / RANK_NB; + r = (-move) % RANK_NB; if (f == 1) f = FILE_NB; else if (f == FILE_NB) f = 1; - move_ = -(f * RANK_NB + r); + move = static_cast(-(f * RANK_NB + r)); } else { - llp[0] = static_cast(from_sq((Move)move_)); - llp[1] = to_sq((Move)move_); + llp[0] = static_cast(from_sq((Move)move)); + llp[1] = to_sq((Move)move); for (i = 0; i < 2; i++) { f = static_cast(llp[i]) / RANK_NB; @@ -1892,19 +1892,19 @@ void Position::turn(int32_t move_, Square s, bool cmdChange /*= true*/) llp[i] = static_cast(f * RANK_NB + r); } - move_ = static_cast(((llp[0] << 8) | llp[1])); + move = static_cast(((llp[0] << 8) | llp[1])); } - if (s != 0) { - f = s / RANK_NB; - r = s % RANK_NB; + if (currentSquare != 0) { + f = currentSquare / RANK_NB; + r = currentSquare % RANK_NB; if (f == 1) f = FILE_NB; else if (f == FILE_NB) f = 1; - s = static_cast(f * RANK_NB + r); + currentSquare = static_cast(f * RANK_NB + r); } if (rule.allowRemovePiecesRepeatedlyWhenCloseSameMill) { @@ -2015,7 +2015,7 @@ void Position::turn(int32_t move_, Square s, bool cmdChange /*= true*/) } } -void Position::rotate(int degrees, int32_t move_, Square s, bool cmdChange /*= true*/) +void Position::rotate(int degrees, bool cmdChange /*= true*/) { degrees = degrees % 360; @@ -2069,14 +2069,14 @@ void Position::rotate(int degrees, int32_t move_, Square s, bool cmdChange /*= t uint64_t llp[3] = { 0 }; - if (move_ < 0) { - f = (-move_) / RANK_NB; - r = (-move_) % RANK_NB; + if (move < 0) { + f = (-move) / RANK_NB; + r = (-move) % RANK_NB; r = (r + RANK_NB - degrees) % RANK_NB; - move_ = -(f * RANK_NB + r); + move = static_cast(-(f * RANK_NB + r)); } else { - llp[0] = static_cast(from_sq((Move)move_)); - llp[1] = to_sq((Move)move_); + llp[0] = static_cast(from_sq((Move)move)); + llp[1] = to_sq((Move)move); f = static_cast(llp[0]) / RANK_NB; r = static_cast(llp[0]) % RANK_NB; r = (r + RANK_NB - degrees) % RANK_NB; @@ -2085,14 +2085,14 @@ void Position::rotate(int degrees, int32_t move_, Square s, bool cmdChange /*= t r = static_cast(llp[1]) % RANK_NB; r = (r + RANK_NB - degrees) % RANK_NB; llp[1] = static_cast(f * RANK_NB + r); - move_ = static_cast(((llp[0] << 8) | llp[1])); + move = static_cast(((llp[0] << 8) | llp[1])); } - if (s != 0) { - f = s / RANK_NB; - r = s % RANK_NB; + if (currentSquare != 0) { + f = currentSquare / RANK_NB; + r = currentSquare % RANK_NB; r = (r + RANK_NB - degrees) % RANK_NB; - s = static_cast(f * RANK_NB + r); + currentSquare = static_cast(f * RANK_NB + r); } if (rule.allowRemovePiecesRepeatedlyWhenCloseSameMill) { diff --git a/src/position.h b/src/position.h index ce5f7c26..0cdae582 100644 --- a/src/position.h +++ b/src/position.h @@ -145,9 +145,9 @@ public: void set_tips(); Color get_winner() const; - void mirror(int32_t move_, Square s, bool cmdChange = true); - void turn(int32_t move_, Square s, bool cmdChange = true); - void rotate(int degrees, int32_t move_, Square s, bool cmdChange = true); + void mirror(bool cmdChange = true); + void turn(bool cmdChange = true); + void rotate(int degrees, bool cmdChange = true); void create_mill_table(); int add_mills(Square s); diff --git a/src/ui/qt/gamecontroller.cpp b/src/ui/qt/gamecontroller.cpp index 2a0848d8..692ce26d 100644 --- a/src/ui/qt/gamecontroller.cpp +++ b/src/ui/qt/gamecontroller.cpp @@ -549,8 +549,8 @@ void GameController::flip() #ifndef TRAINING_MODE stopAndWaitAiThreads(); - position.mirror(position.move, position.currentSquare); - position.rotate(180, position.move, position.currentSquare); + position.mirror(); + position.rotate(180); // 更新棋谱 int row = 0; @@ -575,7 +575,7 @@ void GameController::mirror() #ifndef TRAINING_MODE stopAndWaitAiThreads(); - position.mirror(position.move, position.currentSquare); + position.mirror(); // 更新棋谱 int row = 0; @@ -603,7 +603,7 @@ void GameController::turnRight() #ifndef TRAINING_MODE stopAndWaitAiThreads(); - position.rotate(-90, position.move, position.currentSquare); + position.rotate(-90); // 更新棋谱 int row = 0; @@ -629,7 +629,7 @@ void GameController::turnLeft() #ifndef TRAINING_MODE stopAndWaitAiThreads(); - position.rotate(90, position.move, position.currentSquare); + position.rotate(90); // 更新棋谱 int row = 0;