From fb91ad3f8d6f4abc8995e8c2dd183d1ceb2ebec6 Mon Sep 17 00:00:00 2001 From: Calcitem Date: Tue, 29 Dec 2020 15:03:00 +0800 Subject: [PATCH] =?UTF-8?q?types:=20GameOverReason=20=E6=94=B9=E4=B8=BA=20?= =?UTF-8?q?enum=20class?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/position.cpp | 20 ++++++++++---------- src/position.h | 2 +- src/thread.cpp | 2 +- src/types.h | 20 ++++++++++---------- src/ui/qt/game.cpp | 30 +++++++++++++++--------------- 5 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/position.cpp b/src/position.cpp index bc61d402..d555cd91 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -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? diff --git a/src/position.h b/src/position.h index 68271d5e..81655e47 100644 --- a/src/position.h +++ b/src/position.h @@ -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; diff --git a/src/thread.cpp b/src/thread.cpp index 561ea7c7..26ae4d61 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -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; } diff --git a/src/types.h b/src/types.h index 1ddd5048..0886391a 100644 --- a/src/types.h +++ b/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 diff --git a/src/ui/qt/game.cpp b/src/ui/qt/game.cpp index 923d589b..f14db3a4 100644 --- a/src/ui/qt/game.cpp +++ b/src/ui/qt/game.cpp @@ -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: