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