WAR: 临时性解决点击棋谱后无反应的问题

因为 cmdlist 移动框 gameController 后,每次重新开局被清空后
就没有首行的 s2... 了,临时解决方式是先备份这一行,清空后再
插回去。
This commit is contained in:
Calcitem 2020-09-11 00:29:14 +08:00
parent 51e5f22f06
commit 26eb01e259
3 changed files with 22 additions and 15 deletions

View File

@ -472,7 +472,7 @@ int Position::pieces_in_hand_count()
return pieceCountInHand[BLACK] + pieceCountInHand[WHITE]; return pieceCountInHand[BLACK] + pieceCountInHand[WHITE];
} }
bool Position::set_position(const struct Rule *newRule) int Position::set_position(const struct Rule *newRule)
{ {
rule = *newRule; rule = *newRule;
@ -504,15 +504,10 @@ bool Position::set_position(const struct Rule *newRule)
int r; int r;
for (r = 0; r < N_RULES; r++) { for (r = 0; r < N_RULES; r++) {
if (strcmp(rule.name, RULES[r].name) == 0) 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 -1;
return true;
}
cmdline[0] = '\0';
return false;
} }
bool Position::reset() bool Position::reset()
@ -878,7 +873,7 @@ bool Position::command(const char *cmd)
return false; 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); args = sscanf(cmd, "(%1u,%1u)->(%1u,%1u) %2u:%2u", &file1, &rank1, &file2, &rank2, &mm, &ss);

View File

@ -115,7 +115,7 @@ public:
/// Mill Game /// 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 get_elapsed_time(int us);
time_t start_timeb() const; time_t start_timeb() const;

View File

@ -154,6 +154,7 @@ extern deque<int> openingBookDequeBak;
void GameController::gameStart() void GameController::gameStart()
{ {
//cmdlist.clear();
position.start(); position.start();
// 每隔100毫秒调用一次定时器处理函数 // 每隔100毫秒调用一次定时器处理函数
@ -182,9 +183,14 @@ void GameController::gameReset()
timeID = 0; 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()) { 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(); gameReset();
cmdlist.clear();
} }
void GameController::setEngine(int color, bool arg) void GameController::setEngine(int color, bool arg)