From cd6f8a6a77edc47d9dd518391771ba6a22c691af Mon Sep 17 00:00:00 2001 From: Calcitem Date: Thu, 26 Sep 2019 01:10:47 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=87=8F=E5=B0=91=20setPosition()?= =?UTF-8?q?=20=E7=9A=84=E5=8F=82=E6=95=B0=E4=B8=AA=E6=95=B0=E5=88=B03?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/game/position.cpp | 43 ++++++------------------------------------- src/game/position.h | 8 +------- 2 files changed, 7 insertions(+), 44 deletions(-) diff --git a/src/game/position.cpp b/src/game/position.cpp index 6f4b9ae0..5a756312 100644 --- a/src/game/position.cpp +++ b/src/game/position.cpp @@ -80,11 +80,7 @@ Game &Game::operator= (const Game &game) } // 设置棋局状态和棋盘数据,用于初始化 -bool Game::setPosition(const struct Rule *newRule, step_t maxStepsLedToDraw, int maxTimeLedToLose, - step_t initialStep, - phase_t phase, player_t side, action_t action, - const char *locations, - int nPiecesInHand_1, int nPiecesInHand_2, int nPiecesNeedRemove) +bool Game::setPosition(const struct Rule *newRule, step_t maxStepsLedToDraw, int maxTimeLedToLose) { // 有效性判断 if (maxTimeLedToLose < 0) { @@ -98,26 +94,9 @@ bool Game::setPosition(const struct Rule *newRule, step_t maxStepsLedToDraw, int // 设置棋局数据 - // 设置步数 - this->currentStep = initialStep; - this->moveStep = initialStep; - - // 局面阶段标识 - position.phase = phase; - - // 轮流状态标识 - setSideToMove(side); - - // 动作状态标识 - position.action = action; - // 当前棋局(3×8) - if (locations == nullptr) { - memset(boardLocations, 0, sizeof(position.board.locations)); - position.hash = 0; - } else { - memcpy(boardLocations, locations, sizeof(position.board.locations)); - } + memset(boardLocations, 0, sizeof(position.board.locations)); + position.hash = 0; // 计算盘面子数 // 棋局,抽象为一个(5×8)的数组,上下两行留空 @@ -150,23 +129,13 @@ bool Game::setPosition(const struct Rule *newRule, step_t maxStepsLedToDraw, int return false; } - if (nPiecesInHand_1 < 0 || nPiecesInHand_2 < 0) { - return false; - } - position.nPiecesInHand[1] = rule.nTotalPiecesEachSide - position.nPiecesOnBoard[1]; position.nPiecesInHand[2] = rule.nTotalPiecesEachSide - position.nPiecesOnBoard[2]; - position.nPiecesInHand[1] = std::min(nPiecesInHand_1, position.nPiecesInHand[1]); - position.nPiecesInHand[2] = std::min(nPiecesInHand_2, position.nPiecesInHand[2]); + position.nPiecesInHand[1] = std::min(12, position.nPiecesInHand[1]); // TODO: 12改为变量 + position.nPiecesInHand[2] = std::min(12, position.nPiecesInHand[2]); // TODO: 12改为变量 // 设置去子状态时的剩余尚待去除子数 - if (action == ACTION_CAPTURE) { - if (0 <= nPiecesNeedRemove && nPiecesNeedRemove < 3) { - position.nPiecesNeedRemove = nPiecesNeedRemove; - } - } else { - position.nPiecesNeedRemove = 0; - } + position.nPiecesNeedRemove = 0; // 清空成三记录 if (!position.board.millList.empty()) { diff --git a/src/game/position.h b/src/game/position.h index 7b67a176..97fbf209 100644 --- a/src/game/position.h +++ b/src/game/position.h @@ -104,13 +104,7 @@ public: // 设置棋局状态和棋局,用于初始化 bool setPosition(const struct Rule *rule, step_t maxStepsLedToDraw = 0, // 限制步数 - int maxTimeLedToLose = 0, // 限制时间 - step_t initialStep = 0, // 默认起始步数为0 - phase_t phase = PHASE_NOTSTARTED, player_t turn = PLAYER_1, action_t action = ACTION_PLACE, - const char *locations = nullptr, // 默认空棋盘 - int nPiecesInHand_1 = 12, // 玩家1剩余未放置子数 - int nPiecesInHand_2 = 12, // 玩家2剩余未放置子数 - int nPiecesNeedRemove = 0 // 尚待去除的子数 + int maxTimeLedToLose = 0 // 限制时间 ); // 获取棋盘数据