diff --git a/NineChess/src/ninechess.cpp b/NineChess/src/ninechess.cpp index 9d830f18..3c28fb47 100644 --- a/NineChess/src/ninechess.cpp +++ b/NineChess/src/ninechess.cpp @@ -149,6 +149,7 @@ NineChess::NineChess(const NineChess &chess) currentRule = chess.currentRule; context = chess.context; currentStep = chess.currentStep; + moveStep = chess.moveStep; board_ = context.board; currentPos = chess.currentPos; winner = chess.winner; @@ -170,6 +171,7 @@ const NineChess &NineChess::operator=(const NineChess &chess) currentRule = chess.currentRule; context = chess.context; currentStep = chess.currentStep; + moveStep = chess.moveStep; board_ = context.board; currentPos = chess.currentPos; winner = chess.winner; @@ -336,6 +338,7 @@ bool NineChess::setContext(const struct Rule *rule, int maxStepsLedToDraw, int m { // 设置步数 this->currentStep = initialStep; + this->moveStep = initialStep; // 局面阶段标识 if (flags & GAME_NOTSTARTED) { @@ -504,6 +507,7 @@ bool NineChess::reset() // 步数归零 currentStep = 0; + moveStep = 0; // 局面阶段标识 context.stage = GAME_NOTSTARTED; @@ -796,6 +800,7 @@ bool NineChess::place(int c, int p, long time_p /* = -1*/) #endif currentPos = pos; currentStep++; + moveStep++; n = addMills(currentPos); // 中局阶段未成三 @@ -889,6 +894,7 @@ bool NineChess::capture(int c, int p, long time_p /* = -1*/) currentPos = 0; context.nPiecesNeedRemove--; currentStep++; + moveStep = 0; // 去子完成 // 如果决出胜负 @@ -1516,7 +1522,7 @@ bool NineChess::win(bool forceDraw) // 如果有步数限定 if (currentRule.maxStepsLedToDraw > 0) { - if (currentStep > currentRule.maxStepsLedToDraw) { + if (moveStep > currentRule.maxStepsLedToDraw) { winner = DRAW; context.stage = GAME_OVER; sprintf(cmdline, "Steps over. In draw!"); diff --git a/NineChess/src/ninechess.h b/NineChess/src/ninechess.h index 1a0b6876..596d5b00 100644 --- a/NineChess/src/ninechess.h +++ b/NineChess/src/ninechess.h @@ -332,6 +332,12 @@ public: return currentStep; } + // 获取从上次吃子开始经历的移动步数 + int getMoveStep() const + { + return moveStep; + } + // 获取局面阶段标识 enum GameStage getStage() const { @@ -529,6 +535,9 @@ private: // 当前步数 int currentStep; + // 从走子阶段开始或上次吃子起的步数 + int moveStep; + // 游戏起始时间 timeb startTimeb;