position: 新增 set_gameover() 函数并使用
This commit is contained in:
parent
df58e02132
commit
a3854b94fb
|
@ -780,9 +780,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) {
|
||||||
winner = sideToMove;
|
set_gameover(sideToMove, LOSE_REASON_LESS_THAN_THREE);
|
||||||
phase = PHASE_GAMEOVER;
|
|
||||||
gameoverReason = LOSE_REASON_LESS_THAN_THREE;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -846,10 +844,8 @@ bool Position::resign(Color loser)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
phase = PHASE_GAMEOVER;
|
set_gameover(~loser, LOSE_REASON_RESIGN);
|
||||||
|
|
||||||
winner = ~loser;
|
|
||||||
gameoverReason = LOSE_REASON_RESIGN;
|
|
||||||
//sprintf(cmdline, "Player%d give up!", loser);
|
//sprintf(cmdline, "Player%d give up!", loser);
|
||||||
update_score();
|
update_score();
|
||||||
|
|
||||||
|
@ -918,6 +914,13 @@ Color Position::get_winner() const
|
||||||
return winner;
|
return winner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void Position::set_gameover(Color w, GameOverReason reason)
|
||||||
|
{
|
||||||
|
phase = PHASE_GAMEOVER;
|
||||||
|
gameoverReason = reason;
|
||||||
|
winner = w;
|
||||||
|
}
|
||||||
|
|
||||||
int Position::update()
|
int Position::update()
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
@ -989,14 +992,10 @@ bool Position::check_gameover_condition()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (pieceCountOnBoard[BLACK] + pieceCountOnBoard[WHITE] >= RANK_NB * FILE_NB) {
|
if (pieceCountOnBoard[BLACK] + pieceCountOnBoard[WHITE] >= RANK_NB * FILE_NB) {
|
||||||
phase = PHASE_GAMEOVER;
|
|
||||||
|
|
||||||
if (rule.isBlackLosebutNotDrawWhenBoardFull) {
|
if (rule.isBlackLosebutNotDrawWhenBoardFull) {
|
||||||
winner = WHITE;
|
set_gameover(WHITE, LOSE_REASON_BOARD_IS_FULL);
|
||||||
gameoverReason = LOSE_REASON_BOARD_IS_FULL;
|
|
||||||
} else {
|
} else {
|
||||||
winner = DRAW;
|
set_gameover(DRAW, DRAW_REASON_BOARD_IS_FULL);
|
||||||
gameoverReason = DRAW_REASON_BOARD_IS_FULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -1004,12 +1003,10 @@ 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) {
|
||||||
phase = PHASE_GAMEOVER;
|
set_gameover(~sideToMove, LOSE_REASON_NO_WAY);
|
||||||
gameoverReason = LOSE_REASON_NO_WAY;
|
|
||||||
winner = ~sideToMove;
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
change_side_to_move();
|
change_side_to_move(); // TODO: Need?
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,6 +143,7 @@ public:
|
||||||
|
|
||||||
void change_side_to_move();
|
void change_side_to_move();
|
||||||
Color get_winner() const;
|
Color get_winner() const;
|
||||||
|
void set_gameover(Color w, GameOverReason reason);
|
||||||
|
|
||||||
void mirror(vector <string> &cmdlist, bool cmdChange = true);
|
void mirror(vector <string> &cmdlist, bool cmdChange = true);
|
||||||
void turn(vector <string> &cmdlist, bool cmdChange = true);
|
void turn(vector <string> &cmdlist, bool cmdChange = true);
|
||||||
|
|
Loading…
Reference in New Issue