types: GameOverReason 改为 enum class
This commit is contained in:
parent
44a26a83dd
commit
fb91ad3f8d
|
@ -719,7 +719,7 @@ bool Position::reset()
|
|||
action = ACTION_PLACE;
|
||||
|
||||
winner = NOBODY;
|
||||
gameoverReason = NO_REASON;
|
||||
gameOverReason = GameOverReason::noReason;
|
||||
|
||||
memset(board, 0, sizeof(board));
|
||||
st.key = 0;
|
||||
|
@ -759,7 +759,7 @@ bool Position::reset()
|
|||
|
||||
bool Position::start()
|
||||
{
|
||||
gameoverReason = NO_REASON;
|
||||
gameOverReason = GameOverReason::noReason;
|
||||
|
||||
switch (phase) {
|
||||
case Phase::placing:
|
||||
|
@ -954,7 +954,7 @@ bool Position::remove_piece(Square s, bool updateCmdlist)
|
|||
pieceCountOnBoard[them]--;
|
||||
|
||||
if (pieceCountOnBoard[them] + pieceCountInHand[them] < rule.nPiecesAtLeast) {
|
||||
set_gameover(sideToMove, LOSE_REASON_LESS_THAN_THREE);
|
||||
set_gameover(sideToMove, GameOverReason::loseReasonlessThanThree);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1020,7 +1020,7 @@ bool Position::resign(Color loser)
|
|||
return false;
|
||||
}
|
||||
|
||||
set_gameover(~loser, LOSE_REASON_RESIGN);
|
||||
set_gameover(~loser, GameOverReason::loseReasonResign);
|
||||
|
||||
//sprintf(cmdline, "Player%d give up!", loser);
|
||||
update_score();
|
||||
|
@ -1076,7 +1076,7 @@ bool Position::command(const char *cmd)
|
|||
phase = Phase::gameOver;
|
||||
winner = DRAW;
|
||||
score_draw++;
|
||||
gameoverReason = DRAW_REASON_THREEFOLD_REPETITION;
|
||||
gameOverReason = GameOverReason::drawReasonThreefoldRepetition;
|
||||
//sprintf(cmdline, "Threefold Repetition. Draw!");
|
||||
return true;
|
||||
}
|
||||
|
@ -1093,7 +1093,7 @@ Color Position::get_winner() const
|
|||
inline void Position::set_gameover(Color w, GameOverReason reason)
|
||||
{
|
||||
phase = Phase::gameOver;
|
||||
gameoverReason = reason;
|
||||
gameOverReason = reason;
|
||||
winner = w;
|
||||
}
|
||||
|
||||
|
@ -1119,15 +1119,15 @@ bool Position::check_gameover_condition()
|
|||
st.rule50 > rule.maxStepsLedToDraw) {
|
||||
winner = DRAW;
|
||||
phase = Phase::gameOver;
|
||||
gameoverReason = DRAW_REASON_RULE_50;
|
||||
gameOverReason = GameOverReason::drawReasonRule50;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (pieceCountOnBoard[BLACK] + pieceCountOnBoard[WHITE] >= EFFECTIVE_SQUARE_NB) {
|
||||
if (rule.isBlackLoseButNotDrawWhenBoardFull) {
|
||||
set_gameover(WHITE, LOSE_REASON_BOARD_IS_FULL);
|
||||
set_gameover(WHITE, GameOverReason::loseReasonBoardIsFull);
|
||||
} else {
|
||||
set_gameover(DRAW, DRAW_REASON_BOARD_IS_FULL);
|
||||
set_gameover(DRAW, GameOverReason::drawReasonBoardIsFull);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -1135,7 +1135,7 @@ bool Position::check_gameover_condition()
|
|||
|
||||
if (phase == Phase::moving && action == ACTION_SELECT && is_all_surrounded()) {
|
||||
if (rule.isLoseButNotChangeSideWhenNoWay) {
|
||||
set_gameover(~sideToMove, LOSE_REASON_NO_WAY);
|
||||
set_gameover(~sideToMove, GameOverReason::loseReasonNoWay);
|
||||
return true;
|
||||
} else {
|
||||
change_side_to_move(); // TODO: Need?
|
||||
|
|
|
@ -189,7 +189,7 @@ public:
|
|||
/// Mill Game
|
||||
Color them { NOCOLOR };
|
||||
Color winner;
|
||||
GameOverReason gameoverReason { NO_REASON };
|
||||
GameOverReason gameOverReason { GameOverReason::noReason };
|
||||
|
||||
enum Phase phase {Phase::none};
|
||||
enum Action action;
|
||||
|
|
|
@ -561,7 +561,7 @@ string Thread::nextMove()
|
|||
|
||||
if (gameOptions.getResignIfMostLose() == true) {
|
||||
if (root->value <= -VALUE_MATE) {
|
||||
gameoverReason = LOSE_REASON_RESIGN;
|
||||
gameOverReason = loseReasonResign;
|
||||
//sprintf(cmdline, "Player%d give up!", position->sideToMove);
|
||||
return cmdline;
|
||||
}
|
||||
|
|
20
src/types.h
20
src/types.h
|
@ -157,17 +157,17 @@ enum Action : uint16_t
|
|||
ACTION_REMOVE = 0x0400
|
||||
};
|
||||
|
||||
enum GameOverReason
|
||||
enum class GameOverReason
|
||||
{
|
||||
NO_REASON,
|
||||
LOSE_REASON_LESS_THAN_THREE,
|
||||
LOSE_REASON_NO_WAY,
|
||||
LOSE_REASON_BOARD_IS_FULL,
|
||||
LOSE_REASON_RESIGN,
|
||||
LOSE_REASON_TIME_OVER,
|
||||
DRAW_REASON_THREEFOLD_REPETITION,
|
||||
DRAW_REASON_RULE_50,
|
||||
DRAW_REASON_BOARD_IS_FULL,
|
||||
noReason,
|
||||
loseReasonlessThanThree,
|
||||
loseReasonNoWay,
|
||||
loseReasonBoardIsFull,
|
||||
loseReasonResign,
|
||||
loseReasonTimeOver,
|
||||
drawReasonThreefoldRepetition,
|
||||
drawReasonRule50,
|
||||
drawReasonBoardIsFull,
|
||||
};
|
||||
|
||||
enum Bound : uint8_t
|
||||
|
|
|
@ -1487,29 +1487,29 @@ void Game::appendGameOverReasonToCmdlist()
|
|||
}
|
||||
|
||||
char cmdline[64] = { 0 };
|
||||
switch (position.gameoverReason) {
|
||||
case LOSE_REASON_NO_WAY:
|
||||
switch (position.gameOverReason) {
|
||||
case GameOverReason::loseReasonNoWay:
|
||||
sprintf(cmdline, "Player%d no way to go. Player%d win!", position.sideToMove, position.winner);
|
||||
break;
|
||||
case LOSE_REASON_TIME_OVER:
|
||||
case GameOverReason::loseReasonTimeOver:
|
||||
sprintf(cmdline, "Time over. Player%d win!", position.winner);
|
||||
break;
|
||||
case DRAW_REASON_THREEFOLD_REPETITION:
|
||||
case GameOverReason::drawReasonThreefoldRepetition:
|
||||
sprintf(cmdline, "Threefold Repetition. Draw!");
|
||||
break;
|
||||
case DRAW_REASON_RULE_50:
|
||||
case GameOverReason::drawReasonRule50:
|
||||
sprintf(cmdline, "Steps over. In draw!");
|
||||
break;
|
||||
case LOSE_REASON_BOARD_IS_FULL:
|
||||
case GameOverReason::loseReasonBoardIsFull:
|
||||
sprintf(cmdline, "Player2 win!");
|
||||
break;
|
||||
case DRAW_REASON_BOARD_IS_FULL:
|
||||
case GameOverReason::drawReasonBoardIsFull:
|
||||
sprintf(cmdline, "Full. In draw!");
|
||||
break;
|
||||
case LOSE_REASON_LESS_THAN_THREE:
|
||||
case GameOverReason::loseReasonlessThanThree:
|
||||
sprintf(cmdline, "Player%d win!", position.winner);
|
||||
break;
|
||||
case LOSE_REASON_RESIGN:
|
||||
case GameOverReason::loseReasonResign:
|
||||
sprintf(cmdline, "Player%d give up!", ~position.winner);
|
||||
break;
|
||||
default:
|
||||
|
@ -1575,19 +1575,19 @@ void Game::setTips()
|
|||
break;
|
||||
}
|
||||
|
||||
switch (p.gameoverReason) {
|
||||
case LOSE_REASON_LESS_THAN_THREE:
|
||||
switch (p.gameOverReason) {
|
||||
case GameOverReason::loseReasonlessThanThree:
|
||||
break;
|
||||
case LOSE_REASON_NO_WAY:
|
||||
case GameOverReason::loseReasonNoWay:
|
||||
reasonStr = turnStr + "无子可走被闷。";
|
||||
break;
|
||||
case LOSE_REASON_RESIGN:
|
||||
case GameOverReason::loseReasonResign:
|
||||
reasonStr = turnStr + "投子认负。";
|
||||
break;
|
||||
case LOSE_REASON_TIME_OVER:
|
||||
case GameOverReason::loseReasonTimeOver:
|
||||
reasonStr = turnStr + "超时判负。";
|
||||
break;
|
||||
case DRAW_REASON_THREEFOLD_REPETITION:
|
||||
case GameOverReason::drawReasonThreefoldRepetition:
|
||||
tips = "三次重复局面判和。";
|
||||
break;
|
||||
default:
|
||||
|
|
Loading…
Reference in New Issue