From 26eb01e2598614e8d97df0fa722ab88ad5dde42e Mon Sep 17 00:00:00 2001 From: Calcitem Date: Fri, 11 Sep 2020 00:29:14 +0800 Subject: [PATCH] =?UTF-8?q?WAR:=20=E4=B8=B4=E6=97=B6=E6=80=A7=E8=A7=A3?= =?UTF-8?q?=E5=86=B3=E7=82=B9=E5=87=BB=E6=A3=8B=E8=B0=B1=E5=90=8E=E6=97=A0?= =?UTF-8?q?=E5=8F=8D=E5=BA=94=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 因为 cmdlist 移动框 gameController 后,每次重新开局被清空后 就没有首行的 s2... 了,临时解决方式是先备份这一行,清空后再 插回去。 --- src/position.cpp | 13 ++++--------- src/position.h | 2 +- src/ui/qt/gamecontroller.cpp | 22 +++++++++++++++++----- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/position.cpp b/src/position.cpp index ae3beca6..aa4d4fa3 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -472,7 +472,7 @@ int Position::pieces_in_hand_count() return pieceCountInHand[BLACK] + pieceCountInHand[WHITE]; } -bool Position::set_position(const struct Rule *newRule) +int Position::set_position(const struct Rule *newRule) { rule = *newRule; @@ -504,15 +504,10 @@ bool Position::set_position(const struct Rule *newRule) int r; for (r = 0; r < N_RULES; r++) { if (strcmp(rule.name, RULES[r].name) == 0) - break; + return r; } - if (sprintf(cmdline, "r%1u s%03u t%02u", r + 1, rule.maxStepsLedToDraw, rule.maxTimeLedToLose) > 0) { - return true; - } - - cmdline[0] = '\0'; - return false; + return -1; } bool Position::reset() @@ -878,7 +873,7 @@ bool Position::command(const char *cmd) return false; } - return set_position(&RULES[ruleIndex - 1]); + return set_position(&RULES[ruleIndex - 1]) >= 0 ? true : false; } args = sscanf(cmd, "(%1u,%1u)->(%1u,%1u) %2u:%2u", &file1, &rank1, &file2, &rank2, &mm, &ss); diff --git a/src/position.h b/src/position.h index 18cafa07..32a33c78 100644 --- a/src/position.h +++ b/src/position.h @@ -115,7 +115,7 @@ public: /// Mill Game - bool set_position(const struct Rule *rule); + int set_position(const struct Rule *rule); time_t get_elapsed_time(int us); time_t start_timeb() const; diff --git a/src/ui/qt/gamecontroller.cpp b/src/ui/qt/gamecontroller.cpp index cee1fd40..12a8cb6a 100644 --- a/src/ui/qt/gamecontroller.cpp +++ b/src/ui/qt/gamecontroller.cpp @@ -154,6 +154,7 @@ extern deque openingBookDequeBak; void GameController::gameStart() { + //cmdlist.clear(); position.start(); // 每隔100毫秒调用一次定时器处理函数 @@ -182,9 +183,14 @@ void GameController::gameReset() timeID = 0; // 重置游戏 - position.reset(); + // WAR + if (cmdlist.size() > 1) { + string bak = cmdlist[0]; + cmdlist.clear(); + cmdlist.emplace_back(bak); + } - cmdlist.clear(); + position.reset(); // 停掉线程 if (!gameOptions.getAutoRestart()) { @@ -332,12 +338,18 @@ void GameController::setRule(int ruleNo, Step stepLimited /*= -1*/, int timeLimi } // 设置模型规则,重置游戏 - position.set_position(&RULES[ruleNo]); + int r = position.set_position(&RULES[ruleNo]); + + char cmdline[64] = { 0 }; + if (sprintf(cmdline, "r%1u s%03u t%02u", r + 1, rule.maxStepsLedToDraw, rule.maxTimeLedToLose) <= 0) { + assert(0); + } + string cmd(cmdline); + cmdlist.clear(); + cmdlist.emplace_back(cmd); // 重置游戏 gameReset(); - - cmdlist.clear(); } void GameController::setEngine(int color, bool arg)