大部分 sprintf 转移到 gameController
解决 cmdlist 移走到 gameController 后控制相关和状态相在 cmdlist 不见的问题。 目前自对弈耗时由5800ms左右缩减到5300ms左右。
This commit is contained in:
parent
26eb01e259
commit
81b202babe
|
@ -852,7 +852,7 @@ bool Position::giveup(Color loser)
|
|||
|
||||
winner = ~loser;
|
||||
gameoverReason = LOSE_REASON_GIVE_UP;
|
||||
sprintf(cmdline, "Player%d give up!", loser);
|
||||
//sprintf(cmdline, "Player%d give up!", loser);
|
||||
score[winner]++;
|
||||
|
||||
return true;
|
||||
|
@ -925,7 +925,7 @@ bool Position::command(const char *cmd)
|
|||
winner = DRAW;
|
||||
score_draw++;
|
||||
gameoverReason = DRAW_REASON_THREEFOLD_REPETITION;
|
||||
sprintf(cmdline, "Threefold Repetition. Draw!");
|
||||
//sprintf(cmdline, "Threefold Repetition. Draw!");
|
||||
return true;
|
||||
}
|
||||
#endif /* THREEFOLD_REPETITION */
|
||||
|
@ -992,7 +992,7 @@ bool Position::check_gameover_condition(int8_t updateCmdlist)
|
|||
elapsedSeconds[i] = rule.maxTimeLedToLose * 60;
|
||||
winner = ~Color(i);
|
||||
gameoverReason = LOSE_REASON_TIME_OVER;
|
||||
sprintf(cmdline, "Time over. Player%d win!", ~Color(i));
|
||||
//sprintf(cmdline, "Time over. Player%d win!", ~Color(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1006,7 +1006,7 @@ bool Position::check_gameover_condition(int8_t updateCmdlist)
|
|||
phase = PHASE_GAMEOVER;
|
||||
if (updateCmdlist) {
|
||||
gameoverReason = DRAW_REASON_RULE_50;
|
||||
sprintf(cmdline, "Steps over. In draw!");
|
||||
//sprintf(cmdline, "Steps over. In draw!");
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -1020,7 +1020,7 @@ bool Position::check_gameover_condition(int8_t updateCmdlist)
|
|||
gameoverReason = LOSE_REASON_LESS_THAN_THREE;
|
||||
|
||||
if (updateCmdlist) {
|
||||
sprintf(cmdline, "Player%d win!", winner);
|
||||
//sprintf(cmdline, "Player%d win!", winner);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -1055,13 +1055,13 @@ bool Position::check_gameover_condition(int8_t updateCmdlist)
|
|||
winner = WHITE;
|
||||
gameoverReason = LOSE_REASON_BOARD_IS_FULL;
|
||||
if (updateCmdlist) {
|
||||
sprintf(cmdline, "Player2 win!");
|
||||
//sprintf(cmdline, "Player2 win!");
|
||||
}
|
||||
} else {
|
||||
winner = DRAW;
|
||||
gameoverReason = DRAW_REASON_BOARD_IS_FULL;
|
||||
if (updateCmdlist) {
|
||||
sprintf(cmdline, "Full. In draw!");
|
||||
//sprintf(cmdline, "Full. In draw!");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1076,7 +1076,7 @@ bool Position::check_gameover_condition(int8_t updateCmdlist)
|
|||
if (updateCmdlist) {
|
||||
gameoverReason = LOSE_REASON_NO_WAY;
|
||||
winner = ~sideToMove;
|
||||
sprintf(cmdline, "Player%d no way to go. Player%d win!", sideToMove, winner);
|
||||
//sprintf(cmdline, "Player%d no way to go. Player%d win!", sideToMove, winner);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -576,7 +576,7 @@ string AIAlgorithm::nextMove()
|
|||
if (gameOptions.getGiveUpIfMostLose() == true) {
|
||||
if (root->value <= -VALUE_MATE) {
|
||||
gameoverReason = LOSE_REASON_GIVE_UP;
|
||||
sprintf(cmdline, "Player%d give up!", position->sideToMove);
|
||||
//sprintf(cmdline, "Player%d give up!", position->sideToMove);
|
||||
return cmdline;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1406,6 +1406,44 @@ inline std::string GameController::char_to_string(char ch)
|
|||
}
|
||||
}
|
||||
|
||||
void GameController::appendGameOverReasonToCmdlist()
|
||||
{
|
||||
assert(position.phase == PHASE_GAMEOVER);
|
||||
|
||||
char cmdline[64] = { 0 };
|
||||
switch (position.gameoverReason) {
|
||||
case LOSE_REASON_NO_WAY:
|
||||
sprintf(cmdline, "Player%d no way to go. Player%d win!", position.sideToMove, position.winner);
|
||||
break;
|
||||
case LOSE_REASON_TIME_OVER:
|
||||
sprintf(cmdline, "Time over. Player%d win!", position.winner);
|
||||
break;
|
||||
case DRAW_REASON_THREEFOLD_REPETITION:
|
||||
sprintf(cmdline, "Threefold Repetition. Draw!");
|
||||
break;
|
||||
case DRAW_REASON_RULE_50:
|
||||
sprintf(cmdline, "Steps over. In draw!");
|
||||
break;
|
||||
case LOSE_REASON_BOARD_IS_FULL:
|
||||
sprintf(cmdline, "Player2 win!");
|
||||
break;
|
||||
case DRAW_REASON_BOARD_IS_FULL:
|
||||
sprintf(cmdline, "Full. In draw!");
|
||||
break;
|
||||
case LOSE_REASON_LESS_THAN_THREE:
|
||||
sprintf(cmdline, "Player%d win!", position.winner);
|
||||
break;
|
||||
case LOSE_REASON_GIVE_UP:
|
||||
sprintf(cmdline, "Player%d give up!", ~position.winner);
|
||||
break;
|
||||
default:
|
||||
loggerDebug("No Game Over Reason");
|
||||
break;
|
||||
}
|
||||
|
||||
cmdlist.emplace_back(cmdline);
|
||||
}
|
||||
|
||||
void GameController::setTips()
|
||||
{
|
||||
Position &p = position;
|
||||
|
@ -1443,6 +1481,8 @@ void GameController::setTips()
|
|||
break;
|
||||
|
||||
case PHASE_GAMEOVER:
|
||||
appendGameOverReasonToCmdlist();
|
||||
|
||||
scoreStr = "比分 " + to_string(p.score[BLACK]) + " : " + to_string(p.score[WHITE]) + ", 和棋 " + to_string(p.score_draw);
|
||||
|
||||
switch (p.winner) {
|
||||
|
|
|
@ -138,6 +138,7 @@ public:
|
|||
|
||||
char color_to_char(Color color);
|
||||
std::string char_to_string(char ch);
|
||||
void appendGameOverReasonToCmdlist();
|
||||
void setTips();
|
||||
|
||||
inline const std::vector<std::string> *cmd_list() const
|
||||
|
|
Loading…
Reference in New Issue